标签:sky attrs setup href inf constant 失败 修改 测试结果
本文使用的 HTMLTestRunner 来源于github:
https://github.com/githublitao/HTMLTestRunner_Chart
参考链接:
http://tungwaiyip.info/software/HTMLTestRunner.html
https://github.com/GoverSky/HTMLTestRunner_cn
├── run_case
│?? ├── __init__.py
│?? ├── module_path.py
│?? ├── run_login_case.py
│?? └── run_login_case_report.py
└── utils
├── __init__.py
├── HTMLTestRunnerChart.py
├── constants.py
└── se_utils.py
修改HTMLTestRunnerChart.py
'
'
'
def generateReport(self, test, result):
report_attrs = self.getReportAttributes(result)
generator = 'HTMLTestRunner %s' % __version__
stylesheet = self._generate_stylesheet()
heading = self._generate_heading(report_attrs)
report = self._generate_report(result)
self.path = os.path.splitext(self.stream.name)[0] + ".json"
# 在这个方法下,添加下面一行代码,用于存储最近10次测试结果的Json
self.path = self.path.rsplit('/', 1)[0] + '/WebUiTestRet.json'
'
'
'
run_login_case_report.py
import unittest
from module_path import *
from test_case.test_login import TestLoginCase
from utils.se_utils import Driver
from utils.HTMLTestRunnerChart import HTMLTestRunner
if __name__ == '__main__':
cases = unittest.TestLoader().loadTestsFromTestCase(TestLoginCase)
runner = HTMLTestRunner(
title="测试报告名称",
description="详细描述,例如测试的浏览器和环境",
stream=open(report_path, "wb"),
verbosity=2,
retry=0, # retry,指定重试次数,如果save_last_try 为True ,一个用例仅显示最后一次测试的结果。
save_last_try=True)
runner.run(cases)
# 所有用例运行完后关闭浏览器
Driver.quit_driver()
Driver.Driver = None
根据HTMLTestRunner_Chart要求为test_login.py 增加fixture,以获取用例失败后的截图
class TestLoginCase(unittest.TestCase):
@classmethod
def setUp(cls) -> None:
cls.driver = Driver.get_driver()
`
`
`
标签:sky attrs setup href inf constant 失败 修改 测试结果
原文地址:https://www.cnblogs.com/snailrunning/p/12236322.html