我想为我的 Android 应用创建 Espresso 测试。我有一个StaggeredGridView
(StaggeredGridView Github),其中有很多由自定义模型()制成的网格项目(~1000 Recipe.class
)
<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());
这是一个错误,还是我错过了一些参数?