android - 如何单击 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'
推荐阅读
- java - 如何获取 setOnItemSelectedListener 之外的变量的更新值?
- php - 创建可用 WooCommerce 优惠券代码列表并使用简码在任何地方显示
- reactjs - 在反应中通过 Route 传递道具。将属性从组件树的子级发送到其他组件
- javascript - 如何在打印 mat-dialog 时隐藏 @media print 的 Angular 9 背景组件?
- javascript - useEffect 仍然触发比较同一个对象?
- amazon-web-services - Aws 如何使用 Java SDK 知道 Bucket 的区域
- computation-theory - 在输入 x 上计算字典顺序中的下一个单词的 TM 的正式描述
- vue.js - 将数据从子组件传递到父组件Vue js
- jmeter-5.0 - 在 BIN 文件夹中找不到 ApacheJMeterTemporaryRootCA.crt
- python - AttributeError: 'DataFrame' 对象没有属性 'cat' 和一系列异常