Issue
I have this code:
onView(withId(R.id.my_view)).check(matches(isDisplayed()))
How can I add my own message to it in case of a fall of the test with an error? For example as in junit:
assertEquals("My message", expected, actual)
Solution
You could write your own custom matcher. The following code will check the hint in a EditText. Check out this example:
private Matcher<View> withHint(final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public boolean matchesSafely(EditText view) {
final CharSequence hint = view.getHint();
return hint != null && stringMatcher.matches(hint.toString());
}
@Override
public void describeTo(Description description) {
description.appendText("YOUR WHATEVER CUSTOM MESSAGE");
stringMatcher.describeTo(description);
}
};
}
Answered By - mbob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.