My app reloads data when a down-swipe is done on a SwipeRefreshLayout
. Now I try to test this with Android Test Kit / Espresso like this:
onView
Sleeping over it sometimes helps. The underlying reason was that the to-be-swiped view was only 89% visible to the user, while Espresso's swipe actions internally demand 90%. So the solution is to wrap the swipe action into another action and override these constraints by hand, like this:
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return constraints;
}
@Override
public String getDescription() {
return action.getDescription();
}
@Override
public void perform(UiController uiController, View view) {
action.perform(uiController, view);
}
};
}
This can then be called like this:
onView(withId(R.id.my_refresh_layout))
.perform(withCustomConstraints(swipeDown(), isDisplayingAtLeast(85));