修改报告样式

Signed-off-by: deveco_xdevice <liguangjie1@huawei.com>
This commit is contained in:
deveco_xdevice 2023-12-13 09:28:23 +08:00
parent c4531fbb39
commit 5207737fb6
2 changed files with 132 additions and 131 deletions

View File

@ -590,6 +590,7 @@ class VisionHelper:
file_context = self._render_exec_info(file_context, exec_info)
file_context = self._render_summary(file_context, summary)
if devices is not None and len(devices) != 0:
file_context = self._render_product_info(file_context, devices)
file_context = self._render_devices(file_context, devices)
if render_target == ReportConstant.summary_vision_report:
file_context = self._render_suites(file_context, suites)
@ -617,10 +618,15 @@ class VisionHelper:
if key == "index":
td_content = index
elif key == "others":
td_content = "<div class='tooltip'>" \
"<div class='ellipsis'>{}</div>" \
"<span class='tooltiptext'>{}</span>" \
"</div>".format(value, value)
if len(value) == 0:
td_content = f"""<div style="display: flex;">
<div class="ellipsis">{value}</div>
</div>"""
else:
td_content = f"""<div style="display: flex;">
<div class="ellipsis">{value}</div>
<div class="operate" onclick="showDialog('dialog{index}')"></div>
</div>"""
else:
td_content = value
tds.append("<td class='normal device-{}'>{}</td>".format(key, td_content))
@ -656,51 +662,46 @@ class VisionHelper:
value = self._get_hidden_style_value(getattr(
exec_info, key, "None"))
file_context = self._render_key(prefix, key, value, file_context)
file_context = self._render_product_info(exec_info, file_context,
prefix)
replace_str = "<!--{exec_info.task_log}-->"
file_context = file_context.replace(replace_str, self._get_task_log())
return file_context
def _render_product_info(self, exec_info, file_context, prefix):
"""Construct product info context and render it to file context
rendered product info sample:
<tr>
<td class="normal first">key:</td>
<td class="normal second">value</td>
<td class="normal third">key:</td>
<td class="normal fourth">value</td>
</tr>
Args:
exec_info: dict that used to update file_content
file_context: exist html content
prefix: target replace prefix key
Returns:
updated file context that includes rendered product info
"""
row_start = True
try:
keys = list(exec_info.product_info.keys())
except AttributeError as _:
LOG.error("Product info error %s", exec_info.product_info)
keys = []
render_value = ""
for key in keys:
value = exec_info.product_info[key]
if row_start:
render_value = "%s<tr>\n" % render_value
render_value = "{}{}".format(
render_value, self._get_exec_info_td(key, value, row_start))
if not row_start:
render_value = "%s</tr>\n" % render_value
row_start = not row_start
if not row_start:
render_value = "%s</tr>\n" % render_value
file_context = self._render_key(prefix, ReportConstant.product_info_,
render_value, file_context)
return file_context
@staticmethod
def _render_product_info(file_context, devices):
"""Construct product info context and render it to file context"""
render_result = ""
for index, device in enumerate(devices, 1):
others = device.get("others")
if len(others) == 0:
continue
tmp, count = "", 0
tbody_content = ""
for k, v in others.items():
tmp += f'<td class="key">{k}:</td>\n<td class="value">{v}</td>\n'
count += 1
if count == 2:
tbody_content += "<tr>" + tmp + "<tr>\n"
tmp, count = "", 0
if tmp != "":
tbody_content += "<tr>" + tmp + "<tr>\n"
render_dialog = f"""<div id="dialog{index}" , class="el-dialog">
<div style="margin: 15% auto; width: 60%;">
<div class="el-dialog__header">
<button class="el-dialog__close" onclick="hideDialog()">关闭</button>
</div>
<div class="el-dialog__body">
<table class="el-dialog__table">
<tbody>
{tbody_content}
</tbody>
</table>
</div>
</div>
</div>
"""
render_result += render_dialog
replace_str = "<!--{devices.dialogs}-->"
return file_context.replace(replace_str, render_result)
def _get_exec_info_td(self, key, value, row_start):
if not value:
@ -805,7 +806,6 @@ class VisionHelper:
replace_str = "<!--{suites.context}-->"
suites_context = "<table class='suites'>\n"
suites_context += self._get_task_log()
suites_context += self._get_suites_title()
for index, suite in enumerate(suites):
# construct suite context
@ -844,11 +844,7 @@ class VisionHelper:
def _get_task_log(self):
logs = [f for f in os.listdir(os.path.join(self.report_path, 'log')) if f.startswith('task_log.log')]
link = ["<a href='log/{task_log}'>{task_log}</a>".format(task_log=file_name) for file_name in logs]
temp = "<tr>\n" \
" <td class='tasklog'>TaskLog:</td>\n" \
" <td class='normal' colspan='8' style='border-bottom: 1px #E8F0FD solid;'>{}</td>\n" \
"</tr>".format(' | '.join(link))
return temp
return ' '.join(link)
def _get_testsuite_device_log(self, module_name, suite_name):
log_index, log_name = 0, 'device_log'

View File

