IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

HttpRunner学习9–切换测试报告模板

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

前言

在HttpRunner中,给我们提供了 2 套测试报告模板,分别是 default_report_template.html 和 extent_report_template.html 。

默认报告使用的是 default_report_template ,如果觉得不太美观,这时我们可以使用 extent_report_template ,其生成的报告相对更加漂亮,看起来也更加高大上。

本人环境:HttpRunner V1.5.8

使用ExtentReport模板生成报告

在安装HttpRunner的时候,如果是使用 pip 来安装,那么报告模板的路径在 python 安装路径下的 \Lib\site-packages\httprunner\templates 目录下,如我本地环境的报告模板路径:

101_1.png

第一个是默认情况使用的报告模板,其生成的报告如下:

101_2.png

接下来,我们将使用第二个模板 extent_report_template.html 来生成报告。

在HttpRunner中,如果要指定测试报告的模板,需要通过 –html-report-template 指定报告模板的路径,然后测试运行完成后,就会采用指定模板生成测试报告。

如我在这里使用 extent_report_template 来生成报告:

hrun test_login.yml --html-report-template D:\Python\installation\Lib\site-packages\httprunner\templates\extent_report_template.html

运行完成后,会在当前路径的 reports 目录下生成一份 HTML 格式的测试报告,打开报告可看到:

101_3.png

现在,我们对比一下,是不是能感觉到 extent_report_template 更加美观,逼格更高呢?

指定ExtentReport为默认模板

在上面步骤中,我们发现,使用 extent_report_template 来生成报告,运行命令会比较长,如果我们想将 extent_report_template 作为默认的测试报告模板,那么我们就需对 HttpRunner 的源码进行简单修改了。

HttpRunner中,生成报告相关的源码在 \Lib\site-packages\httprunner\report.py 下,打开文件并找到需要修改的地方:

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))

    logger.log_info("Start to render Html report ...")
    logger.log_debug("render data: {}".format(summary))

从源码中看到,如果不指定测试报告模板,那么参数 html_report_template=None ,使用的是 default_report_template.html 这个模板,因此,我们只要将这里修改一下,应该就能够达到我们的目标。

    if not html_report_template:
        html_report_template = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            "templates",
            "extent_report_template.html"
        )

OK,修改之后,再次执行命令,可以发现,生成测试报告使用的默认模板已修改。

文章永久链接:https://tech.souyunku.com/?p=32933


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(84) 打赏



未经允许不得转载:搜云库技术团队 » HttpRunner学习9–切换测试报告模板

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367