I’m working on Espresso tests for Android and for one of my actions I want to search a list using a SearchView, select an item and then navigate back to the previous screen (by closing the searchview and then pressing the up button).
I’ve tried some things to access the up/collapse button of the SearchView to close it (that don’t work):
onView(withContentDescription(R.string.abc_action_bar_up_description))
onView(withId(R.id.search_close_btn))
onView(withId(R.id.home))
onView(withId(R.id.homeAsUp))
onView(withId(R.id.collapseActionView))
Espresso.pressBack()
(to just navigate back)
I’m hoping someone might know some way to access and close this button, because I have no idea.
Thanks in advance.
Advertisement
Answer
Apparantly I had to press the back button twice to navigate out of it, so if anyone would like to know, you need to use Espresso.pressBack();
twice to get out of the search menu.