Issue
Is ist possible with android-espresso to verify, if a string is shown in one of more items of a listAdapter?
Trying somethiong like this:
onData(anything()).inAdapterView(withId(R.id.test)).check(matches(hasToString("Anmeldung steht noch aus!")));
Solution
This must work but only based on list item position:
onData(instanceOf(YourListItem.class))
.inAdapterView(withId(R.id.test))
.atPosition(0)
.check(matches(hasDescendant(withText("Anmeldung steht noch aus!"))));
If you want to check that the unique text is present somewhere in the adapter - you should create your own matcher, so, it will be something like:
onData(withYourListItemText("Anmeldung steht noch aus!"))
.inAdapterView(withId(R.id.test))
.check(matches(isDisplayed()));
and matcher:
public static Matcher<Object> withYourListItemText(final Matcher<String> yourListItemText) {
Checks.checkNotNull(yourListItemText);
return new BoundedMatcher<Object, YourListItem>(YourListItem.class) {
@Override
public boolean matchesSafely(YourListItem item) {
return yourListItemText.matches(item.getYourItemText());
}
@Override
public void describeTo(Description description) {
description.appendText("with text: " + yourListItemText.toString());
yourListItemText.describeTo(description);
}
};
}
Answered By - denys
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.