I have a RecyclerView (R.id.recyclerView) where each row has an image (R.id.row_image) and a TextView. I want to click on the image in the first row.
I've tried to use onData(..) but it doesn't seem to work.
The RecyclerView widget manages the display and handling of items in a list. It provides Layout Managers to position these items. This way, you can create customized layout managers for RecyclerView containers. We can use a RecyclerView inside another RecyclerView.
Use RecyclerViewActions
onView(withId(R.id.recyclerView)) .perform(actionOnItemAtPosition(0, click()));
Include this in your gradle script:
dependencies { androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' }
Just to add to Gabor's answer (which is the correct and complete answer since Espresso 2.0).
You may encounter problems at the moment when using espresso-contrib
and RecyclerView
s (see android-test-kit ticket).
A workaround is to add this exclusion in the espresso-contrib
dependency Gabor mentioned above:
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') { exclude group: 'com.android.support', module: 'appcompat' exclude group: 'com.android.support', module: 'support-v4' exclude module: 'recyclerview-v7' }
(This is an answer instead of a comment to Gabor's answer because I don't have the right to post comments yet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With