I'm trying to write an Espresso test that will typeText in a custom SearchView. The custom SearchView is here:
https://github.com/MiguelCatalan/MaterialSearchView/tree/develop/library/src/main/res/layout
I'm using it in my MainActivity. If I directly call 'typeText' on this SearchView, it throws an error because I actually need to get the EditText from this SearchBar.
The EditText is in search_view.xml
I think the Espresso command should look like:
onView(get EditText from SearchView).perform(typeText("chicken"));
How should I get the EditText reference?
Doesn't matter, I found a solution.
I got my 'search' view in the Unit test and then I started looping through its children.
When I found the EditText, then I called onView.
Here's the code. Hope it will help someone:
search = (SearchBox) mActivityRule.getActivity().findViewById(R.id.searchbox);
for( int i = 0; i < search.getChildCount(); i++ )
if( search.getChildAt( i ) instanceof EditText) {
onView(withId(search.getChildAt(i).getId())).perform(typeText("soup" + '\n'));
}
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