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?
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.
PS: 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()));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.