How is it possible to scroll down to the bottom of ScrollView in Espresso test? Thanks!
For completeness (based on Morozov's answer), you can pass a custom ViewAction
instead of scrollTo()
, which allows to use NestedScrollView
:
ViewAction customScrollTo = new ViewAction() {
@Override
public Matcher getConstraints() {
return allOf(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), isDescendantOfA(anyOf(
isAssignableFrom(ScrollView.class),
isAssignableFrom(HorizontalScrollView.class),
isAssignableFrom(NestedScrollView.class)))
);
}
@Override
public String getDescription() {
return null;
}
@Override
public void perform(UiController uiController, View view) {
new ScrollToAction().perform(uiController, view);
}
};
And use it like this:
onView(withId(R.id.onBottomOfScrollView)).perform(customScrollTo, click());