How to click on an item inside a RecyclerView in Espresso
Solution 1:
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'
}
Solution 2:
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)