前言
受益于pytest的集成,HttpRunner v3.x可以使用pytest所有插件,包括pytest-html和allure-pytest,也可以实现这2种方式的报告
内置html报告
pytest-html插件随HttpRunner一期安装。当你运行测试用例想生成html报告时,可以在命令行中添加--html 安装Httprunner时,pytest-html插件也会随之安装,当运行测试用例的时候,想生成html形式的报告,可以在命令行中添加--html + 报告路径
$ hrun /path/to/testcase --html=report.html
举例:在当前目录执行testcases下的所有用例,并在当前目录下的report目录下,生成名为test_report.html的报告
(httprunner_env) ➜ hrun_demo hrun testcases --html=reports/test_report.html 2021-02-10 11:24:21.055 | INFO | httprunner.make:__make:512 - make path: /Users/jkc/hrun/hrun_demo/testcases 2021-02-10 11:24:21.057 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ... No Path provided. Nothing to do ???? 2021-02-10 11:24:21.263 | INFO | httprunner.cli:main_run:56 - start to run tests with pytest. HttpRunner version: 3.1.4 ================================================================================================= test session starts ================================================================================================== platform darwin -- Python 3.7.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 rootdir: /Users/jkc/hrun/hrun_demo plugins: metadata-1.11.0, html-2.1.1 collected 3 items testcases/demo_testcase_ref_test.py . [ 33%] testcases/demo_testcase_request_test.py . [ 66%] testcases/baidu_test.py . [100%] ---------------------------------------------------------------- generated html file: file:///Users/jkc/hrun/hrun_demo/reports/test_report.html ---------------------------------------------------------------- ================================================================================================== 3 passed in 4.79s ===================================================================================================
打开html报告,查看报告内容
如果想创建一个独立的、更加方便共享测试结果的html报告(通俗的说:该目录只有html报告,没有css样式),可以在命令行中添加--self-contained-html
$ hrun /path/to/testcase --html=report.html --self-contained-html
allure报告
allure-pytest是HttpRunner的可选依赖项,所以如果想生成allure报告时,需要单独安装:
pip3 install allure-pytest
或者在安装httprunner时选择安装:
pip install "httprunner[allure]"
安装完成后,下面的参数可以使用hrun/pytest的命令:
--alluredir=DIR:在指定目录中生成allure报告(可能不存在) --clean-alluredir:清理alluredir文件夹(如果存在) --allure-no-capture:不要将pytest捕获的日志记录/ stdout / stderr附加到报告中 要使Allure侦听器能够在测试执行期间收集结果,只需添加--alluredir选项,并提供路径即可。$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results
要在测试完成后查看实际报告,您需要使用Allure命令行实用程序从结果生成报告
# 在线打开报告(此命令将在默认浏览器中显示您生成的报告) $ allure serve /tmp/my_allure_results # 生成html报告 allure generate reports/allure -o reports/allure/html
关于allure报告就不做过多的演示了,跟pytest里面用法一样
查看更多关于httprunner(11)运行测试报告的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did126621