Counting number of text views within a framelayout

12 views
Skip to first unread message

Gowtham JS

unread,
Apr 11, 2019, 1:50:58 PM4/11/19
to Android Testing Support Library
Hello!

I am a newbie to espresso. I have a scenario, where I need to validate if two textviews are present in the screen, they both have the same parent, frame layout. I tried the below, doesn't seem to work.


onView(allOf(withId(R.id.listview),
    isDescendantOfA(withId(R.id.framelayout))
            .check(ViewAssertions.matches (Matchers.withListSize (2)))))

with the following custom matcher

class Matchers {
  public static Matcher<View> withListSize (final int size) {
    return new TypeSafeMatcher<View> () {
      @Override public boolean matchesSafely (final View view) {
        return ((ListView) view).getCount () == size;
      }

      @Override public void describeTo (final Description description) {
        description.appendText ("ListView should have " + size + " items");
      }
    };
  }
}

Reply all
Reply to author
Forward
0 new messages