问题1:selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\SDK\SDK\platform-tools\adb.exe -s 78f59013 shell "ps 'uiautomator'""
解决方法:
adb.js(你的安装目录\Appium\node_modules\appium\node_modules\appium-adb\lib\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);
};
提示:这是老的appium每次运行都去安装Unlock,AppiumSetting,等3个应用的解决办法,老的appium不支持android7.0了,建议用新的appium
问题2:因为执行appium的时候,会先往手机中安装几个应用,现在的手机(vivo,小米)都会出现未知来源的安全提示,必须要装sim卡和输密码,这个问题怎么解决?
解决方法:
1.自己手动安装 你的安装目录\Appium\node_modules\appium\build 目录下的 settings_apk ,unicode_ime_apk ,unlock_apk 这三个apk
2.找到appium的安装路径\Appium\node_modules\appium\lib\devices\android\android.js 大概109行,注释掉下面我注释掉的这四行代码~
this.installAppForTest.bind(this),
this.forwardPort.bind(this),
this.pushAppium.bind(this),
// this.initUnicode.bind(this),
// this.pushSettingsApp.bind(this),
// this.pushUnlock.bind(this),
function (cb) {this.uiautomator.start(cb);}.bind(this),
this.wakeUp.bind(this),
// this.unlock.bind(this),
this.getDataDir.bind(this),
3.重启appium