python自动化测试之生成BeautifulReport可视化测试报告

 用python写自动化测试时,unittest框架与BeautifulReport结合可以生成完美的可视化测试报告html

【第一步】:准备好BeautifulReport,git地址:python

https://github.com/TesterlifeRaymond/BeautifulReportgit

若是本身电脑上安装了git,能够直接使用git命令克隆到本地指定目录下github

git clone https://github.com/TesterlifeRaymond/BeautifulReport

克隆到python安装目录的/Lib/site-packages/目录下;web

若是没有安装git,直接在git上下载BeautifulReport.ZIP 到本地python的的/Lib/site-packages/目录下框架

 

【第二步】:组织用例并套用BeautifulReport测试

这里用到unittest.defaultTestLoader.discover()方法批量处理整合测试套件,再用BeautifulReport()方法执行用例。代码以下:code

import unittest
from BeautifulReport import BeautifulReport

if __name__ == '__main__':
   case_path = os.path.join(os.getcwd(), "testcases") discover = unittest.defaultTestLoader.discover(case_path, pattern="inter*.py", top_level_dir=None) # 测试报告写入路径 report_dir = "F:\\work\\linkcld\\lds\\report\\" result = BeautifulReport(discover) result.report(filename='test_report', description='整合后的接口自动化测试报告', log_path=report_dir)

解释:htm

report ( filename -> 测试报告名称, 若是不指定默认文件名为report.html ;description -> 测试报告用例名称展现 ;log_path='.' -> 测试报告文件写入路径 )blog

 

完成!

web自动化测试使用此测试报告的时候,用例执行失败还可以进行截图,后续试过再记录。

具体可参考:https://www.cnblogs.com/hao2018/p/10093343.html

相关文章
相关标签/搜索