How to click on an item inside a RecyclerView in Espresso

前端 未结 10 2301
逝去的感伤
逝去的感伤 2020-12-01 05:33

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

10条回答
  •  粉色の甜心
    2020-12-01 05:50

    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 RecyclerViews (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)

提交回复
热议问题