Issue
I know that we can use expresso to check view outputs as such: onView((withId(R.id.text_view_name))).check(matches(withText("text_value_here")));
to see if outputs are as expected, but what if we want to make sure it is within a certain range of values? For instance, not below 0.
How can you write test code using espresso that makes sure a UI value is below, above, or within a certain range of values?
Solution
It can be done easily with a custom matcher:
public class TextViewValueMatcher extends TypeSafeMatcher<View> {
@Override
protected boolean matchesSafely(View item) {
TextView textView = (TextView) item;
String value = textView.getText().toString();
boolean matching = <here your condition on the value>;
return matching;
}
@Override
public void describeTo(Description description) {
}
}
And then used as the following:
Espresso.onView(withId(<some_id>)).check(matches(new TextViewValueMatcher()));
Answered By - Anatolii
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.