Espresso not triggering SelectionTracker
Description
A longClick() with RecyclerViewActions.actionOnItemAtPosition does not trigger the selection of the item in a RecyclerView that has been passed to a SelectionTracker.
Steps to Reproduce
Set up a SelectionTracker with a RecyclerView in a Fragment.
Use launchActivity and onActivity set the Fragment to the Activity.
longClick() an item in the RecyclerView
Notice that nothing was selected.
It is worth noting that if debugging, and at a breakpoint, if you manually longClick(), a selection will be triggered.
Expected Results
The SelectionTracker to be triggered by a longClick() on an item in the RecyclerView passed to it, therefore triggering a selection.
Actual Results
The SelectionTracker was not triggered by a longClick() on an item in the RecyclerView passed to it, and a selection was not triggered.
AndroidX Test and Android OS Versions
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Android 11
Here is some context:
https://stackoverflow.com/questions/72538316/how-do-you-use-espresso-to-test-a-selectiontracker?noredirect=1#comment128138564_72538316
val cdl = CountDownLatch(1)
scenario.onActivity {
val recyclerView = it.findViewById<RecyclerView>(R.id.fragment_editor_recycler_view)
val ite = recyclerView.getChildAt(0)
ite.getLocationOnScreen(location)
cdl.countDown()
}
cdl.await()
onView(isRoot()).perform(
GeneralClickAction(
Tap.LONG,
{ FloatArray(location.size){ i -> (location[i]+1).toFloat() } },
Press.FINGER,
InputDevice.SOURCE_UNKNOWN,
MotionEvent.BUTTON_PRIMARY
)
)
Long click still does not trigger SelectionTracker when clicked through the root view. I have verified it is connected to the Fragment's RecyclerView. This is clearly a bug.
InputDevice seems to be the culprit. Changing the default value to something like SOURCE_TOUCHSCREEN or SOURCE_MOUSE triggered the SelectionTracker for us.
- ViewActions.click()
+ ViewActions.click(InputDevice.SOURCE_TOUCHSCREEN, MotionEvent.BUTTON_PRIMARY)
I'm not sure what changed between 1.5.0 betas and 1.5.0 stable though.