httprunner默認生成的報告不怎麼美觀,裏面還有第二套報告模板extent_report_template.html。html
使用 hrun -h
能夠看到運行的時候能夠添加的命令行參數python
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.htmlapi
hrun test_demo.yml --html-report-template /path/templates/extent_report_template.html測試
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測試報告,默認黑色主題this
也能夠切換成白色主題spa
若是你不想每次輸入這麼長的參數,咱們能夠修改源碼。默認使用extent_report_template.html
找到\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))
修改後代碼debug
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))
這樣默認就會生成extentreport3d
hrun test_demo.ymlcode
帶上default參數就會生成原始的報告
hrun test_demo.yml --html-report-template default