问题描述
我是Android Espresso库的新手。尝试在 ViewPager
中单击 RecyclerView
项目。我搜索了互联网,但没有发现任何有关ViewPager的信息。所以我的问题是:如何使用Espresso在 ViewPager
中访问 RecyclerView
来执行点击?
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?
推荐答案
假设您想点击 buttonClick ,这是您的RecyclerView中按钮的ID。
Let's suppose you want to tap on buttonClick, which is the id of a button inside your RecyclerView.
我使用此代码:
onView(allOf(withId(R.id.buttonToClick), isCompletelyDisplayed()))
.perform(click());
这将获取当前显示的此ID并执行单击的视图。
This gets the view with this id which is currently displayed and performs a click on it.
希望这会有所帮助。
PS:此外,在 espresso-contrib 上还有 RecyclerViewActions
您可以使用: actionOnHolderItem
, actionOnItem
和 actionOnItemAtPosition
。您可以执行以下操作:
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()));
这篇关于ViewPager中的Espresso RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!