Android 8.0 模拟器上的 Espresso webView webkeys 失败
Espresso webView webkeys failures on the Android 8.0 simulator
我是 运行 来自 Espresso Web 的一些测试代码
@Test
public void typeTextInInput_clickButton_SubmitsForm() {
// Lazily launch the Activity with a custom start Intent per test.
mActivityRule.launchActivity(withWebFormIntent());
// Selects the WebView in your layout. If you have multiple WebView objects,
// you can also use a matcher to select a given WebView,
// onWebView(withId(R.id.web_view)).
onWebView()
// Find the input element by ID.
.withElement(findElement(Locator.ID, "text_input"))
// Clear previous input and enter new text into the input element.
.perform(clearElement())
.perform(DriverAtoms.webKeys(MACCHIATO))
// Find the "Submit" button and simulate a click using JavaScript.
.withElement(findElement(Locator.ID, "submitBtn"))
.perform(webClick())
// Find the response element by ID, and verify that it contains the
// entered text.
.withElement(findElement(Locator.ID, "response"))
.check(webMatches(getText(), containsString(MACCHIATO)));
}
它在 7.1.1 模拟器上工作但在 8.0 上不工作
我收到错误消息
Caused by: java.lang.RuntimeException: Error in evaluationEvaluation: status: 13 value: {message=Cannot set the selection end} hasMessage: true message: Cannot set the selection end
如果我更改代码
element.
.perform(clearElement())
.perform(DriverAtoms.webKeys(MACCHIATO)) => perform(webClick())
然后就可以了。所以我猜它可以找到只是不执行操作的元素。
我的代码有什么需要更改的吗?
我遇到了同样的问题。请参考Cant add text to webview text field with Espresso
中的这个post
我的代码适用于 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) 您可能需要解决的以下问题是它可能会抱怨 "versions for app (2x.x.x) and test app (2x.x.x) differ"
所以我在 gradle.
中添加了以下内容
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:2x.x.x'
}
4) 此外,您可能需要确保已添加 Runner。
defaultConfig {
"android.support.test.runner.AndroidJUnitRunner"
}
我是 运行 来自 Espresso Web 的一些测试代码
@Test
public void typeTextInInput_clickButton_SubmitsForm() {
// Lazily launch the Activity with a custom start Intent per test.
mActivityRule.launchActivity(withWebFormIntent());
// Selects the WebView in your layout. If you have multiple WebView objects,
// you can also use a matcher to select a given WebView,
// onWebView(withId(R.id.web_view)).
onWebView()
// Find the input element by ID.
.withElement(findElement(Locator.ID, "text_input"))
// Clear previous input and enter new text into the input element.
.perform(clearElement())
.perform(DriverAtoms.webKeys(MACCHIATO))
// Find the "Submit" button and simulate a click using JavaScript.
.withElement(findElement(Locator.ID, "submitBtn"))
.perform(webClick())
// Find the response element by ID, and verify that it contains the
// entered text.
.withElement(findElement(Locator.ID, "response"))
.check(webMatches(getText(), containsString(MACCHIATO)));
}
它在 7.1.1 模拟器上工作但在 8.0 上不工作 我收到错误消息
Caused by: java.lang.RuntimeException: Error in evaluationEvaluation: status: 13 value: {message=Cannot set the selection end} hasMessage: true message: Cannot set the selection end
如果我更改代码
element.
.perform(clearElement())
.perform(DriverAtoms.webKeys(MACCHIATO)) => perform(webClick())
然后就可以了。所以我猜它可以找到只是不执行操作的元素。 我的代码有什么需要更改的吗?
我遇到了同样的问题。请参考Cant add text to webview text field with Espresso
中的这个post我的代码适用于 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) 您可能需要解决的以下问题是它可能会抱怨 "versions for app (2x.x.x) and test app (2x.x.x) differ" 所以我在 gradle.
中添加了以下内容configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:2x.x.x'
}
4) 此外,您可能需要确保已添加 Runner。
defaultConfig {
"android.support.test.runner.AndroidJUnitRunner"
}