android系统运行报错,Appium在Android7.0及以上系统运行时报错的解决方案

背景:在使用Samsung S系列手机进行自动化测试时,发现同样脚本的情况下华为荣耀系列可以正常运行,最终发现差异在于Android7.0及以上系统和appium版本不匹配,需要升级appium。但需要升级的文件较多,在win环境下不方便执行,所以需要找到一个能够快速解决的方案。

要解决的问题:appium在androidV7.0系统上运行时报错 Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]

原因分析:appium的uiautomator版本与androidV7.0不适配。

前后使用了如下方法,最终问题解决。

方案一:

1、  找到appium的安装目录下的adb.js文件,目录为:Appium\node_modules\appium\node_modules\appium-adb\lib

2、  打开adb.js,找到如下代码:

ADB.prototype.getPIDsByName =function (name, cb) {

logger.debug("Getting all processes with '" + name + "'");this.shell("ps '" + name + "'", function (err, stdout) {if (err) returncb(err);

stdout=stdout.trim();var procs =[];var outlines = stdout.split("\n");

在这段代码下面加入这行代码:

outlines.shift()

3、  重启appium

而我用这种方法并没有解决问题,就使用了第二种方法。

方案二:

1、  找到appium的安装目录下的adb.js文件,目录为:Appium\node_modules\appium\node_modules\appium-adb\lib

2、打开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);

};

再找到如下代码:

ADB.prototype.getPIDsByName = function(name, cb) {

logger.debug("Getting all processes with '" + name + "'");this.shell("ps '" + name + "'", function(err, stdout) {if (err) returncb(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(newError(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(newError(msg));

}

cb(null, pids);

});

};

3、重启appium

采用这种方案后,一般问题都能解决,但我的程序还在报错,最终找到如下方案解决了问题。

最终方案:

预置条件:手机端已经安装完Appium Settings 和 Unlock两个应用

解决步骤:1.修改源码文件-注释安装appiumSettings和unlock的两行代码

文件路径: X:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js

f37d6f23c78a84f48085dfea4aae5c87.png

2.修改源码文件如下:

路径:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js

在adb.js的1035行找到

this.shell("ps '" + name + "'", function(err, stdout) {if (err) returncb(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);

};

3.重启appium

最终问题解决,在这里做一个记录,方便大家遇到同样问题时处理。

原文出处:https://www.cnblogs.com/pengfy/p/10653104.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值