pytest框架的使用

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')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值