@ -212,31 +212,10 @@
.ellipsis {
overflow: hidden;
width: 250px;
width: 180px;
text-overflow: ellipsis;
white-space: nowrap;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltiptext {
display: none;
position: absolute;
z-index: 1;
left: 0;
top: 100%;
background-color: #F2F5F7;
text-align: left;
border-radius: 5px;
padding: 5px 5px;
word-break: break-all;
max-height: 300px;
overflow-y: auto;
}
.tooltip:hover .tooltiptext {
display: inline-block;
}
table.suites {
width: 1160px;
@ -260,28 +239,19 @@
text-align: left;
}
table.suites th.module {
width: 138px;
padding: 10px 0 0 20px;
}
table.suites th.test-suite {
width: 384px;
padding: 10px 0 0 0;
width: 210px;
}
table.suites th.total {
width: 110px;
padding: 10px 0 0 0;
}
table.suites th.passed, table.suites th.failed, table.suites th.blocked {
width: 90px;
padding: 10px 0 0 0;
}
table.suites th.ignored, table.suites th.time {
width: 90px;
padding: 10px 0 0 0;
}
table.suites th.operate {
width: 58px;
padding: 10px 0 0 0;
}
table.suites tr.background-color{
background-color: #F9FAFC;
@ -295,28 +265,19 @@
word-break: break-all;
}
table.suites td.module {
width: 138px;
padding: 0 0 0 20px;
}
table.suites td.test-suite {
width: 384px;
padding: 0 0 0 0;
width: 210px;
}
table.suites td.total {
width: 110px;
padding: 0 0 0 0;
}
table.suites td.passed, table.suites td.failed, table.suites td.blocked {
width: 90px;
padding: 0 0 0 0;
}
table.suites td.ignored, table.suites td.time {
width: 90px;
padding: 0 0 0 0;
}
table.suites td.operate {
width: 58px;
padding: 0 0 0 0;
}
table.test-suite, table.failure-test {
@ -331,7 +292,6 @@
font-size: 14px;
height: 22px;
text-align: left;
wrap-option: no;
overflow: hidden;
}
table.test-suite th.normal, table.failure-test th.normal {
@ -343,28 +303,19 @@
text-align: left;
}
table.test-suite th.module {
width: 138px;
padding: 5px 0 0 20px;
}
table.test-suite th.test-suite {
width: 384px;
padding: 5px 0 0 0;
width: 210px;
}
table.test-suite th.test {
width: 427px;
padding: 5px 0 0 0;
}
table.test-suite th.time {
width: 90px;
padding: 5px 0 0 0;
}
table.test-suite th.status {
width: 11px;
padding: 5px 0 0 0;
}
table.test-suite th.result {
width: 90px;
padding: 5px 0 0 0;
}
.circle-normal {
border-radius: 50%;
@ -403,66 +354,50 @@
word-break: break-all;
}
table.test-suite td.module {
width: 138px;
padding: 0 0 0 20px;
}
table.test-suite td.test-suite {
width: 384px;
padding: 0 0 0 0;
width: 210px;
}
table.test-suite td.test {
width: 427px;
padding: 0 0 0 0;
}
table.test-suite td.time {
width: 90px;
padding: 0 0 0 0;
}
table.test-suite td.status {
width: 11px;
padding: 0 0 0 0;
}
table.test-suite td.result {
width: 90px;
padding: 0 0 0 0;
}
table.failure-test th.test {
width: 569px;
padding: 5px 0 0 20px;
}
table.failure-test th.status {
width: 11px;
padding: 5px 0 0 0;
}
table.failure-test th.result {
width: 80px;
padding: 5px 0 0 0;
}
table.failure-test th.details {
width: 480px;
padding: 5px 0 0 0;
}
table.failure-test td.test {
vertical-align: top;
width: 569px;
padding: 2px 0 0 20px;
}
table.failure-test td.status {
vertical-align: top;
width: 11px;
padding: 8px 0 0 0;
padding: 8px;
}
table.failure-test td.result {
vertical-align: top;
width: 80px;
padding: 2px 0 0 0;
}
table.failure-test td.details {
vertical-align: top;
width: 480px;
padding: 2px 0 0 0;
}
div.hidden {
@ -471,16 +406,68 @@
text-overflow: ellipsis;
width: 424px;
}
.el-dialog {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: none;
z-index: 9999;
}
.el-button {
margin-right: 10px;
}
.el-dialog__header {
background-color: #f5f7fa;
padding: 10px;
height: 30px;
}
.el-dialog__body {
background-color: #fff;
padding: 10px;
max-height: 280px;
overflow-y: auto;
}
.el-dialog__close {
font-size: 16px;
float: right;
}
table.el-dialog__table {
width: 100%;
background-color: #FFFFFF;
font-family: PingFangSC-Regular, sans-serif;
/* font-family: PingFangSC-Medium, sans-serif; */
}
table.el-dialog__table td {
color: #5E6678;
font-size: 14px;
height: 30px;
text-align: left;
word-break: break-all;
}
table.el-dialog__table td.key {
width: 20%;
font-weight: bold;
}
table.el-dialog__table td.value {
width: 30%;
}
</style>
</head>
<body>
<table class="logo">
<th>
<!--<div class="logo"></div>-->
</th>
</table>
<div class="layout">
<table class="exec-info" id="summary">
<tr>
@ -504,7 +491,10 @@
<td class="normal third">Execution Time:</td>
<td class="normal fourth"><!--{exec_info.execute_time}--></td>
</tr>
<!--{exec_info.product_info}-->
<tr>
<td class="normal first">Task Logs:</td>
<td class="normal second" colspan="3"><!--{exec_info.task_log}--></td>
</tr>
</table>
<table class="summary">
@ -531,10 +521,25 @@
</table>
<!--{devices.context}-->
<!--{devices.dialogs}-->
<h4>Test Details</h4>
<!--{suites.context}-->
<!--{cases.context}-->
<!--{failures.context}-->
</div>
<script>
function showDialog(dialog_id) {
const dialog = document.getElementById(dialog_id);
dialog.style.display = 'block';
}
function hideDialog() {
const dialogs = document.getElementsByClassName('el-dialog');
for (let i = 0; i < dialogs.length; i++) {
dialogs[i].style.display = 'none';
}
}
</script>
</body>
</html>