dimanche 5 juillet 2020

How to test nested RecyclerView (RecyclerView inside RecyclerView) with Espresso

I have implemented RecyclerView(childRecyclerView) inside another RecyclerView(parentRecyclerView), picture blow explains all the implentation:

enter image description here

I want to wire an espresso test that checks all TextViews inside the childRecyclerView are with the expected text, I have checked this answer https://stackoverflow.com/a/34141230/3522182, so in my case is this:

onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentRecyclerView).atPosition(0)),
                isDescendantOfA(withRecyclerView(R.id.childRecyclerView).atPosition(0)),
                withId(R.id.textView1)))
                .check(matches(withText("some text")));

it's ok, but the problem I had was that when I pass 1 for atPosition in withRecyclerView(R.id.parentRecyclerView).atPosition(0) I get an error that says the view is not found in the hierarchy:

No views in hierarchy found matching: (is descendant of a: RecyclerView with id: com.example.testapp:id/parentRecyclerView at position: 1

is there another way to test childRecyclerView contents?

Aucun commentaire:

Enregistrer un commentaire