如何通过Appium执行模拟器命令

时间:2019-07-17 10:15:01

标签: android testing cmd automated-tests appium

我想通过appium执行仿真器命令以进行自动化的Android测试。

adb shell命令可以轻松执行,例如这样->

driver.executeScript("mobile: shell", ImmutableMap.of("command", "dumpsys window windows | grep -E 'mCurrentFocus'"))

有什么方法可以执行以下命令“ adb emu network delay gprs”

1 个答案:

答案 0 :(得分:1)

正确的语法为:

Map<String, Object> argv = new HashMap<>();
argv.put("command", "dumpsys ");
argv.put("args", Lists.newArrayList("window", "windows", "|", "grep", "-E", "'mCurrentFocus'"));
String result = driver.executeScript("mobile: shell", argv).toString();

参考:How To Execute Shell Commands On The Remote Device

顺便说一下,有Appium SeeTest Extensions为运行命令提供了简化的语法,例如:

driver.executeScript("seetest:client.run(\"adb shell dumpsys window windows | grep -E 'mCurrentFocus'\")");