Web ui自动化框架搭建(八)

测试执行&测试报告

测试用例执行

我这边用的pytest测试框架,测试用例执行的常用两种方式:

  1. 命令方式:pytest -vs ./testcases,
    执行testcases文件所有的符合命名规范的测试方法(命名规范,网上资料很多),
    2、pytest.ini +命令 :pytest的主配置文件,可以改变pytest的默认行为,pytest -vs ./testcases放入配置pytest.ini 如下,命令执行时直接pytest:
[pytest]
testpaths=./testcases
addopts=-vs

指定执行测试用例

有时不想跑所有的测试用例,可以指定执行,改变 pytest执行命令即可,eg:执行某个模块 pytest -vs ./testcases/test_ad.py

测试报告

pytest-html

  是 pytest自带的报告,pytest-html

命令:pytest -vs --html=./report/report.html --self-contained-html,同样也可以通过配置文件简化命令:

[pytest]
testpaths=./testcases
addopts= -vs --reruns 1 --html=report.html --self-contained-html

–reruns 1 :失败重跑1次

allure(推荐这种)

  • 1、生成报告文件: pytest --alluredir ./report/allure (pytes.init配置了命令的话,直接pytest)
  • 2、查看报告:allure serve report/allure
[pytest]
testpaths=./testcases
addopts= --alluredir ./report/allure

如果想使allure报告展示信息更详细,可以在用例加上allure的标签,进行描述:

add_ad_data = read_excel_to_case("资源位管理", 'test_add', 6)
# print(add_ad_data)
@allure.epic("功能:后台资源位管理自动化用例,编写人:李玮;编写时间:20211105,")
@allure.feature("资源位管理测试用例")
@allure.story("新增资源位")
@allure.title("添加资源位-成功")
@allure.severity("blocker ")
@pytest.mark.parametrize("advertName,start_time,end_time,route_value,sort_value,pic_path", add_ad_data)
def test_add_ad_success(login, advertName, start_time, end_time, route_value, sort_value,
                        pic_path):  # login 是fixture,后面参数时方法本身的参数
    """资源位添加成功"""
    # driver = SelectBrowser.open_brower("firefox")
    # t = Login(driver)
    # t.manage_login("admin", "admin")
    ad = ADPostMangeger(login)
    sleep(5)
    ad_text = ad.add_ad(advertName, start_time, end_time, route_value, str(sort_value), pic_path)
    assert ad_text == advertName

报告截图如下:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值