Espresso: How To Test Swiperefreshlayout?
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(withId(R.id.my_refresh_layout)).per
Solution 1:
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:
publicstaticViewActionwithCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
returnnewViewAction() {
@OverridepublicMatcher<View> getConstraints() {
return constraints;
}
@OverridepublicStringgetDescription() {
return action.getDescription();
}
@Overridepublicvoidperform(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)));
Post a Comment for "Espresso: How To Test Swiperefreshlayout?"