Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one test Support v7 SearchView with Espresso on Android

I am doing some instrumented tests on my app in Android, but hit a wall. I have a SearchView which is from android's v7 support library, and I want to test this somehow. I guess its not directly clickable, since I tried it with conventional ways like:

onView(withId(R.id.search_view)).perform(click())

Is there any way to test such SearchView with Espresso?

like image 323
coras09 Avatar asked Mar 02 '17 16:03

coras09


1 Answers

The solution depends on the initial state of the SearchView.If it is collapsed, you have to open it first:

onView(withId(R.id.your_search_menu_id)).perform(click());

Then you can type into it.

There are two ways:

  1. By search autocomplete id, which is public

    onView(withId(android.support.design.R.id.search_src_text)).perform(typeText("something"));
    
  2. By using the fact, that it is AutoCompleteTextView

    onView(isAssignableFrom(AutoCompleteTextView.class)).perform(typeText("something"));
    
like image 138
R. Zagórski Avatar answered Nov 07 '22 09:11

R. Zagórski