Command failed: C:\Windows\system32\cmd.e...adb.exe -s 16fcb2be shell “ps ‘uiautomat解决方法

问题

        最近在安装使用Appium进行App自动化测试时,运行Appium时报了这样一个错误“Command failed: C:\Windows\system32\cmd.e...adb.exe -s 16fcb2be shell "ps 'uiautomat”,检查了安装环境发现是没有错误的,后来百度后解决了该问题,先将解决方法分享给大家。

解决方法

1、找到appium的安装目录下的adb.js文件,目录为:Appium\node_modules\appium\node_modules\appium-adb\lib,然后找到adb.js文件,使用编辑器打开,我这里使用的是notepad++,然后在这行代码下面加入“outlines.shift();”即:

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");
outlines.shift();

2、然后再找到如下代码,找到该代码后,把该段代码注释掉,新增以下代码:

/*
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");
    outlines.shift();
    _.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);
  });
};

3、再在adb.js中找到该代码,

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

5、以上完成后,保存adb.js,然后重启appium就问题解决了。

Guess you like

Origin blog.csdn.net/sl01224318/article/details/121303179