Android 7.0系统的手机无法执行appium脚本的问题:"PS 'uiautomator'"

博客主要围绕解决Android 7.0系统手机无法执行appium脚本的问题展开。指出uiautomator1.0可能不支持7.0,可换用uiautomator2.0或改脚本。详细说明了修改appium安装目录下adb.js文件内容的解决办法,包括替换指令和增加shell_grep函数。

报错:

解决:

解决办法

uiautomator1.0应该是不支持7.0,不升版本就换用uiautomator2.0吧,或者用下面的改脚本的方法使用。

解决Android 7.0系统的手机无法执行appium脚本的问题,改问题的具体解决方法如下:

  1. 找到appium的安装目录下的adb.js文件,windows版本的目录如下:Appium\node_modules\appium\node_modules\appium-adb\lib
    2、 打开adb.js,手动修改该文件下的内容,此方法我已经试验成功。

adb.js 中1035 行this.shell("ps '" + name + "'", function (err, stdout) {
对应执行的指令是ps 'uiautomator', Android7不支持这个指令格式,所以执行结果是bad pid 'uiautomator'
目前Appium未对此进行处理,所以需要修改此指令的执行方式
即将
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);

};

 

如图:

 

[HTTP] Request idempotency key: 15bd591f-7d18-458e-ac83-96231a3aa334 [HTTP] --> POST /session {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"UIAutomator2","platformName":"Android"}}} [AppiumDriver@acbb] Calling AppiumDriver.createSession() with args: [{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"UIAutomator2","platformName":"Android"}},{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"UIAutomator2","platformName":"Android"}},{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"UIAutomator2","platformName":"Android"}}] [AppiumDriver@acbb] Event 'newSessionRequested' logged at 1757315400285 (15:10:00 GMT+0800 (中国标准时间)) [Appium] Attempting to find matching driver for automationName 'UIAutomator2' and platformName 'Android' [Appium] The 'uiautomator2' driver was installed and matched caps. [Appium] Will require it at C:\Users\admin\.appium\node_modules\appium-uiautomator2-driver [Appium] Requiring driver at C:\Users\admin\.appium\node_modules\appium-uiautomator2-driver\build\index.js [AppiumDriver@acbb] Appium v3.0.1 creating new AndroidUiautomator2Driver (v5.0.0) session [AppiumDriver@acbb] Checking BaseDriver versions for Appium and AndroidUiautomator2Driver [AppiumDriver@acbb] Appium's BaseDriver version is 10.0.0 [AppiumDriver@acbb] AndroidUiautomator2Driver's BaseDriver version is 10.0.0 [AndroidUiautomator2Driver@46c6] [AndroidUiautomator2Driver@46c6] Creating session with W3C capabilities: { "alwaysMatch": { "platformName": "Android", "appium:automationName": "UIAutomator2" }, "firstMatch": [ {} ] }
最新发布
09-09
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值