pytest使用POM模式运行UI自动化时提示空套件的问题
问题描述
1、pytest使用POM模式运行UI自动化时提示空套件
2、运行 pytest --collect-only 结果提示存在init方法,测试类继承了Base类,而Base类是有init方法的
错误代码:
3、解决办法:将Base类中的init方法去掉,修改后如下:
-
class BaseTest: browser = 'Chrome' if browser == 'Chrome': options = webdriver.ChromeOptions() options.add_experimental_option("detach", True) # selenium4不自动关闭浏览器 driver = webdriver.Chrome(options=options) elif browser == 'Firefox': driver = webdriver.Firefox()
4、最后运行成功