Uiautomator - takeScreenshot - 有没有办法将图像存储在机器 运行 测试而不是设备上

Uiautomator - takeScreenshot - is there a way to store the image on the machine running the tests instead of the device

在 uiautomator 测试中,使用 takeScreenshot(),有没有办法将图像存储在机器 运行 测试而不是设备上?

如果无法使用 takeScreenshot 完成,我有兴趣听听任何人提出的任何替代方法。

谢谢

您可以定义存储路径(screenPath)并将屏幕截图保存在设备上。

你可以像这样使用 adb pull:

adb pull screenPath localPath

将截图复制到本地。

尚未完全涵盖所有 UiAutomator 案例,但 AndroidViewClient/culebra 可以为您提供替代方案。您可以替换您的一些测试并截取屏幕截图,它们将保存在机器上运行正在测试。

有一种使用 Culebra GUI 生成测试用例的极其简单的方法,只需 运行:

$ culebra -UG -o mytest.py

生成测试用例。然后,在测试生成期间,您可以使用 CTRL+F (或上下文菜单),屏幕截图将被保存,并且像这样的一行

self.vc.writeImageToFile('/tmp/${serialno}-${focusedwindowname}-${timestamp}.png', 'PNG')

会在测试脚本中生成,所以每次运行都会保存,不会覆盖之前的。

希望这对您有所帮助。