I have a heterogeneous recycler view and I am trying to scroll it to item at position 30. My test is passing but I cannot see the screen actually scrolling.
onView(withId(R.id.content_view))
.perform(RecyclerViewActions.scrollToPosition(30));
This is what I am doing to scroll.
To interact with RecyclerViews using Espresso, you can use the espresso-contrib package, which has a collection of RecyclerViewActions that can be used to scroll to positions or to perform actions on items: scrollTo() - Scrolls to the matched View, if it exists.
4 Answers. Show activity on this post. You can use SWIPE to scroll to the bottom of the screen: Espresso.
To help you build apps with lists, Android provides the RecyclerView . RecyclerView is designed to be very efficient, even with large lists, by reusing, or recycling, the views that have scrolled off the screen.
Use scrollToHolder()
:
onView(withId(R.id.recyclerViewId))
.perform(scrollToHolder(viewHolderMatcher(some_parameter_to_match)));
where viewHolderMatcher(some_parameter_to_match)
returns Matcher<RecyclerView.ViewHolder>
i.e. the position of the holder/item in the RecyclerView.
Or only by position:
onView(withId(rvLayoutId))
.perform(actionOnItemAtPosition(256, scrollTo()));
last one is from here.
Have you tried the ViewActions swipeDown?
Tell it about the ViewHolder.
onView(withId(R.id.recyclerview)).perform(
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
YOUR_POSITION
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With