In Espresso, How to Avoid Ambiguousviewmatcherexception When Multiple Views Match

In Espresso, how to avoid AmbiguousViewMatcherException when multiple views match

You should use onData() to operate on GridView:

onData(withId(R.id.item_image))
.inAdapterView(withId(R.id.grid_adapter_id))
.atPosition(0)
.perform(click());

This code will click on the image inside first item in GridView

Espresso: avoid AmbiguousViewMatcherException by specifying the parent view

You could try combination of matchers with allOf, like for example:

onView(allOf(withId(R.id.feeding_name), withParent(withId(R.id.fragment_show_feeding))))
.check(matches(isDisplayed()));

AmbiguousViewMatcherException multiple RecyclerViews

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())

Espresso: matches multiple views in the hierarchy

Yes.

It seems like your assumption is correct.

The Material Lib uses an internal view called InternalEditText.

You will need to specify an extra matcher to match the correct view.

Espresso AmbiguousViewMatcherException when trying to click a navigation button

This is not a bug in Espresso. The view hierarchy clearly shows two views having the same ID. This is likely due to the view being inside a ViewPager, which is an AdapterView. So multiple instances are to be expected.

To solve this, be more specific when matching the view. Going just by ID doesn't help. Since the other ImageView for the home button is not visible, because it's parent is GONE, you can simply match for that:

onView(allOf(withId(..), withEffectiveVisibility(VISIBLE))).perform(click());


Related Topics



Leave a reply



Submit