Espresso: how to scroll to the bottom of ScrollView

Issue

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

Solution

If at the bottom of the ScrollView you need to find a view and match something against it, then simply perform the scrollTo() action on it, before any other actions that require it to be displayed.

onView(withId(R.id.onBottomOfScrollView))
    .perform(scrollTo(), click());

Note: scrollTo will have no effect if the view is already displayed so you can safely use it in cases when the view is displayed

Answered By – appoll

Leave a Comment