# RecyclerViewActions

Artifact: [androidx.test.espresso:espresso-contrib](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/contrib/RecyclerViewActions.java+class:androidx.test.espresso.contrib.RecyclerViewActions)

*** ** * ** ***


```
public final class RecyclerViewActions
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/test/espresso/ViewAction`s to interact `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`. RecyclerView works differently than `https://developer.android.com/reference/android/widget/AdapterView.html`. In fact, RecyclerView is not an AdapterView anymore, hence it can't be used in combination with `https://developer.android.com/reference/androidx/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>)`.

To use `https://developer.android.com/reference/androidx/test/espresso/ViewAction`s in this class use `https://developer.android.com/reference/androidx/test/espresso/Espresso#onView(org.hamcrest.Matcher<android.view.View>)` with a [`Matcher
`](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) that matches your `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`, then perform a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` from this class.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction extends https://developer.android.com/reference/androidx/test/espresso/ViewAction` Most RecyclerViewActions are given a matcher to select a particular view / viewholder within the RecyclerView. |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#actionOnHolderItem(org.hamcrest.Matcher<VH>,androidx.test.espresso.ViewAction)( https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<VH> viewHolderMatcher, https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction )` Performs a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` on a view matched by viewHolderMatcher. |
| `static https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#actionOnItem(org.hamcrest.Matcher<android.view.View>,androidx.test.espresso.ViewAction)( https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html> itemViewMatcher, https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction )` Performs a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` on a view matched by viewHolderMatcher. |
| `static https://developer.android.com/reference/androidx/test/espresso/ViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#actionOnItemAtPosition(int,androidx.test.espresso.ViewAction)( int position, https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction )` Performs a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` on a view at position. |
| `static https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#scrollTo(org.hamcrest.Matcher<android.view.View>)(https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html> itemViewMatcher)` Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the view matched by itemViewMatcher. |
| `static https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#scrollToHolder(org.hamcrest.Matcher<VH>)( https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<VH> viewHolderMatcher )` Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the view matched by viewHolderMatcher. |
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/ViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#scrollToLastPosition()()` Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the last position. |
| `static https://developer.android.com/reference/androidx/test/espresso/ViewAction` | `<VH extends https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions#scrollToPosition(int)(int position)` Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to a position. |

## Public methods

### actionOnHolderItem

```
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> actionOnHolderItem(
    Matcher<VH> viewHolderMatcher,
    ViewAction viewAction
)
```

Performs a `https://developer.android.com/reference/androidx/test/espresso/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 |
|---|---|
| `https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<VH> viewHolderMatcher` | a [`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) that matches an item view holder in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` |
| `https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction` | the action that is performed on the view matched by viewHolderMatcher |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/PerformException` | if there are more than one items matching given viewHolderMatcher. |

### actionOnItem

```
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> actionOnItem(
    Matcher<View> itemViewMatcher,
    ViewAction viewAction
)
```

Performs a `https://developer.android.com/reference/androidx/test/espresso/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 |
|---|---|
| `https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html> itemViewMatcher` | a [`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) that matches an item view in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` |
| `https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction` | the action that is performed on the view matched by itemViewMatcher |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/PerformException` | if there are more than one items matching given viewHolderMatcher. |

### actionOnItemAtPosition

```
public static ViewAction <VH extends RecyclerView.ViewHolder> actionOnItemAtPosition(
    int position,
    ViewAction viewAction
)
```

Performs a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` on a view at position.

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

| Parameters |
|---|---|
| `int position` | position of a view in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` |
| `https://developer.android.com/reference/androidx/test/espresso/ViewAction viewAction` | the action that is performed on the view matched by itemViewMatcher |

### scrollTo

```
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> scrollTo(Matcher<View> itemViewMatcher)
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the view matched by itemViewMatcher.

This approach uses `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder`s 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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#scrollToPosition(int)`.

| Parameters |
|---|---|
| `https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html> itemViewMatcher` | a [`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) that matches an item view in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/PerformException` | if there are more than one items matching given viewHolderMatcher. |

### scrollToHolder

```
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> scrollToHolder(
    Matcher<VH> viewHolderMatcher
)
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the view matched by viewHolderMatcher.

This approach uses `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder`s 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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#scrollToPosition(int)`. Note: scrollTo method is not overloaded, method overloading with generic parameters is not possible.

| Parameters |
|---|---|
| `https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<VH> viewHolderMatcher` | a [`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) that matches an item view holder in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/PerformException` | if there are more than one items matching given viewHolderMatcher. |

### scrollToLastPosition

```
public static @NonNull ViewAction <VH extends RecyclerView.ViewHolder> scrollToLastPosition()
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to the last position.

### scrollToPosition

```
public static ViewAction <VH extends RecyclerView.ViewHolder> scrollToPosition(int position)
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/ViewAction` which scrolls `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` to a position.

| Parameters |
|---|---|
| `int position` | the position of the view to scroll to |