mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
fix html report
This commit is contained in:
@@ -7,21 +7,18 @@ from httprunner.v3.schema import Record
|
||||
|
||||
|
||||
class HtmlTestResult(unittest.TextTestResult):
|
||||
""" A html result class that can generate formatted html results.
|
||||
Used by TextTestRunner.
|
||||
""" A html result class that can generate formatted html results, used by TextTestRunner.
|
||||
Each testcase is corresponding to one HtmlTestResult instance
|
||||
"""
|
||||
def __init__(self, stream, descriptions, verbosity):
|
||||
super(HtmlTestResult, self).__init__(stream, descriptions, verbosity)
|
||||
self.records = []
|
||||
self.record = Record()
|
||||
|
||||
def _record_test(self, test, status, attachment=''):
|
||||
record = Record(
|
||||
name=test.shortDescription(),
|
||||
status=status,
|
||||
attachment=attachment,
|
||||
meta_datas=test.meta_datas
|
||||
)
|
||||
self.records.append(record)
|
||||
self.record.name = test.shortDescription()
|
||||
self.record.status = status
|
||||
self.record.attachment = attachment
|
||||
self.record.meta_datas = test.meta_datas
|
||||
|
||||
def startTestRun(self):
|
||||
self.start_at = time.time()
|
||||
|
||||
@@ -181,17 +181,10 @@
|
||||
|
||||
<h2>Details</h2>
|
||||
|
||||
{% for test_suite_summary in details %}
|
||||
{% set suite_index = loop.index %}
|
||||
<h3>{{test_suite_summary.name}}</h3>
|
||||
<table id="suite_{{suite_index}}" class="details">
|
||||
<tr>
|
||||
<td>TOTAL: {{test_suite_summary.stat.total}}</td>
|
||||
<td>SUCCESS: {{test_suite_summary.stat.successes}}</td>
|
||||
<td>FAILED: {{test_suite_summary.stat.failures}}</td>
|
||||
<td>ERROR: {{test_suite_summary.stat.errors}}</td>
|
||||
<td>SKIPPED: {{test_suite_summary.stat.skipped}}</td>
|
||||
</tr>
|
||||
{% for testcase_summary in details %}
|
||||
{% set testcase_index = loop.index %}
|
||||
<h3>{{testcase_summary.name}}</h3>
|
||||
<table id="testcase_{{testcase_index}}" class="details">
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th colspan="2">Name</th>
|
||||
@@ -199,22 +192,22 @@
|
||||
<th>Detail</th>
|
||||
</tr>
|
||||
|
||||
{% for record in test_suite_summary.records %}
|
||||
{% set record_index = "{}_{}".format(suite_index, loop.index) %}
|
||||
{% set record_meta_datas = record.meta_datas %}
|
||||
<tr id="record_{{record_index}}">
|
||||
{% set record_meta_datas = testcase_summary.record.meta_datas %}
|
||||
{% for meta_data in record_meta_datas %}
|
||||
{% set step_index = "{}_{}".format(testcase_index, loop.index) %}
|
||||
<tr id="step_{{step_index}}">
|
||||
<th class="{{record.status}}" style="width:5em;">{{record.status}}</th>
|
||||
<td colspan="2">{{record.name}}</td>
|
||||
<td style="text-align:center;width:6em;">{{ record.response_time }} ms</td>
|
||||
<td class="detail">
|
||||
|
||||
{% for meta_data in record_meta_datas %}
|
||||
{% set meta_data_index = "{}_{}".format(record_index, loop.index) %}
|
||||
<a class="button" href="#popup_log_{{meta_data_index}}">log-{{loop.index}}</a>
|
||||
<div id="popup_log_{{meta_data_index}}" class="overlay">
|
||||
|
||||
{% set step_index = "{}_{}".format(testcase_index, loop.index) %}
|
||||
<a class="button" href="#popup_log_{{step_index}}">log-{{loop.index}}</a>
|
||||
<div id="popup_log_{{step_index}}" class="overlay">
|
||||
<div class="popup">
|
||||
<h2>Request and Response data</h2>
|
||||
<a class="close" href="#record_{{meta_data_index}}">×</a>
|
||||
<a class="close" href="#step_{{step_index}}">×</a>
|
||||
|
||||
<div class="content">
|
||||
<h3>Name: {{ meta_data.name }}</h3>
|
||||
@@ -342,11 +335,11 @@
|
||||
{% endfor %}
|
||||
|
||||
{% if record.attachment %}
|
||||
<a class="button" href="#popup_attachment_{{record_index}}">traceback</a>
|
||||
<div id="popup_attachment_{{record_index}}" class="overlay">
|
||||
<a class="button" href="#popup_attachment_{{step_index}}">traceback</a>
|
||||
<div id="popup_attachment_{{step_index}}" class="overlay">
|
||||
<div class="popup">
|
||||
<h2>Traceback Message</h2>
|
||||
<a class="close" href="#record_{{record_index}}">×</a>
|
||||
<a class="close" href="#step_{{step_index}}">×</a>
|
||||
<div class="content"><pre>{{ record.attachment | e }}</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -206,7 +206,7 @@ def stringify_summary(testsuite_summary: TestSuiteSummary):
|
||||
if not testcase_summary.name:
|
||||
testcase_summary.name = f"testcase {index}"
|
||||
|
||||
for record in testcase_summary.records:
|
||||
meta_datas = record.meta_datas
|
||||
__stringify_meta_datas(meta_datas)
|
||||
record.response_time = __get_total_response_time(meta_datas)
|
||||
record = testcase_summary.record
|
||||
meta_datas = record.meta_datas
|
||||
__stringify_meta_datas(meta_datas)
|
||||
record.response_time = __get_total_response_time(meta_datas)
|
||||
|
||||
@@ -53,7 +53,7 @@ def get_summary(result: HtmlTestResult) -> TestCaseSummary:
|
||||
"success": True,
|
||||
"stat": {},
|
||||
"time": {},
|
||||
"records": []
|
||||
"record": {}
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -71,6 +71,6 @@ def get_summary(result: HtmlTestResult) -> TestCaseSummary:
|
||||
start_at=result.start_at,
|
||||
duration=result.duration
|
||||
),
|
||||
records=result.records,
|
||||
record=result.record,
|
||||
in_out=TestCaseInOut()
|
||||
)
|
||||
|
||||
@@ -9,9 +9,9 @@ class TestHttpRunner(unittest.TestCase):
|
||||
self.runner = HttpRunner(failfast=True)
|
||||
|
||||
def test_run_testcase_by_path(self):
|
||||
summary = self.runner.run_path("examples/postman_echo/request_methods/request_with_variables.yml")
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["details"][0]["name"], "request methods testcase with variables")
|
||||
self.assertEqual(summary["details"][0]["records"][0]["name"], "request methods testcase with variables")
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 1)
|
||||
# self.assertEqual(summary["stat"]["teststeps"]["total"], 2)
|
||||
summary = self.runner.run_path("examples/postman_echo/request_methods/")
|
||||
self.assertTrue(summary.success)
|
||||
self.assertEqual(summary.details[0].name, "request methods testcase with variables")
|
||||
self.assertEqual(summary.details[0].record.name, "request methods testcase with variables")
|
||||
self.assertEqual(summary.stat.testcases["total"], 1)
|
||||
# self.assertEqual(summary.stat.teststeps["total"], 2)
|
||||
|
||||
@@ -134,7 +134,7 @@ class TestCaseSummary(BaseModel):
|
||||
success: bool
|
||||
stat: TestCaseStat
|
||||
time: TestCaseTime
|
||||
records: List = [Record]
|
||||
record: Record = {}
|
||||
in_out: TestCaseInOut = {}
|
||||
log: Text = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user