使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式相关的知识,希望对你有一定的参考价值。

appium1.4,运行自动化脚本时提示

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: "D:Program Filesandroid-sdk-windowsplatform-toolsadb.exe" -s GSL0217302005195 shell "ps ‘uiautomator‘"
ps: uiautomator

解决办法:

找到appium的安装目录:D:Program Files (x86)Appium ode_modulesappium ode_modulesappium-adblib下,打开abd.js

1、找到这段代码:

ADB.prototype.shell = function (cmd, cb) {
if (cmd.indexOf(‘"‘) === -1) {
cmd = ‘"‘ + cmd + ‘"‘;
}
var execCmd = ‘shell ‘ + cmd;
this.exec(execCmd, cb);
};

在该代码下边加上:

//解决 ps uiautomator问题
ADB.prototype.shell_grep = function (cmd, grep, cb) {
if (cmd.indexOf(‘"‘) === -1) {
cmd = ‘"‘ + cmd + ‘"‘;
}
var execCmd = ‘shell ‘ + cmd + ‘| grep ‘ + grep;
this.exec(execCmd, cb);
};

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(" ");
_.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 = /[^ ]+[ ]+([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 = /[^ ]+[ ]+([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,重启appium,可以解决

 



























































以上是关于使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式的主要内容,如果未能解决你的问题,请参考以下文章

android之版本特点

为啥CameraX预览在真机上模糊不清,怎么对焦?

appium1.4?????????????????????appium???????????????unlock,setting?????????????????????

如何在真机上使用android studio和Xcode日志格式

Appium Maven 项目无法在真机上运行

Flutter 在真机上运行时报错