Scrolling Recycler view with Espresso
Asked Answered
C

3

7

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.

Commonly answered 2/11, 2017 at 21:57 Comment(0)
C
13

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.

Coherent answered 3/11, 2017 at 21:56 Comment(0)
C
2

Have you tried the ViewActions swipeDown?

Colander answered 2/11, 2017 at 22:14 Comment(0)
S
2

Tell it about the ViewHolder.

onView(withId(R.id.recyclerview)).perform(
        RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
          YOUR_POSITION
        )
      )
Saddle answered 9/3, 2022 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.