appium在android7.0上無法啟動問題
前言
由於最近很多android手機升級到7.0系統了,有些小夥伴的appium版本用的還是1.4版本,在運行android7.0的app自動化時候遇到無法啟動問題:WebDriverException: Message: A new session could not be created
我的電腦環境:
- python 3.6
- android 7.0
- appium 1.4.13
android7.0遇到問題
1.執行代碼:
# coding:utf-8 # 作者:上海-悠悠 from appium import webdriver from time import sleep desired_caps = { 'platformName': 'Android', 'deviceName': 'A5RNW18316011440', 'platformVersion': '7.0', 'appPackage': 'com.baidu.yuedu', 'appActivity': 'com.baidu.yuedu.splash.SplashActivity' } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
2.執行後報錯如下:A new session could not be created
D:\soft\python3.6\python.exe D:/xcm_app_test/app/test_login.py Traceback (most recent call last): File "D:/xcm_app_test/app/test_login.py", line 11, in <module> driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) File "D:\soft\python3.6\lib\site-packages\appium\webdriver\webdriver.py", line 36, in __init__ super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive) File "D:\soft\python3.6\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__ self.start_session(desired_capabilities, browser_profile) File "D:\soft\python3.6\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session response = self.execute(Command.NEW_SESSION, capabilities) File "D:\soft\python3.6\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "D:\soft\python3.6\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: Command failed: )
分析問題
1.遇到無法啟動問題,報錯都一樣:A new session could not be created,看編輯器報錯是沒啥用的,這個時候就需要打開appium的日誌界面,分析走到哪一步報錯了,日誌太多,就貼一部分了
> info: [debug] Device is at API Level 24 > info: Device API level is: 24 > info: [debug] Extracting strings for language: default > info: [debug] Apk doesn't exist locally > info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
2.從上面日誌可以看出,當前的設備API版本是24,而appium1.4支持的最高API版本是23。打開appium客戶端,左上角點機器人圖標,點開platformVersion如下圖所示
3.也就是說appium1.4支持最高android版本是6.0,查下資料可以知道android7.0需使用appium1.6.3以上版本才能支持。
解決問題
1.重新下載最新版appium,appium1.6以後版本都是以appium-desktop命名的,目前我使用的版本是appium-desktop1.2.2,安裝完之後也就是V1.7.1版本
2.appium-desktop所以版本在github都能下載到:
appium-desktop 所有版本下載地址
3.appium-desktop和之前老的appium版本是可以共存的,所有不需要卸載之前的版本,重新打開appium1.7版本,運行代碼
4.重新運行時候發現報這個錯,從報錯信息看是手機上安裝的unlock版本不匹配(因為之前運行appium1.4版本有殘留),解決辦法:手動卸載手機上的appium settings和Unlock就可以了
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'D\:\\soft\\Android\\platform-tools\\adb.exe -P 5037 -s A5RNW18316011440 install C\:\\Users\\admin\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\node_modules\\appium\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk' exited with code 1'; Stderr: 'Failed to install C:\Users\admin\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package io.appium.unlock signatures do not match the previously installed version; ignoring!]'; Code: '1'
備註
1.有些小夥伴可能用的appium1.6版本,可以嘗試加上這個參數,用uiautomator2運行
‘automationName‘: ‘uiautomator2‘
# coding:utf-8
# 作者:上海-悠悠
from appium import webdriver
from time import sleep
desired_caps = {
'platformName': 'Android',
'deviceName': 'A5RNW18316011440',
'platformVersion': '7.0',
'automationName': 'uiautomator2',
'appPackage': 'com.baidu.yuedu',
'appActivity': 'com.baidu.yuedu.splash.SplashActivity'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
appium在android7.0上無法啟動問題