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

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

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

https://github.com/TesterlifeRaymond/BeautifulReport

如果自己电脑上安装了git,可以直接使用git命令克隆到本地指定目录下

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

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

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

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

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

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)

解释:

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

完成!

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

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

猜你喜欢

转载自www.cnblogs.com/wulixia/p/11420315.html