Httprunner generates an Allure formatted HTML report

Keywords: httprunner

1. Preface

We have been using httprunner for interface automation for some time and found that httprunner has its own advantages over pytest and unittest.

  • Low script capability requirements
  • Complete and lightweight scaffold
  • Fast script output
  • HTML report with visualization

This article does not discuss how to use httprunner, but only discusses several methods of generating reports after using httprunner,

2. httprunner v2.x version Report

In HttpRunner, we are provided with two sets of test report templates, namely default_report_template.html and extend_ report_ template.html .

The default report uses default_report_template. If we don't think it's beautiful, we can use extend_ report_ The report generated by template is relatively more beautiful and looks taller.

2.1 generate report using extendreport template

When installing HttpRunner, if pip is used for installation, the path of the report template is under the python installation path  \ Lib\site-packages\httprunner\templates   Directory, such as the report template path of my local environment:

The first is the report template used by default. The reports generated are as follows:

Next, we will use the second template, ext_ report_ Template.html to generate the report.

In HttpRunner, if you want to specify the template of the test report, you need to pass  -- html-report-template   Specify the path of the report template. After the test run is completed, the test report will be generated using the specified template.

If I use extend here_ report_ Template to generate a report:

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

After running, a test report in HTML format will be generated in the reports directory of the current path. Open the report and you can see:

Now, let's compare whether we can feel the extension_ report_ The template is more beautiful and the force grid is higher?

2.2 specify extensreport as the default template

In the above steps, we found that using extend_ report_ Template to generate the report, and the command will be long if we want to add ext_ report_ Template is used as the default test report template, so we need to simply modify the source code of HttpRunner.

In HttpRunner, the source code related to generating reports is in  \ Lib\site-packages\httprunner\   Next, open the file and find the place to modify:

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(
        logger.log_debug("No html report template specified, use default.")
        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))

From the source code, if the test report template is not specified, the parameters will be changed   html_report_template=None  , Default is used_ report_ Template.html is the template, so we just need to modify it here, and we should be able to achieve our goal.

    if not html_report_template:
        html_report_template = os.path.join(

OK, after modification, execute the command again. You can find that the default template used to generate the test report has been modified.

three   httprunner v3.x version Report

3.1 simulated HTML test report

The HTTPrunner comes with it after installation   Pytest html plug-in, when you want to generate   When html test report, you can add command parameter -- html

 hrun testcases/dlvopenapi/ --html=test.html

--test.html in html=test.html ` is the storage path of the test report. If there is no folder, it will be stored in the current folder where the command runs. Here is the project root directory

When the hrun command generates a report, bring it with you  -- html   Specify report path

>hrun testcases/ --html=./reports/result.html

--html   The css file of the report generated by the parameter is separate and inconvenient to view. You can add the -- self contained HTML parameter to integrate the css file into HTML

>hrun testcases/ --html=./reports/result.html --self-contained-html

The report generated is as follows

three point two   allure Report

pytest   Support famous   allure   Test report, httprunner   It integrates pytest and naturally supports allure. however   HTTPrunner   Not installed by default   Allure, you need to install it separately.

There are two ways to install:

  • Install the allure pytest dependency library allure pytest;
  • Install the allure dependency library for httprunner[allure].

Install allure pytest:

pip3 install allure-pytest

Install httprunner[allure] (recommended)

pip3 install "httprunner[allure]"

Once allure pytest is ready, the following parameters can be used with the hrun/pytest command:

  • --Allouredir = dir: generate the raw data of the allourereport to the specified directory
  • -Clean allouredir: if the specified directory already exists, clean the folder
  • --Allow no capture: do not attach the logging, stdout, and stderr captured by pytest to the report

To enable the Allure listener to collect results during test execution, simply add the -- alluredir option and provide a path to the folder where the results are stored. For example:

hrun testcases/dlvopenapi/ --alluredir=/tmp/my_allure_results

/tmp/my_allure_results only stores the collected test results, not the completed report, and needs to be generated by command.

generate allure Report, execution:
allure generate ./tmp/my_allure_results -o ./tmp/allure-report --clean,After running, a report My folder is allure Report of

To view the actual report after the test is completed, you need to use the Allure command-line utility to generate a report from the results.

Display report, execute:
allure open -h -p 8083 ./tmp/allure-report,Display Report


allure serve /tmp/my_allure_results

This command will display the report you generated in the default browser.

  At the same time, you can also install the allure report plug-in in Jenkins to integrate the results with Jenkins.

Posted by pedroteixeira07 on Fri, 19 Nov 2021 02:46:00 -0800