1. # -*-coding:utf-8一*-
2. # @Time:2021/10/15
3. # @Author: 大海
4.
5. import pytest
6. import time
7. from selenium import webdriver
8.
9.
10. # 习惯浏览器命名为driver, 当然也可以直接命名为driver就不用起别名了
11. @pytest.fixture(name="driver")
12. def open_browser():
13. # 创建浏览器实例
14. driver = webdriver.Chrome()
15. yield driver
16. driver.close()
17.
18.
19. def test_blog(driver):
20. # 打开我的博客
21. driver.get("https://blog.csdn.net/IT_heima")
22. driver.maximize_window()
23. time.sleep(2)
24.
25.
26. if __name__ == '__main__':
27. pytest.main(["-s", "test_25.py"])