OkDroid
OkDroid

Reputation: 195

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.

Upvotes: 7

Views: 9943

Answers (3)

Akshay Nandwana
Akshay Nandwana

Reputation: 1292

Tell it about the ViewHolder.

onView(withId(R.id.recyclerview)).perform(
        RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
          YOUR_POSITION
        )
      )

Upvotes: 2

denys
denys

Reputation: 6910

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.

Upvotes: 13

Victor Hugo Montes
Victor Hugo Montes

Reputation: 1322

Have you tried the ViewActions swipeDown?

Upvotes: 2

Related Questions