I have a TextView which has the following text: "line1.\nline2.\n line3"
.
I set the TextView to be ellipsized at the end and limit to maximum two lines. To test that it shows ellipses, I have this code
public static final String TEST_BODY = "line1.\nline2.\nline3.";
//a setup method is called so that mail_cell_body_preview_field is set to above TEST_BODY
//...
public void testMessageSnippetIsVisible() {
onView(withId(R.id.mail_cell_body_preview_field)).check(matches(isDisplayed()));
onView(withId(R.id.mail_cell_body_preview_field)).check(matches(hasEllipsizedText()));
onView(withId(R.id.mail_cell_body_preview_field)).check(matches(withText(TEST_BODY)));
//Add statement to verify that line3 not visible in UI
}
How can I write a test case to verify that in UI, the third line is not visible?
I wrote that matcher to check lines count:
public static TypeSafeMatcher<View> isTextInLines(final int lines) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
return ((TextView) item).getLineCount() == lines;
}
@Override
public void describeTo(Description description) {
description.appendText("isTextInLines");
}
};
}
Usage:
onView(withId(R.id.activity_main_text_tv))
.check(matches(CustomMatchers.isTextInLines(1)));
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