简体   繁体   English

如何使用javascript通过appium打开/关闭辅助功能

[英]How can I Turn on/off Accessibility through appium using javascript

I have this adb shell command for android and tried with the terminal and it's working perfectly. 我有这个针对Android的adb shell命令,并在终端上进行了尝试,并且运行良好。

But not sure how to use this in a framework using appium command. 但是不确定如何在使用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

I am able to use abd command in java in the following way. 我可以通过以下方式在Java中使用abd命令。 Hope its helps you too. 希望它也能帮助您。

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();
}

You can use mobile:shell in Appium to execute ADB commands : 您可以在Appium中使用mobile:shell执行ADB命令

You must start Appium server with security key: appium --relaxed-security 您必须使用安全密钥启动Appium服务器: appium --relaxed-security

Then you do it like: 然后,您可以像这样:

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

I'm not sure about settings put operation, but pull / push / rm works perfectly. 我不确定settings put操作,但是pull / push / rm效果很好。

this works for me. 这对我有用。

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;
        }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM