我们可以为 Android espresso 测试禁用 aws device farm 中的对话框吗

Can we disable a dialog box in aws device farm for Android espresso tests

我们正在使用 aws device farm 进行 运行 我们所有的 android 浓缩咖啡测试。如果您看到下图,则此对话框会使我们的一些测试失败。

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

我不知道在 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

  • 使用 UIAutomator 是一种解决方法,但不推荐使用,因为这种方法与一种语言相关,向项目添加另一个库只是为了 hack,最糟糕的是,它会在所有必须的测试中产生大量冗余代码处理弹出窗口。
  • 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 一样发布给 google(例如:https://issuetracker.google.com/issues/64389280

  • 另一种方法是使用 ADB 授予您权限:

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

在这里查看我的回答,了解如何在测试前在 espresso 中实施 adb 命令(它应该与 aws farm 兼容):

希望对您有所帮助!