android / android/android-test
[FR] Assert an item is present or not in RecyclerView.
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### Description
I'm looking for an easy way to assert whether an element is present or not in RecyclerView, without having to scroll (the element might or might not be currently on screen). I found a workaround was to assert that clicking the item throws an exception:
```java
Assert.assertThrows(PerformException.class, () -> onView(recyclerView)
.perform(RecyclerViewActions.actionOnItem(matcher, click())));
```
But I'd prefer to write something like the following instead, which is more precise and direct:
```java
onView(recyclerView).perform(RecyclerViewActions.hasItemMatching(matcher)));
```
See also this [Medium post](https://medium.com/koala-tea-assurance/better-android-recyclerview-testing-a5e3ed7ef38b) where the author implements a RecyclerViewAssertions class along these lines.
Contributor guide
Research direction
Start with RecyclerViewActions, especially actionOnItem, and compare the requested API with the RecyclerViewAssertions approach described in the linked Medium post. Define completion as a direct assertion that determines whether a matching RecyclerView item exists, including items not currently on screen, without using a click workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100