import pytest
from appium import webdriver
class Test:
def setup_class(self):
print("setup from here")
desired_caps = dict()
desired_caps['platformName'] = 'ios'
desired_caps['platformVersion'] = '12.1'
desired_caps['deviceName'] = 'iPhone 8'
desired_caps['app'] = 'com.masilotti.UI-Testing-Cheat-Sheet'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
PycharmProjects/DemoTest/venv/lib/python3.8/site-packages/appium/webdriver/webdriver.py:274: DeprecationWarning:desired_capability 已被弃用,请 传入带有 options kwarg 的 Options 对象 超级()。初始化(
如何摆脱这个警告,每当使用Unitest或Pytest时都会出现这个警告。
简短回答:
你不能。 (你可以压制它)
长答案:
Selenium Webdriver 现在使用选项来传递功能,但我假设您正在使用的
appium python-client
尚不支持它。官方仓库这里有一个未解决的问题。 这里是硒方面的实现。
这里是解决方案的线程:https://bytemeta.vip/repo/appium/python-client/issues/680
将以下内容添加到 pytest.ini 以抑制警告。
[pytest]
filterwarnings =
# Appium team is aware of deprecation warning - https://github.com/appium/python-client/issues/680
ignore::DeprecationWarning
或者使用Python:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
self.driver = webdriver.Remote(hub_url, caps)
对于目前正在解决这个问题的人来说,在 Selenium 版本 4(Appium 也使用该版本)中,所需功能的配置已进行了修改,现在建议使用 Options 对象。
适用于 ios 设备的 python 示例:
from appium import webdriver
from appium.options.ios.xcuitest.base import XCUITestOptions
desired_capabilities = {
'platformName': 'iOS',
'platformVersion': '16.4',
'deviceName': 'iPhone 12 Pro',
'automationName': 'XCUITest',
}
options = XCUITestOptions()
options.load_capabilities(desired_capabilities)
appium_server_url = 'http://localhost:4723'
driver = webdriver.Remote(appium_server_url, options=options)