Member-only story
Dealing with actions and checks on children of a RecyclerView’s item in Espresso tests
While writing UI test for Android with Espresso, you might have noticed that dealing with RecyclerViews is not straightforward as with ListViews.
That’s because RecyclerView inherits from ViewGroup and not from AdapterView and thus you can’t do things like
onData(…)
…
.perform(…)
Fortunately RecyclerViewActions from “espresso-contrib” come in handy, allowing you to doing things like
onView(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(3, click()))
to give you an example.
But when it comes to views inside a RecyclerView’s item, how do you deal with it?
Suppose we have a RecyclerView whose items are editable notes and you want to replace the text contained inside the row or want to check if text contained in the EditText of a given row matches what you expected.
You would usually have to create a custom ViewAction implementation for the particular action to take, for instance