I want to create Espresso tests for my Android app. I have a StaggeredGridView
(StaggeredGridView Github ) with lots of grid items (~1000) made of custom models (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>
The grid items are a simple LinearLayout
with Image
and TextView
.
The problem is when I want to click on an element which is not visible on screen then the Espresso stucks and not scroll to it to perfom an action.
I've tried the following (if I change the position to 1, then it works fine):
onData(anything()).inAdapterView(withId(R.id.mainPageGridView))
.atPosition(5)
.perform(click());
And tried this:
onData(anything()).inAdapterView(withId(R.id.mainPageGridView))
.atPosition(5)
.perform(scrollTo(), click());
Is it a bug, or am I missing some params?