環境介紹:
1、appium版本:1.4.16.1
2、真機運行
實現結果:
運行appium第一次運行則安裝Appium settings和Unclock的apk,再次之后的運行則無需手動卸載,再次安裝。
問題描述:
第一次:Android手機運行appium,自動安裝Appium settings和Unclock的apk,
第二次:第一次運行完畢,若不手動刪除已經安裝的Appium settings和Unclock,將會提示報錯信息如下,提示:Appium settings和Unclock不是第一次安裝,因此必須每次運行appium腳本,都需要手動刪除此2個apk,重新運行則不會報錯。
WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\AutoTest\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s GWY0216A22013956 install "D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"" Failed to install D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.] )
根據以上報錯信息,可以看到Appium settings和Unclock的安裝路徑。
apk作用說明:
1、Appium settings:用於設置網絡狀態
2、Unclock:用於自動解鎖(使用場景:手機是滑動鎖屏的情況下,則會自動解鎖並啟動apk,注意:圖案鎖屏與數字鎖則不可以哦,只能是滑動鎖屏)
解決方法:
1、需要手動去修改appium安裝路徑下的android.js文件,來實現運行首次安裝Appium settings和Unclock,之后的運行則無需再次卸載的操作。
2、android.js的存放路徑:D:\Auto Test\appium\Appium\node_modules\appium\lib\devices\android\android.js,說明:D:\Auto Test\appium\為本人的appium存放路徑。
3、android.js文件中找到如下代碼
... Android.prototype.start = function (cb, onDie) { this.launchCb = cb; this.uiautomatorExitCb = onDie; logger.info("Starting android appium"); async.series([ this.initJavaVersion.bind(this), this.initAdb.bind(this), this.packageAndLaunchActivityFromManifest.bind(this), this.initUiautomator.bind(this), this.prepareDevice.bind(this), this.checkApiLevel.bind(this), this.pushStrings.bind(this), this.processFromManifest.bind(this), this.uninstallApp.bind(this), this.installAppForTest.bind(this), this.forwardPort.bind(this), this.pushAppium.bind(this), this.initUnicode.bind(this), //this.pushSettingsApp.bind(this), #手動注釋此2行代碼,即可解決問題 //this.pushUnlock.bind(this), function (cb) {this.uiautomator.start(cb);}.bind(this), this.wakeUp.bind(this), this.unlock.bind(this), this.getDataDir.bind(this), this.setupCompressedLayoutHierarchy.bind(this), this.startAppUnderTest.bind(this), this.initAutoWebview.bind(this), this.setActualCapabilities.bind(this) ], function (err) { if (err) { this.shutdown(function () { this.launchCb(err); }.bind(this)); } else { this.didLaunch = true; this.launchCb(null, this.proxySessionId); } }.bind(this)); };
歡迎加入群一起學習: