Android 8.0模拟器上的Espresso webView webkeys故障 [英] Espresso webView webkeys failures on the Android 8.0 simulator

查看:89
本文介绍了Android 8.0模拟器上的Espresso webView webkeys故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Espresso Web运行一些测试代码

I am running some test codes from 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上无效我收到错误消息为

It worked on the 7.1.1 simulator but not on the 8.0 I got the error message as

由以下原因引起:java.lang.RuntimeException:评估错误评估:状态:13值:{message =无法设置选择结束} hasMessage:正确消息:无法设置选择结束

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())

然后它起作用.因此,我猜它可以找到仅不执行操作的元素.我需要更改代码中的任何内容吗?

Then it works. So I guess it can find the element just not perform the action. Is there anything I need to change in my code?

推荐答案

我正面临着同样的问题.请在无法将文本添加到使用Espresso的webview文本字段

I am facing the same issue. Please refer to this post in Cant add text to webview text field with Espresso

我的代码适用于Android 7.1.1模拟器,但在Android 8.0模拟器上也无法使用.我通过在build.gradle中执行以下操作来解决它.

My code works for Android 7.1.1 simulator but it fails on the Android 8.0 simulator as well. I got it resolved by doing the following in the build.gradle.

1)升级浓缩咖啡库.我在:

1) Upgrade espresso library. I was on:

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)完成此操作后,您的应用可能无法构建.可能会说找不到测试:runner:1.0.0在这种情况下,您需要添加

2) After doing that, your app might not build. It might say it cannot find the test:runner:1.0.0 In that case, you need to add

repositories {
    maven { url "https://maven.google.com" }
}

3)您可能需要解决的以下问题是,它可能会抱怨应用程序(2x.x.x)和测试应用程序(2x.x.x)的版本不同"因此,我将以下内容添加到了gradle中.

3) The following issue you might need to resolve is that it might complain about "versions for app (2x.x.x) and test app (2x.x.x) differ" So I add the following in the gradle.

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:2x.x.x'
}

4)另外,您可能需要确保已添加跑步者".

4) Additional, you might need to make sure you have the Runner added.

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

这篇关于Android 8.0模拟器上的Espresso webView webkeys故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