写入Android UI Automator输出控制台

del*_*una 8 android android-uiautomator

我正在Android UI Automator上写一个小包装器.通常我们可以在控制台中看到测试用例状态.我可以访问它并添加我自己的消息吗?我试过了System.out.println.但它没有用.有没有办法做到这一点?

All*_*air 2

您可以使用Instrumentation.sendStatus(..)向控制台报告信息。

sendStatus(..) 将 Bundle 和状态代码作为参数。它不会让你直接向控制台写入字符串,但 Bundle 中的每个键/值对都会像这样写出:

INSTRUMENTATION_STATUS: key1=value1
INSTRUMENTATION_STATUS: key2=value2
INSTRUMENTATION_STATUS_CODE: -1
Run Code Online (Sandbox Code Playgroud)

注意:这仅在您使用最新版本的 UiAutomator (2.0+) 时才有效。旧版本无法访问 Instrumentation,因此如果您使用基于 shell 的 UiAutomator,那么是时候升级了!