Appium - Java 解決安卓7.X無法運行的問題

出現這個問題是因爲:adb.js 中1035 行this.shell("ps '" + name + "'", function (err, stdout) {
對應執行的指令是ps 'uiautomator', Android7不支持這個指令格式,所以執行結果是bad pid 'uiautomator'
目前Appium未對此進行處理,所以需要修改此指令的執行方式
 

 

下面我說下解決的辦法:

打開C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js文件

第一步:


this.shell("ps '" + name + "'", function (err, stdout) {
if (err) return cb(err);

替換成
this.shell_grep("ps", name, function (err, stdout) {
if (err) {
logger.debug("No matching processes found");
return cb(null, []);
}

 

第二步:

增加一個shell_grep函數

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

 

第三步:

添加一行代碼: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(); //在該處添加此行代碼

 


第四步:

重啓Appium

 

到此問題就可以解決了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章