环境配置
python3.6
Mac 10.13
Appium 1.4.13
之前跑android 8的时候报错,按网上的方法把appium里的adb.js里的getPIDsByName替换了,但跑低版本的时候报错找不到procs
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);
});
};
/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js
error: Unhandled error: ReferenceError: procs is not defined
error: Unhandled error: ReferenceError: procs is not defined
at /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:1050:12
at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:180:9)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5) context: [POST /wd/hub/session {"capabilities":{"firstMatch":[{"platformName":"Android","appium:platformVersion":"6.0","appium:deviceName":"dddddd","appium:appPackage":"com.xxx.xxxx","appium:appActivity":"com.xxx.xxxx.Wel]
再对比原函数,少了proc的获取代码,于是把adb.js的getPIDsByName补回该段代码
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, []);
}
// add by salted fish start
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, []);
}
//add by salted fish end
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);
});
};
参考文章:
https://blog.youkuaiyun.com/aa790775800/article/details/101924242