Testing the UI Eschedo Nested Recycler Views

I have a horizontal RecyclerViewinside a vertical RecyclerView. I am using this code, which I found on another question:

onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(parentPosition)),
             isDescendantOfA(withRecyclerView(R.id.childHorizontalRecyclerView).atPosition(childPosition)),
                (withText("USA"))))
                .perform(click());

// It is not working for parentPosition > 0

but this only works for the first line of the parent RecyclerView.

How do I click an element on the child RecyclerView of the second row of the parent RecyclerView?

+4
source share
1 answer

I finally understood the solution for this:

onView(allOf(
         withId(R.id.childHorizontalRecyclerView),
         withParent(
           withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(2)
         )
       )
).perform(RecyclerViewActions.actionOnItemAtPosition(3, scrollTo()))
.check(matches(hasDescendant(withText("USA")))); 
+2
source

Source: https://habr.com/ru/post/1673481/


All Articles