pytest框架的使用
运行测试并生成html测试报告
在test_case文件夹下cmd命令执行以下命令
pytest --html=../report/report.html --self-contained-html
会执行当前test_case下的所有case
…/report/report.html 代表生成的测试报告路径testcase的同级的report文件夹下,生成report.html报告
参数化的使用
@pytest.mark.parametrize('username,password',
[('admin','Admin66')])
def test_login(self,drivers,username,password):
LoginPage(drivers).login(username,password)
在要参数化的case上@pytest.mark.parametrize固定写法
'username,password’为参数名称
后面跟list,填写参数具体的值[(‘admin’,‘admin’),(‘test’,‘testpwd’)]
跳过某个测试用例
下面展示一些 内联代码片
。
@pytest.mark.skip(reason="this is a demo_test")
def test_csdn(self,drivers):
drivers.get("https://www.csdn.net/")
drivers.find_element_by_class_name('toolbar_to_feed').click()
在pycharm中批量运行测试用例
if __name__ =="__main__":
os.system('pytest --html=../report/report.html --self-contained-html')