如何在 aws device farm 中截屏以进行 android espresso 测试

How to take screenshot in aws device farm for android espresso testing

我正在使用 aws device farm 进行 运行 我的 android 测试,我们正在使用 espresso 框架。今天有一些测试失败了,如果我测试失败了,我想截图。我已经阅读了您的文档,但找不到任何具体内容。这是我目前所知道的:

Documentation

You can take screenshots as part of your Android UI Automator tests.

To take a screenshot, call the takeScreenshot method (for example, takeScreenshot("/sdcard/uiautomator-screenshots/home-screen-1234.png");).

Note: All screenshots must be stored in the /sdcard/uiautomator-screenshots directory. You must specify the full path (including the file name) of the screenshot to be stored. The takeScreenshot method works for API Levels 17 and higher only. For API Level 16, UI Automator is supported, but screenshots are not supported.

有什么方法可以配置 aws device 农场自动截取屏幕截图而无需调用测试中的函数?是否支持?另外,我找不到任何相关的屏幕截图 commands。如果有人能解释截图所需的步骤,我将不胜感激。谢谢

免责声明:我是 AWS Device Farm 的开发人员。

关于 takeScreenshot 方法的那部分文档是针对 uiautomator 1.0,而不是 uiautomator 2.0,后者与Android Instrumentation/Espresso.

我认为 Espresso 没有添加用于捕获屏幕截图的内置功能。但是,如果您查看 Android 的官方 AWS Device Farm 示例应用程序,您应该可以直接从 Espresso 测试中使用一个帮助程序 class ScreenShot.java

希望对您有所帮助!

最佳,
安德鲁@AWS Device Farm