[英]How do I click on specify recyclerview on androidx.test.espresso?
我在單擊我的代碼時在指定recylcer視圖時遇到問題,仍然出錯
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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.