前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >httprunner学习10-测试报告ExtentReport

httprunner学习10-测试报告ExtentReport

作者头像
上海-悠悠
发布2019-09-29 14:06:36
9960
发布2019-09-29 14:06:36
举报

前言

httprunner默认生成的报告不怎么美观,里面还有第二套报告模板extent_report_template.html。

extent_report_template

使用 hrun -h 可以看到运行的时候可以添加的命令行参数

代码语言:javascript
复制
C:\Users\dell>hrun -h
usage: hrun [-h] [-V] [--no-html-report] [--html-report-name HTML_REPORT_NAME]
            [--html-report-template HTML_REPORT_TEMPLATE]
            [--log-level LOG_LEVEL] [--log-file LOG_FILE]
            [--dot-env-path DOT_ENV_PATH] [--failfast]
            [--startproject STARTPROJECT]
            [--validate [VALIDATE [VALIDATE ...]]]
            [--prettify [PRETTIFY [PRETTIFY ...]]]
            [testset_paths [testset_paths ...]]

One-stop solution for HTTP(S) testing.

positional arguments:
  testset_paths         testset file path

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show version
  --no-html-report      do not generate html report.
  --html-report-name HTML_REPORT_NAME
                        specify html report name, only effective when
                        generating html report.
  --html-report-template HTML_REPORT_TEMPLATE
                        specify html report template path.
  --log-level LOG_LEVEL
                        Specify logging level, default is INFO.
  --log-file LOG_FILE   Write logs to specified file path.
  --dot-env-path DOT_ENV_PATH
                        Specify .env file path, which is useful for keeping
                        production credentials.
  --failfast            Stop the test run on the first error or failure.
  --startproject STARTPROJECT
                        Specify new project name.
  --validate [VALIDATE [VALIDATE ...]]
                        Validate JSON testset format.
  --prettify [PRETTIFY [PRETTIFY ...]]
                        Prettify JSON testset format.

使用 --html-report-template参数可以替换自己的模板,后面指定模板的路径:E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html

hrun test_demo.yml —html-report-template /path/templates\extent_report_template.html

代码语言:javascript
复制
D:\soft\untitled>hrun test_demo.yml --html-report-template E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html
test_demo case1
INFO     GET http://127.0.0.1:8000/api/test/demo
INFO     status_code: 200, response_time(ms): 39.2 ms, response_length: 255 bytes
INFO     start to extract from response object.
INFO     start to validate.
.

----------------------------------------------------------------------
Ran 1 test in 0.049s

OK
INFO     render with html report template: E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html
INFO     Start to render Html report ...
INFO     Generated Html report: D:\soft\untitled\reports\1569369482.html

D:\soft\untitled>

查看extentreport报告

查看extentreport测试报告,默认黑色主题

也可以切换成白色主题

默认使用extentreport报告

如果你不想每次输入这么长的参数,我们可以修改源码。默认使用extent_report_template.html 找到\site-packages\httprunner\report.py文件,相关代码

代码语言:javascript
复制
def render_html_report(summary, html_report_name=None, html_report_template=None):
    """ render html report with specified report name and template
        if html_report_name is not specified, use current datetime
        if html_report_template is not specified, use default report template
    """
    if not html_report_template:
        html_report_template = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            "templates",
            "default_report_template.html"
        )
        logger.log_debug("No html report template specified, use default.")
    else:
        logger.log_info("render with html report template: {}".format(html_report_template))

修改后代码

代码语言:javascript
复制
def render_html_report(summary, html_report_name=None, html_report_template=None):
    """ render html report with specified report name and template
        if html_report_name is not specified, use current datetime
        if html_report_template is not specified, use default report template
    """
    if not html_report_template:
        html_report_template = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            "templates",
            "extent_report_template.html"
        )
        logger.log_debug("No html report template specified, use extent_report_template.")
    elif html_report_template == 'default':
        html_report_template = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            "templates",
            "default_report_template.html"
        )
        logger.log_debug("render with html report template: default_report_template.")
    else:
        logger.log_info("render with html report template: {}".format(html_report_template))

这样默认就会生成extentreport

hrun test_demo.yml

带上default参数就会生成原始的报告

hrun test_demo.yml —html-report-template defaul

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-09-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • extent_report_template
  • 查看extentreport报告
  • 默认使用extentreport报告
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档