Android Espresso – Closing the SearchView

Tags: , , , ,

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(
  • onView(withId(
  • onView(withId(
  • onView(withId(
  • 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.


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.

Source: stackoverflow