我有一个列表,其中textView @ + id / job_status在页面中存在次数。我需要找到它的计数并断言它。
情景:
Filter(5)
<Item1>
<Item2>
<Item3>
我需要检查显示的计数过滤器(“5”)是否与列表中显示的项目数相同。
我尝试过以下方法:
public static class RecyclerViewAssertion implements ViewAssertion {
private final int expectedCount;
public RecyclerViewAssertion(int expectedCount) {
this.expectedCount = expectedCount;
}
@Override
public void check(View view, NoMatchingViewException
noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.Adapter adapter = recyclerView.getAdapter();
assertThat(adapter.getItemCount(), is(expectedCount));
}
}
onView (withId(android.R.id.list)).check(new
JobsPage.RecyclerViewAssertion(5));
它引发了我的错误说:android.R.id.list匹配层次结构中的多个视图。此ID已在应用的多个位置使用。这个问题还有其他办法吗?