背景:在使用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) return cb(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) return cb(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(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); }); };
3、重启appium
采用这种方案后,一般问题都能解决,但我的程序还在报错,最终找到如下方案解决了问题。
最终方案:
预置条件:手机端已经安装完Appium Settings 和 Unlock两个应用
解决步骤:1.修改源码文件-注释安装appiumSettings和unlock的两行代码
文件路径: X:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js
路径: \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) return cb(err); 替换成 this.shell_grep("ps", name, function (err, stdout) { if (err) { logger.debug("No matching processes found"); return cb(null, []); }
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
最终问题解决,在这里做一个记录,方便大家遇到同样问题时处理。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。