如何使用JavaScript在Appium中开启/关闭辅助功能

5

我有一个针对Android的adb shell命令,已经在终端中测试通过。但是不确定如何在使用appium命令的框架中使用它。

// disable
adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService

// enable
adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService
3个回答

1
我能够以以下方式在Java中使用abd命令。希望这对你有帮助。
String disable= "adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService"
String enable = "adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService"
try{
       Runtime.getRuntime().exec(disable); //to disable
   //    Runtime.getRuntime().exec(enable);  //to enable
}catch(Exception e){
      e.printStackTrace();
}

这很有帮助。非常感谢。但我正在尝试使用Node.js来完成它。 - J.Adhikari

0

在 Appium 中,您可以使用 mobile:shell 执行 ADB 命令

您必须使用安全密钥启动 Appium 服务器: appium --relaxed-security

然后您可以这样做:

List<String> args = Arrays.asList(
   arg1,
   arg2,
   ...
   argN
);
Map<String, Object> yourCmd = ImmutableMap.of(
    "command", <adbCommand>,
    "args", args
);
driver.executeScript("mobile: shell", yourCmd);

我不确定关于settings put操作,但是pull/push/rm完美运行。


0

这对我有效。

const { exec } = require('child_process');

exec('adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService', (err, stdout, stderr) => {
        if (err) {
          return;
        }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接