appium报错, ANDROID_HOME is set but does not exist on the file system at “D:\android-sdk;“

一、appium报错, ANDROID_HOME is set but does not exist on the file system at “D:\android-sdk;

在cmd命令行输入:appium-doctor 

报错:ANDROID_HOME is set but does not exist on the file system at "D:\android-sdk;"或者其他类似问题

查看ANDROID_HOME是否添加在用户变量这里;

path中是否添加:

path中是否添加

二、Appium运行时,error: Logcat capture failed: spawn ENOENT的解决办法

我在我的电脑上已经设置环境变量了啊。并且可以正常执行adb命令,为什么appium识别不到呢?难道需要在appium里单独设置吗?

重启appium,问题解决,不再报错了。

三、 error: Failed to start an Appium session, err was: Error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s 127.0.0.1:16384 shell "ps 'uiautomator'""
> ps: bad uiautomator

原因:

对应执行的指令是ps ‘uiautomator’,Android7不支持这个指令格式,所以执行结果是bad pid ‘uiautomator’;
目前Appium未对此进行处理,所以需要修改此指令的执行方式。

解决方法:

1、从目录Appium的安装目录\Appium\node_modules\appium\node_modules\appium-adb\lib找到文件adb.js。
2、修改代码:

ADB.prototype.shell = function (cmd, cb) {

  if (cmd.indexOf('"') === -1) {

    cmd = '"' + cmd + '"';

  }

  var execCmd = 'shell ' + cmd;

   this.exec(execCmd, cb);

 };

在上面的代码段下方添加代码段:

ADB.prototype.shell_grep = function (cmd, grep, cb){

   if (cmd.indexOf('"') == -1){

     cmd = '"' + cmd + '"';

   }

  var execCmd = 'shell' + cmd + '| grep ' + grep;

   this.exec(execCmd, cb);

 };

修改代码:

 ADB.prototype.getPIDsByName = function (name, cb) {
 logger.debug("Getting all processes with '" + name + "'");
 this.shell("ps '" + name + "'", function (err, stdout) {
 if (err) return cb(err);
 stdout = stdout.trim();
 var procs = [];
 var outlines = stdout.split("\n");
 _.each(outlines, function (outline) {
 if (outline.indexOf(name) !== -1) {
 procs.push(outline);
 }
 });
 if (procs.length < 1) {
 logger.debug("No matching processes found");
 return cb(null, []);
 }
 var pids = [];
 _.each(procs, function (proc) {
 var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
 if (match) {
 pids.push(parseInt(match[1], 10));
 }
 });
 if (pids.length !== procs.length) {
 var msg = "Could not extract PIDs from ps output. PIDS: " +
 JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
 return cb(new Error(msg));
 }
cb(null, pids);
 });
 };

将上方代码段注释掉,新增下方的代码段:

ADB.prototype.getPIDsByName = function (name, cb) {
logger.debug("Getting all processes with '" + name + "'");
this.shell_grep("ps", name, function (err, stdout) {
if (err) {
logger.debug("No matching processes found");
return cb(null, []);
}
var pids = [];
_.each(procs, function (proc) {
var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
if (match) {
pids.push(parseInt(match[1], 10));
}
});
if (pids.length !== procs.length) {
var msg = "Could not extract PIDs from ps output. PIDS: " +
JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
return cb(new Error(msg));
}
cb(null, pids);
});
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值