android / android/android-test
`RecyclerViewActions::itemsMatching` doesn't work properly with the latest (1.2.1) RecyclerVivew
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### Description
After bumping RecyclerView to 1.2.1 the `RecyclerViewActions::itemsMatching` doesn't work as expected
### Steps to Reproduce
Since RecyclerView 1.2.1 this matcher doesn't work as expected
```kotlin
class RecyclerViewTest {
@get:Rule
internal val rule = activityScenarioRule()
@Test
fun findItem() {
Espresso
.onView(ViewMatchers.isAssignableFrom(RecyclerView::class.java))
.perform(RecyclerViewActions.scrollToHolder(layoutPositionMatcher(0)))
}
private fun layoutPositionMatcher(layoutPosition: Int): Matcher =
object : TypeSafeMatcher() {
override fun matchesSafely(item: VH): Boolean = if (item != null) {
item.layoutPosition == layoutPosition
} else {
false
}
override fun describeTo(description: Description) {
description.appendText(" Position matching ")
}
}
}
```
### Expected Results
Test succeeded
### Actual Results
```
java.lang.RuntimeException: Found more than one sub-view matching Position matching
```
Looks like the `RecyclerViewActions::itemsMatching` [should be updated](https://github.com/android/android-test/blob/9d25d24ec7abe5021672c0423a992e87b44eb261/espresso/contrib/java/androidx/test/espresso/contrib/RecyclerViewActions.java#L453) since new `Adapter` member `mBindingAdapter` is not cleared during `Adapter::onViewRecycled`
### AndroidX Test and Android OS Versions
Any of these versions:
- `androidx.test.espresso:espresso-core:3.3.0`
- `androidx.test.espresso:espresso-core:3.4.0-rc01`
### Link to a public git repo demonstrating the problem:
The complete project can be found [here](https://bitbucket.org/Bakiev/espressoandrecyclerview/src/main/)
Contributor guide
Research direction
Start with RecyclerViewActions.java at the itemsMatching implementation linked in the issue, then reproduce the failure using the provided Kotlin test and RecyclerView 1.2.1. Check the adapter and recycling behavior described in the report; done means the reproduction no longer reports multiple matching sub-views and the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, kotlin
- Domain
- mobile, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100