Uriel Frankel Uriel Frankel - 6 months ago 63
Android Question

Android Espresso: Sliding Tabs with RecyclerViews in every tab

I have a sliding tabs app, with recyclerview in every tab.
I am testing the app using Android Espresso. I want to click on one of the recyclerview item. when i do this:

.perform(RecyclerViewActions.actionOnItemAtPosition(2, click()));

I get this exception:

android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.uriel.frankel:id/recyclerView' matches multiple views in the hierarchy.

any Ideas?


Uhm, i guess you are using the same xml file for every RecyclerView in your tabs. Hence all your RecyclerView's have the same ID. So you can't refer to your RecyclerView's using your ID's.

So either give every RecyclerView it's own ID or try searching with any other ViewMatcher like withText("any specific text in your recyclers"). Here you may find methods that will work in your case.