本文主要是介绍手机自动化测试:3.Appium-Python-Client-4.0.0下代码如何变更,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.昨天留了个问题就是Appium-Python-Client不能使用目前最高版本的问题。
今天要完善一下,使用最好的。
编写一个测试 (Python) - Appium Documentationhttps://appium.io/docs/zh/latest/quickstart/test-py/官网上给的示例。
首先将昨天的低版本升上去。
pip3 install --upgrade Appium-Python-Client
原代码:
from appium import webdriver
desired_caps = {"platformName": "Android","platformVersion": "10","deviceName": "Q5X7N19605002672","appPackage": "tv.danmaku.bili","appActivity": ".MainActivityV2","unicodeKeyboard": True,"resetKeyboard":True,'noReset': True,"appium:newCommandTimeout": 6000,"appium:automationName": "UiAutomator2"
}if desired_caps is not None:driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
else:raise ValueError("desired_caps must not be None")
出错信息
Traceback (most recent call last):File "D:\py_doc2024\get_meituan\0605.py", line 17, in <module>driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "D:\anaconda3\envs\appenv\Lib\site-packages\appium\webdriver\webdriver.py", line 229, in __init__super().__init__(File "D:\anaconda3\envs\appenv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in __init__capabilities = options.to_capabilities()^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
新代码:
from appium import webdriver
from appium.options.android import UiAutomator2Options
desired_caps = {"platformName": "Android","platformVersion": "10","deviceName": "Q5X7N19605002672","appPackage": "tv.danmaku.bili","appActivity": ".MainActivityV2","unicodeKeyboard": True,"resetKeyboard":True,'noReset': True,"appium:newCommandTimeout": 6000,"appium:automationName": "UiAutomator2"
}if desired_caps is not None:driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', options=UiAutomator2Options().load_capabilities(desired_caps))
else:raise ValueError("desired_caps must not be None")
成功打开。
以上在csdn,他们的方法就是降低版本。唉,也怪自己。
这篇关于手机自动化测试:3.Appium-Python-Client-4.0.0下代码如何变更的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!