Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso - How to match ActionBar visibility?

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

like image 971
urSus Avatar asked Nov 25 '14 16:11

urSus


Video Answer


1 Answers

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.

like image 188
Daniel Lubarov Avatar answered Oct 30 '22 21:10

Daniel Lubarov