Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling Recycler view with Espresso

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.

like image 456
OkDroid Avatar asked Nov 02 '17 21:11

OkDroid


People also ask

How do you scroll on recycler view Espresso?

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.

How do you scroll down in Espresso?

4 Answers. Show activity on this post. You can use SWIPE to scroll to the bottom of the screen: Espresso.

Is a recycler view scrollable?

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.


3 Answers

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.

like image 140
denys Avatar answered Oct 12 '22 20:10

denys


Have you tried the ViewActions swipeDown?

like image 21
Victor Hugo Montes Avatar answered Oct 12 '22 18:10

Victor Hugo Montes


Tell it about the ViewHolder.

onView(withId(R.id.recyclerview)).perform(
        RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
          YOUR_POSITION
        )
      )
like image 2
Akshay Nandwana Avatar answered Oct 12 '22 20:10

Akshay Nandwana