I am using Espresso to test a list view that appears when I am searching for an item (like an autocomplete). The list view does not appear until the user has typed in something into the SearchView. i.e. I set the ListView to View.VISIBLE
only when the user has typed something into the SearchView
I am getting this error when I try to click on text in a list view. android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id:'
. Using onData did not work.
Adding an artificial delay works, but I am unsure if this is bad practice since it seems to defeat the purpose of methods such as onData
etc.
What I've tried:
I've tried seeing what the Espresso test recorder does, but when I use the test recorder's code, I get the error above. I believe this is because the recorder introduces some delay.
I read through these StackOverflow questions but they do not resolve my issue:
My Code
This code works, but I would prefer not to have to introduce an artificial delay.
public pickSuggestion(int index){
/** artificial delay to allow list to appear.
This works but I shouldn't have to do this right? **/
SystemClock.sleep(1000);
onData(anything())
.inAdapterView(withId(R.id.list))
.atPosition(index)
.onChildView(withId(R.id.mTextView))
.perform(click());
}