I'm testing with espresso and I have multiple AdapterViews in one page, for example, with id: R.id.list1, R.id.list2, when I use
onData(withMainValue("xx")).check(matches(isDisplayed()))
public static Matcher<Object> withMainValue(final String value) {
return new BoundedMatcher<Object,
GuessYouLikeGoodItem.DataEntity>(GuessYouLikeGoodItem.DataEntity.class) {
@Override public void describeTo(Description description) {
description.appendText("has value " + value);
}
@Override public boolean matchesSafely(
GuessYouLikeGoodItem.DataEntity item) {
return item.store_name.contains(value);
}
};
}
,
the Espresso reports:
android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
How to select the specific listview and try onData on it ?
If you have multiple listview with unique id, you should be able to check is one of the list is displayed
onView(withId(R.id.list1)).check(matches(isDisplayed()));
If you want to go inside AdapterView, this will allow you to click an element inside listview
onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With