记录使用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

再次运行代码-成功


相关推荐
孟健3 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞5 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽7 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程12 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪12 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook12 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪1 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽1 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战1 天前
Pydantic配置管理最佳实践(一)
python