ligi ligi - 5 months ago 47
Android Question

click home icon with espresso

I am trying to click the home icon in some espresso tests via:

onView(withId(android.R.id.home)).perform(click());


this works fine for Android>3.0 - but fails below as appcompat does not seem to use this id for this element then. What is a good approach to do what I want to do?

Answer

Use the withContentDescription() Matcher:

onView(withContentDescription("Navigate up")).perform(click());