android 7.0无法运行,Appium在Android7.0上无法启动问题

本文介绍了在Android 7.0系统上使用Appium 1.4版本进行自动化测试时遇到的问题及解决方法。主要问题是由于Appium版本过旧,最高只支持到API 23,而Android 7.0对应API 24。解决方案是升级到Appium 1.6.3及以上版本,并处理因版本不匹配导致的解锁apk安装失败问题。此外,文中还提供了使用uiautomator2的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

由于最近很多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

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)

上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值