我想为我的Android应用程序创建Espresso测试。我有一个包含许多自定义模型(Recipe.class
)的StaggeredGridView
(StaggeredGridView Github),其中包含大量网格项(约1000个)。
<com.etsy.android.grid.StaggeredGridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainPageGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="main_grid"
android:descendantFocusability="blocksDescendants"
app:column_count="2"
app:item_margin="8dp">
</com.etsy.android.grid.StaggeredGridView>
网格项是一个简单的LinearLayout
,其中包含Image
和TextView
。
问题在于,当我想点击屏幕上不可见的元素时,Espresso会卡住,并且无法滚动以执行操作。
我已经尝试了以下方法(如果我将位置更改为1,则可以正常工作):
onData(anything()).inAdapterView(withId(R.id.mainPageGridView))
.atPosition(5)
.perform(click());
我已经尝试过这个方法:
onData(anything()).inAdapterView(withId(R.id.mainPageGridView))
.atPosition(5)
.perform(scrollTo(), click());
这是一个bug吗,还是我漏了一些参数?