Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 for older versions 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?

like image 264
ligi Avatar asked Jun 01 '14 22:06

ligi


2 Answers

To not depend on the app locale, you can use the code from Matt Logan by replacing "Navigate up" with R.string.abc_action_bar_up_description:

onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click()); 

This helped me a lot because I have an app in more than 5 languages and I had to act like this.

like image 78
sunlover3 Avatar answered Sep 19 '22 12:09

sunlover3


Use the withContentDescription() Matcher:

onView(withContentDescription("Navigate up")).perform(click()); 
like image 28
Matt Logan Avatar answered Sep 18 '22 12:09

Matt Logan