我面临着同样的问题。请参考这篇文章无法使用 Espresso 将文本添加到 webview 文本字段 https://stackoverflow.com/questions/45571968/cant-add-text-to-webview-text-field-with-espresso/45761498#45761498
我的代码适用于 Android 7.1.1 模拟器,但在 Android 8.0 模拟器上也失败。
我通过在 build.gradle 中执行以下操作解决了这个问题。
1) 升级浓缩咖啡库。
我当时在:
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2')
现在它:
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test:rules:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:3.0.0')
2) 执行此操作后,您的应用程序可能无法构建。它可能会说找不到 test:runner:1.0.0
在这种情况下,您需要添加
repositories {
maven { url "https://maven.google.com" }
}
3) 您可能需要解决的以下问题是它可能会抱怨“应用程序 (2x.x.x) 和测试应用程序 (2x.x.x) 的版本不同”
所以我在gradle中添加了以下内容。
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:2x.x.x'
}
4) 另外,您可能需要确保添加了跑步者。
defaultConfig {
"android.support.test.runner.AndroidJUnitRunner"
}