My Android activity's menu is populated dynamically and i'd like to test the items are shown with Espresso. I know that there should be at least 1 item with title containing some title string "N" and at least 1 item with title string containing "M", eg.:
- Item N1
- Item N2
- Item M1
- Item M2
I'm getting AmbiguousViewMatcherException
exception for the test:
openActionBarOverflowOrOptionsMenu( getInstrumentation().getTargetContext());
// go to subitem level 1
onView(
allOf(
withId(R.id.title),
withText("Settings"),
isDisplayed()))
.perform(click());
SystemClock.sleep(50);
// go to subitem level 2
onView(
allOf(
withId(R.id.title),
withText("Item type"),
isDisplayed()))
.perform(click());
SystemClock.sleep(50);
// items are shown
// assertions
onView(
allOf(withId(R.id.title),
withText("N"),
isDisplayed()))
.check(matches(isDisplayed()));
onView(
allOf(withId(R.id.title),
withText("M"),
isDisplayed()))
.check(matches(isDisplayed()));
What will be the right assertion meaning "at least 1 view with the following assertions (let's say "title contains ... ") is shown"?
I know i can catch the exception and actually it means that the test is passed, but i'd like to do the thing right.