在执行pytest时候的时候遇到这个问题:很是烦人
============================== warnings summary ===============================
testcase/test_login.py::TestLogin::test_login
D:\Python\lib\site-packages\appium\webdriver\webdriver.py:229: DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg
super().__init__(
-- Docs: https://docs.pytest.org/en/stable/warnings.html
- generated html file: file:///E:/joinkwang/Documents/appium_Ui/outputs/reports/report.html -
=================== 1 passed, 1 warning in 93.19s (0:01:33) ===================
运行的代码:
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_capabilities has been deprecated, please pass in an Options object with options kwarg super().init(
通过查阅的资料表明:
Selenium Webdriver现在使用Options来传递功能,但我假设您正在使用的appium python客户端尚不支持它。
只能将以下内容添加到pytest.ini中以消除警告。
在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)
推荐第一种pytest.ini文件中新增内容。
如果觉得有用,点赞+收藏,谢谢