Espresso: how to scroll to the bottom of ScrollView

后端 未结 4 1209
渐次进展
渐次进展 2021-02-05 05:50

How is it possible to scroll down to the bottom of ScrollView in Espresso test? Thanks!

4条回答
  •  轮回少年
    2021-02-05 06:06

    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());
    

提交回复
热议问题