Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AmbiguousViewMatcherException multiple RecyclerViews

I have a Fragment that contains RecyclerView. But since I have a lot of elements in this Fragment, I want to swipe up the list to see and check all the elements that are in this Fragment.

Earlier this method helped me, but now for some reason it does not work:

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp())

I have many RecyclerViews with same id in my project:

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"/>

Also in my tests I've written something like this:

onView(allOf( withId(R.id.recyclerView), isDisplayed()))
onView(withId(R.id.recyclerView)).perform(swipeUp())

But caught error only on second line.

android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.fentury.android:id/recyclerView' matches multiple views in the hierarchy. Problem views are marked with '****MATCHES****' below.

like image 498
Morozov Avatar asked Jun 14 '17 07:06

Morozov


2 Answers

You have multiple views with id R.id.recyclerView in your view hierarchy, therefore espresso lacks to perform correct matching. Make the ids of those RecyclerViews unique.


onView(allOf(withId(R.id.recyclerView), isDisplayed())) onView(withId(R.id.recyclerView)).perform(swipeUp())

But caught error only on second line.

Then perform matching this way:

onView(allOf(withId(R.id.recyclerView), isDisplayed())).perform(swipeUp())
like image 88
azizbekian Avatar answered Oct 29 '22 09:10

azizbekian


Solution:

onView(allOf(withId(R.id.recyclerview), isDisplayed())).perform(swipeUp());
like image 32
Pinak Gauswami Avatar answered Oct 29 '22 08:10

Pinak Gauswami