如何点击上androidx.test.espresso指定recyclerview?

问题描述 投票:0回答:1

我有问题点击特定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'
}
android kotlin android-espresso android-instrumentation
1个回答
0
投票

根据您的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'
© www.soinside.com 2019 - 2024. All rights reserved.