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