3

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.

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
santidoo
  • 1,913
  • 2
  • 12
  • 10

2 Answers2

0

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:

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.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
-1

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();

Juan
  • 1
  • 1