6

Im trying to do a Espresso test for checking if actionbar is hidden/shown, but I cant seem to figure out how to match it with Espresso.onView(...). Afaik it doesnt have a id, right?

Thanks a lot

urSus
  • 12,492
  • 12
  • 69
  • 89

1 Answers1

4

The action bar view has an ID but it's not exposed. 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 haven't tested it.

Community
  • 1
  • 1
Daniel Lubarov
  • 7,796
  • 1
  • 37
  • 56