android / android/android-test
ActionOnItemAtPositionViewAction does not take into account the provided ViewAction's constraints
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### Description
`ActionOnItemAtPositionViewAction` calls `getDescription()` and `perform()` of its `viewAction` field, but it never calls its `getConstraints()`. So, the action is run regardless if the item view satisfies the constraints or not.
### Steps to Reproduce
Execute in unit test (with robolectric)
```kotlin
onView(withId(R.id.myRecyclerView)).perform(
actionOnItemAtPosition(
0, clickOnChildView(R.id.childView)))
```
where
```kotlin
fun clickOnChildView(childId: Int) = object : ViewAction {
override fun getDescription(): String =
"Click on child view with id $childId"
override fun getConstraints(): Matcher = isDisplayed()
override fun perform(uiController: UiController?, view: View?) {
view?.findViewById(childId)?.performClick()
}
}
```
and
```kotlin
childView.visibility == View.GONE
```
### Expected Results
The action should fail since the child view is not displayed.
### Actual Results
The child view is clicked as if displayed.
### AndroidX Test and Android OS Versions
core 1.3.0
rules 1.3.0
espresso 3.3.0
junit-ktx 1.1.2
robolectric 4.3.1
android API 29
Contributor guide
Research direction
Start at the ActionOnItemAtPositionViewAction entry point and reproduce the issue with the Robolectric unit-test example from the report. Verify that a child view failing the provided ViewAction constraint prevents the action from being performed, while a displayed child still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100