As I understand it, in espresso you can only perform one action for one item at a time. I think I cannot get a list of elements by name or class name or the like. therefore, if we have a container like RecyclerView, we can perform actions on it with children in a loop. Like this:
for (int i = 0; i <= num; i++) {
onView(withId(R.id.result)).perform(RecyclerViewActions.actionOnItemAtPosition(i, click()));
}
and we can get the number of children:
public int getRecyclerViewChildCount(int matcher) {
final int[] count = {0};
onView(withId(matcher)).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(RecyclerView.class);
}
@Override
public String getDescription() {
return "getting child count";
}
@Override
public void perform(UiController uiController, View view) {
RecyclerView rv = (RecyclerView) view;
count[0] = rv.getChildCount();
}
});
return count[0];
}
, , , , . , .
, , PerformException, :
try {
int count = 50;// specify number of child elements in RecycleView you want to click
for (int i = 0; i <= count; i++) {
onView(withId(R.id.result)).perform(RecyclerViewActions.actionOnItemAtPosition(i, click()));
}
}catch(PerformException e){}//if argument is greater then files in search result.