我想通过appium执行仿真器命令以进行自动化的Android测试。
adb shell命令可以轻松执行,例如这样->
driver.executeScript("mobile: shell", ImmutableMap.of("command", "dumpsys window windows | grep -E 'mCurrentFocus'"))
有什么方法可以执行以下命令“ adb emu network delay gprs”
答案 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'\")");