Reputation: 313
I am new to Android Espresso library. Trying to test click on RecyclerView
item inside the ViewPager
. I've searched the Internet but found nothing about ViewPager. So my question is: how to access RecyclerView
inside a ViewPager
using Espresso to perform click?
Upvotes: 1
Views: 2496
Reputation: 18022
Let's suppose you want to tap on buttonClick, which is the id of a button inside your RecyclerView.
I use this code:
onView(allOf(withId(R.id.buttonToClick), isCompletelyDisplayed()))
.perform(click());
This gets the view with this id which is currently displayed and performs a click on it.
Hope this helps.
P.S.: Also, on espresso-contrib there are RecyclerViewActions
that maybe you can use: actionOnHolderItem
, actionOnItem
and actionOnItemAtPosition
. You can do something like:
onView(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
Upvotes: 3