class RecyclerViewActions


ViewActions to interact RecyclerView. RecyclerView works differently than . In fact, RecyclerView is not an AdapterView anymore, hence it can't be used in combination with onData.

To use ViewActions in this class use onView with a Matcher that matches your RecyclerView, then perform a ViewAction from this class.

Summary

Nested types

Most RecyclerViewActions are given a matcher to select a particular view / viewholder within the RecyclerView.

Public functions

java-static RecyclerViewActions.PositionableRecyclerViewAction!
<VH : RecyclerView.ViewHolder?> actionOnHolderItem(
    viewHolderMatcher: Matcher<VH!>!,
    viewAction: ViewAction!
)

Performs a ViewAction on a view matched by viewHolderMatcher.

java-static RecyclerViewActions.PositionableRecyclerViewAction!
<VH : RecyclerView.ViewHolder?> actionOnItem(
    itemViewMatcher: Matcher<View!>!,
    viewAction: ViewAction!
)

Performs a ViewAction on a view matched by viewHolderMatcher.

java-static ViewAction!
<VH : RecyclerView.ViewHolder?> actionOnItemAtPosition(
    position: Int,
    viewAction: ViewAction!
)

Performs a ViewAction on a view at position.

java-static RecyclerViewActions.PositionableRecyclerViewAction!
<VH : RecyclerView.ViewHolder?> scrollTo(itemViewMatcher: Matcher<View!>!)

Returns a ViewAction which scrolls RecyclerView to the view matched by itemViewMatcher.

java-static RecyclerViewActions.PositionableRecyclerViewAction!
<VH : RecyclerView.ViewHolder?> scrollToHolder(
    viewHolderMatcher: Matcher<VH!>!
)

Returns a ViewAction which scrolls RecyclerView to the view matched by viewHolderMatcher.

java-static ViewAction

Returns a ViewAction which scrolls RecyclerView to the last position.

java-static ViewAction!

Returns a ViewAction which scrolls RecyclerView to a position.

Public functions

actionOnHolderItem

java-static fun <VH : RecyclerView.ViewHolder?> actionOnHolderItem(
    viewHolderMatcher: Matcher<VH!>!,
    viewAction: ViewAction!
): RecyclerViewActions.PositionableRecyclerViewAction!

Performs a ViewAction on a view matched by viewHolderMatcher.

  1. Scroll Recycler View to the view matched by itemViewMatcher
  2. Perform an action on the matched view
Note: actionOnItem method is not overloaded, method overloading with generic parameters is not possible.
Parameters
viewHolderMatcher: Matcher<VH!>!

a Matcher that matches an item view holder in RecyclerView

viewAction: ViewAction!

the action that is performed on the view matched by viewHolderMatcher

Throws
androidx.test.espresso.PerformException

if there are more than one items matching given viewHolderMatcher.

actionOnItem

java-static fun <VH : RecyclerView.ViewHolder?> actionOnItem(
    itemViewMatcher: Matcher<View!>!,
    viewAction: ViewAction!
): RecyclerViewActions.PositionableRecyclerViewAction!

Performs a ViewAction on a view matched by viewHolderMatcher.

  1. Scroll Recycler View to the view matched by itemViewMatcher
  2. Perform an action on the matched view
Parameters
itemViewMatcher: Matcher<View!>!

a Matcher that matches an item view in RecyclerView

viewAction: ViewAction!

the action that is performed on the view matched by itemViewMatcher

Throws
androidx.test.espresso.PerformException

if there are more than one items matching given viewHolderMatcher.

actionOnItemAtPosition

java-static fun <VH : RecyclerView.ViewHolder?> actionOnItemAtPosition(
    position: Int,
    viewAction: ViewAction!
): ViewAction!

Performs a ViewAction on a view at position.

  1. Scroll Recycler View to position
  2. Perform an action on the view at position
Parameters
position: Int

position of a view in RecyclerView

viewAction: ViewAction!

the action that is performed on the view matched by itemViewMatcher

scrollTo

java-static fun <VH : RecyclerView.ViewHolder?> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction!

Returns a ViewAction which scrolls RecyclerView to the view matched by itemViewMatcher.

This approach uses ViewHolders to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a scrollToPosition.

Parameters
itemViewMatcher: Matcher<View!>!

a Matcher that matches an item view in RecyclerView

Throws
androidx.test.espresso.PerformException

if there are more than one items matching given viewHolderMatcher.

scrollToHolder

java-static fun <VH : RecyclerView.ViewHolder?> scrollToHolder(
    viewHolderMatcher: Matcher<VH!>!
): RecyclerViewActions.PositionableRecyclerViewAction!

Returns a ViewAction which scrolls RecyclerView to the view matched by viewHolderMatcher.

This approach uses ViewHolders to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a scrollToPosition. Note: scrollTo method is not overloaded, method overloading with generic parameters is not possible.

Parameters
viewHolderMatcher: Matcher<VH!>!

a Matcher that matches an item view holder in RecyclerView

Throws
androidx.test.espresso.PerformException

if there are more than one items matching given viewHolderMatcher.

scrollToLastPosition

java-static fun <VH : RecyclerView.ViewHolder?> scrollToLastPosition(): ViewAction

Returns a ViewAction which scrolls RecyclerView to the last position.

scrollToPosition

java-static fun <VH : RecyclerView.ViewHolder?> scrollToPosition(position: Int): ViewAction!

Returns a ViewAction which scrolls RecyclerView to a position.

Parameters
position: Int

the position of the view to scroll to