There are a few posts that show how can you click a certain fixed item in the RecyclerView with Espresso, like:
How to click on an item inside a RecyclerView in Espresso
Using Espresso to click view inside RecyclerView item
Example:
//Change the 0 with any other number, will be the position of the item clicked.
onView(withId(R.id.a_main_recycler))
.perform(RecyclerViewActions
.actionOnItemAtPosition(0, click()));
But, what if you want to click on a random item in the RecyclerView?
Use the
getActivity()
method of ActivityTestRule.You will be able to use
findViewById()
(as in any other context) and handle the RecyclerView instance.Example: