我是espresso UI测试的新手,正在尝试计算应用程序特定屏幕中显示的文本视图的数量。我尝试了以下类似的方法
onView(allOf(withId(R.id.listview),
isDescendantOfA(withId(R.id.framelayout))
.check(ViewAssertions.matches (Matchers.withListSize (2)))))
使用以下自定义匹配器
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");
}
};
}
}
我尝试了此处提到的那个,Espresso count elements不适用于最新版本。