Espresso: avoid AmbiguousViewMatcherException by specifying the parent view

714 Views Asked by At

onView(withId(R.id.feeding_name)).check(matches(isDisplayed())); causes AmbiguousViewMatcherException.

Due to multiple fragments on the screen the id "feeding_name" matches multiple views.

I am wondering, if there is any way to specify the parent of the view so that I could do something like onView(withIdAndParentId(R.id.feeding_name, R.id.fragment_show_feeding)).check(matches(isDisplayed()));

1

There are 1 best solutions below

0
On BEST ANSWER

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