记录使用appium+夜神模拟器测试多设备时selenium和appium版本不兼容带来的问题

记录使用appium+夜神模拟器测试多设备时selenium和appium版本不兼容带来的问题

好不容易解决了selenium和appium的版本冲突问题(导致:AttributeError: 'NoneType' object has no attribute 'to_capabilities'异常发生)

第二天运行代码发现出现了连接Appium 服务器被拒绝

bash 复制代码
http://127.0.0.1:4723/wd/hub
Exception in thread Thread-2 (appim_desired_01):
Traceback (most recent call last):
  File "E:\anaconda3\Lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "E:\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

后来发现Appium 服务器没有启动成功

bash 复制代码
[ERROR] Unrecognized arguments: -bp 4724

在使用 start 命令启动 Appium 时,如果遇到"Unrecognized arguments: -bp 4724"错误,这可能是因为你使用的 Appium 版本不支持 -bp 参数。看来是解决selenium和appium版本冲突问题时降低了appium版本导致的

解决方法

  1. 对于 Appium,通常需要指定的参数为 --port 和 --base-path。如果你想设置基础路径,可以使用 --base-path 替代 -bp。因此,修改后的命令如下:
bash 复制代码
start /b appium -a 127.0.0.1 -p 4723 --base-path /wd/hub
  1. 在连接到 Appium 服务器时,所请求的会话缺少 automationName 参数的话会出现错误Error connecting to Appium server: Message: 'automationName' can't be blank。automationName 是 Appium 的一个重要配置项,用于指定使用的自动化引擎,比如:
  • UiAutomator2(适用于 Android)
  • XCUITest(适用于 iOS)
bash 复制代码
desired_caps = {
    'platformName': 'Android',
    'platformVersion': '5.1.1',  # 确保这个版本与你的设备匹配
    'deviceName': '127.0.0.1:62025',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings',  # 等待的活动
    'noReset': False,
    "automationName": "UiAutomator2"
}
  1. 设置参数后需要安装相应的驱动。 否则Appium 没有找到与 automationName 为 UiAutomator2 和 platformName 为 Android 的配置相匹配的驱动程序会出现错误Error connecting to Appium server: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a driver for automationName 'UiAutomator2' and platformName 'Android'. Have you installed a driver that supports those capabilities? Run 'appium driver list --installed' to see. (Lower-level error: Could not find installed driver to support given caps)v

  2. 解决步骤

    1)检查已安装的驱动:

    运行以下命令查看已安装的驱动程序:

bash 复制代码
appium driver list --installed

确保 appium-uiautomator2-driver 驱动程序已安装。如果没有,你需要安装它。

2)安装 UiAutomator2 驱动:

如果你没有安装 UiAutomator2 驱动,可以通过以下命令安装:

bash 复制代码
appium driver install uiautomator2

再次运行代码-成功


相关推荐
踏着七彩祥云的小丑21 小时前
pytest——Mark标记
开发语言·python·pytest
不爱吃炸鸡柳1 天前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
Dxy12393102161 天前
Python基于BERT的上下文纠错详解
开发语言·python·bert
SiYuanFeng1 天前
Colab复现 NanoChat:从 Tokenizer(CPU)、Base Train(CPU) 到 SFT(GPU) 的完整踩坑实录
python·colab
炸炸鱼.1 天前
Python 操作 MySQL 数据库
android·数据库·python·adb
_深海凉_1 天前
LeetCode热题100-颜色分类
python·算法·leetcode
AC赳赳老秦1 天前
OpenClaw email技能:批量发送邮件、自动回复,高效处理工作邮件
运维·人工智能·python·django·自动化·deepseek·openclaw
zhaoshuzhaoshu1 天前
Python 语法之数据结构详细解析
python
AI问答工程师1 天前
Meta Muse Spark 的"思维压缩"到底是什么?我用 Python 复现了核心思路(附代码)
人工智能·python
zfan5201 天前
python对Excel数据处理(1)
python·excel·pandas