如何在 androidx.test.espresso 上点击指定回收站视图?

How do I click on specify recyclerview on androidx.test.espresso?

我在我的代码中点击特定的 recyclerview 时遇到问题,它仍然出错

Espresso.onView(withId(R.id.recyclerLastMatchlist))
    .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, ViewActions.click()))

这是依赖关系

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'


androidTestImplementation("com.android.support.test.espresso:espresso-contrib:2.2.2") {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}

根据您在 gradle 中的依赖项,您的应用似乎使用的是 com.android.support,而不是 androidx。如果是这种情况,您将得到 NoViewMatchException,因为您的测试试图对 androidx.recyclerview.widget.RecyclerView 而不是 android.support.v7.widget.RecyclerView 执行操作,这显然是不同的。

所以请尝试替换您的依赖项:

//androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//androidTestImplementation 'androidx.test:runner:1.1.0'
//androidTestImplementation 'androidx.test:rules:1.1.0'

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'