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");
}
};
}
}