准备工作:
1、下载Python
2、pip下载pytest-selenium
代码:
from selenium.webdriver.common.by import By
def test_baidu_so_get_value(selenium):
selenium.get('http://www.baidu.com/')
kw = selenium.find_element(By.ID, 'kw')
kw.send_keys('NBA')
assert kw.get_attribute('value') == 'NBA'
命令行执行:
pytest TestCase/test_case.py --driver Chrome --html=report/result.html
============================================== test session starts ===============================================
platform win32 -- Python 3.7.3, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
driver: Chrome
sensitiveurl: .*
rootdir: E:\auto_selenium_test
plugins: base-url-1.4.2, html-3.1.1, metadata-1.11.0, selenium-2.0.1, variables-1.9.0
collected 1 item
TestCase\test_case.py
DevTools listening on ws://127.0.0.1:58971/devtools/browser/a1d75249-75b1-4245-930b-86d3ec9528bd
. [100%]
================================================ warnings summary ================================================
TestCase/test_case.py::test_baidu_so_get_value
e:\auto_selenium_test\env\lib\site-packages\selenium\webdriver\chrome\webdriver.py:73: DeprecationWarning: desire
d_capabilities has been deprecated, please pass in a Service object
service_log_path, service, keep_alive)
TestCase/test_case.py::test_baidu_so_get_value
e:\auto_selenium_test\env\lib\site-packages\selenium\webdriver\chrome\webdriver.py:73: DeprecationWarning: servic
e_log_path has been deprecated, please pass in a Service object
service_log_path, service, keep_alive)
-- Docs: https://docs.pytest.org/en/stable/warnings.html
---------------------- generated html file: file://E:\auto_selenium_test\report\result.html ----------------------
========================================= 1 passed, 2 warnings in 4.82s ==========================================
报告展示:
|