gpt4 book ai didi

android - Espresso webView webkeys 在 Android 8.0 模拟器上失败

转载 作者:搜寻专家 更新时间:2023-11-01 09:32:37 24 4
gpt4 key购买 nike

我正在从 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中的这篇帖子

我的代码适用于 Android 7.1.1 模拟器,但在 Android 8.0 模拟器上也失败。我通过在 build.gradle 中执行以下操作解决了这个问题。

1) 升级 Espresso 库。我在:

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) 此外,您可能需要确保添加了 Runner。

defaultConfig {
"android.support.test.runner.AndroidJUnitRunner"
}

关于android - Espresso webView webkeys 在 Android 8.0 模拟器上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45822957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com