码迷,mamicode.com
首页 > 移动开发 > 详细

python+appium “ps ‘uiautomator

时间:2020-08-24 16:38:42      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:windows   代码   mon   char   node   信息   原因   处理   nes   

pycharm 报错信息

selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c “E:\android-sdk-windows\platform-tools\adb.exe -s 02743107C5002344 shell “ps ‘uiautomator’  bad pid ‘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);
});
};

注意:注释记得要用 // 进行注释

最近学习appium 碰到这个问题,在网上找了好久,这个方法是在这个大神博客看见的,原文链接:https://blog.csdn.net/xiaocai5731/article/details/104314886

python+appium “ps ‘uiautomator

标签:windows   代码   mon   char   node   信息   原因   处理   nes   

原文地址:https://www.cnblogs.com/zzgk123/p/13530101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!