【问题标题】:Can we disable a dialog box in aws device farm for Android espresso tests我们可以在 aws 设备场中为 Android espresso 测试禁用一个对话框吗
【发布时间】:2016-09-09 20:01:04
【问题描述】:

我们使用aws device farm 运行我们所有的android espresso 测试。如果您看到下图,则此对话框使我们的几次测试失败。

我们是否可以在运行测试时禁用此对话框?或者有没有一种方法可以在运行测试之前在控制台中运行adb 命令。 我将非常感谢您提供的任何意见。 谢谢

【问题讨论】:

    标签: android amazon-web-services android-espresso aws-device-farm


    【解决方案1】:

    我不知道如何在 aws 之前的测试运行中使用 adb 来授予权限,但是...

    另一种方法是使用 UiAutomator 处理系统对话框。此工具可与 Espresso 结合使用。

    样本:

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject button = device.findObject(new UiSelector().text("Allow"));
    button.click();
    

    必要的依赖:

    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    

    我已经开始编写一个库,它应该可以让 espresso 和 uiautomator 的测试更加简单。这包括用于权限处理的工具。 https://github.com/nenick/espresso-macchiato 参见 EspPermissionDialog 和 EspPermissionsTool

    【讨论】:

      【解决方案2】:
      • 使用 UIAutomator 是一种解决方法,但不推荐使用,因为这种方法与一种语言相关联,将另一个库添加到项目中只是为了破解,最糟糕的是,它会在您必须处理的所有测试中产生大量冗余代码弹出窗口。
      • Espresso 可以通过添加包含您需要的所有权限的适当规则(以逗号分隔)来处理权限:

      @Rule public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule .grant(android.Manifest.permission.ACCESS_FINE_LOCATION);

      https://developer.android.com/reference/android/support/test/rule/GrantPermissionRule https://www.kotlindevelopment.com/runtime-permissions-espresso-done-right/

      但实际上,根据所需的权限,一些用户报告说它不能按预期工作,并且已像 WRITE_EXTERNAL_STORAGE 一样发给谷歌(例如:https://issuetracker.google.com/issues/64389280

      • 另一种方法是使用亚行授予您权利:

      adb shell pm grant your.package.name android.permission.ACCESS_FINE_LOCATION

      在此处查看我的答案,了解如何在测试前在 espresso 中实施 adb 命令(它应该与 aws farm 兼容): https://stackoverflow.com/a/52698720/10472007

      希望对您有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-30
        • 2018-04-25
        • 2021-07-15
        相关资源
        最近更新 更多