Espresso - How to match the visibility of an ActionBar?

I am trying to run an Espresso test to verify that the action bar is hidden / shown, but I cannot figure out how to match it with Espresso.onView (...). Afaik he does not have an identifier, right?

Thank you so much

+4
source share
1 answer

The action bar view has an identifier, but it does not appear. We can get it with getIdentifier:

Resources resources = getInstrumentation().getTargetContext().getResources();
int actionBarId = resources.getIdentifier("action_bar_container", "id", "android");
onView(withId(actionBarId)).check(matches(isDisplayed()));

Code adapted from this related answer . I think this will work, but I have not tested it.

+4
source

All Articles