I would like to know if there is a way to test the status bar tint displayed while using the app target. I haven't found any information about UI test related with the status bar for Espresso.
-
Did you find any solution , I have the same problem! – Javad Shirkhani Feb 01 '22 at 08:26
2 Answers
Nowadays it's impossible. Espresso see only your application views, I mean it won't work with notifications, sharing intents, status bar etc.
Here's my answer on similar issue: Espresso test for Notification to showing up
Espresso UI test framework doesn't see more than actual View. I doubt seriously that you can check any notification with Espresso.
For this purpose use another Googles testing framework
uiautomator
, which is described as:UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
Here you would find how to use it with Espresso: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
More information:
Documentation(I): https://google.github.io/android-testing-support-library/docs/uiautomator/index.html
Documentation(II): http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html
Visit also: Android Testing: UIAutomator vs Espresso
Check methods that uiatomator
offers. If you won't find it, don't hesitate to add an issue on related to it code.google.com repo.
Hope it will help.

- 1
- 1

- 19,130
- 7
- 81
- 94
Try with this:
onView(withId(android.R.id.statusBarBackground)).check(matches(withBackgroundColor(color)));
You may need a color matcher:
public static Matcher<View> withBackgroundColor(final int colorId) {
Checks.checkNotNull(colorId);
int colorFromResource = ContextCompat.getColor(getTargetContext(), colorId);
return new BoundedMatcher<View, View>(View.class) {
@Override
public boolean matchesSafely(View view) {
int backGroundColor = ((ColorDrawable) view.getBackground()).getColor();
return colorFromResource == backGroundColor;
}
@Override
public void describeTo(Description description) {
}
};
}
Or this one: getCurrentActivity().getWindow().getStatusBarColor();

- 1
- 1