Skip to content Skip to sidebar Skip to footer

In Espresso, How Can I Test That Textview Shows Only Two Lines

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 ellip

Solution 1:

I wrote that matcher to check lines count:

publicstaticTypeSafeMatcher<View> isTextInLines(final int lines) {
    returnnewTypeSafeMatcher<View>() {
        @OverrideprotectedbooleanmatchesSafely(View item) {
            return ((TextView) item).getLineCount() == lines;
        }

        @OverridepublicvoiddescribeTo(Description description) {
            description.appendText("isTextInLines");
        }
    };
}

Usage:

onView(withId(R.id.activity_main_text_tv))
            .check(matches(CustomMatchers.isTextInLines(1)));

Solution 2:

onView(withId(R.id.mail_cell_body_preview_field)).check(matches( ......compare length for this...);

Use text comparison with your text length. like if you have 2 lines then text length is more.

Post a Comment for "In Espresso, How Can I Test That Textview Shows Only Two Lines"