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?
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:
By search autocomplete id, which is public
onView(withId(android.support.design.R.id.search_src_text)).perform(typeText("something"));
By using the fact, that it is AutoCompleteTextView
onView(isAssignableFrom(AutoCompleteTextView.class)).perform(typeText("something"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With