接⼝⾃动化测试报告html模板
研究了下好⼏个接⼝⾃动化报告的模板,⾃⼰改造了个带饼图的接⼝⾃动化模板,先贴报告吧~
在贴代码如下:
# *-*coding:utf-8*-*
"""
@version: Python3.4.4
@author: Hszhang
@time: 2017/6/14 16:34
- 使⽤bottle来动态⽣成html
- ddit/r/learnpython/comments/2sfeg0/using_template_engine_with_python_for_generating/
"""
from bottle import template
import webbrowser
import json
import sys
html_template = u"""
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<title>接⼝测试报告</title>
<meta name="generator" content="HTMLTestRunner 0.8.2.2"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="libs.baidu/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="libs.baidu/jquery/2.0.0/jquery.min.js"></script>
<script src="libs.baidu/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<!-- 引⼊ echarts.js -->
<script type="text/javascript" src="echarts.baidu/gallery/vendors/echarts/echarts-all-3.js"></script>
<script type="text/javascript" src="echarts.baidu/gallery/vendors/echarts-stat/ecStat.min.js"></script>
<script type="text/javascript" src="echarts.baidu/gallery/vendors/echarts/extension/dataTool.min.js"></script>
<style type="text/css" media="screen">
body {
margin: 0;
font-family: "Arial", "Microsoft YaHei", "⿊体", "宋体", sans-serif;
font-size: 18px;
line-height: 1.5;
line-height: 1.5;
color: #333333;
}
.table {
margin-bottom: 1px;
width: 100%;
}
.hiddenRow {
display: none;
}
.container-fluid {
padding-right: 120px;
padding-left: 120px;
}
.nav-tabs li {
width: 186px;
text-align: center;
}
</style>
</head>
<body >
<script language="javascript" type="text/javascript">
function showClassDetail(detail_id, hiddenRow_id, class_type) {
console.ElementById(hiddenRow_id).className)
if ('详细' == ElementById(detail_id).innerText) {
if ('all' == class_type) {
bootstrap项目}
else if ('success' == class_type) {
}
else if ('error' == class_type) {
}
else{
}
}
else {
}
}
</script>
<div class="container-fluid">
<div class="page-header">
<h1 class="text-primary" >接⼝⾃动化测试报告</h1> </div>
<div class="col-md-12">
<div class="col-md-4" >
<h3 >测试基本信息</h3>
<table class="table table-hover table-bordered" >
<tbody>
<tr class="info">
<td class="text-center">开始时间</td>
<td class="text-center">{{start_time}}</td>
</tr>
<tr class="info">
<td class="text-center">结束时间</td>
<td class="text-center">{{end_time}}</td>
</tr>
<tr class="info">
<td class="text-center">测试⽤时</td>
<td class="text-center">{{used_time}}</td>
</tr>
<tr class="info">
<td class="text-center">总⽤例数</td>
<td class="text-center">{{sum_all_cases}}</td>
</tr>
<tr class="info">
<td class="text-center">执⾏⽤例数</td>
<td class="text-center">{{sum_executed_cases}}</td>
</tr>
<tr class="info">
<td class="text-center">跳过⽤例数</td>
<td class="text-center">{{sum_untreaded_cases}}</td> </tr>
</tbody>
</table>
</div>
<div class="col-md-8">
<!-- 为ECharts准备⼀个具备⼤⼩(宽⾼)的Dom -->
<div id="main" ></div>
<script type="text/javascript">
var myChart = echarts.ElementById('main')); var option = {
backgroundColor: '#F5F5F5', //背景⾊
title: {
text: '测试统计数据',
x: 'center'
},
legend: {
orient: 'vertical',
x: 'left',
data: ['成功', '失败', '未检验']
},
color: ['#3c763d', '#a94442', '#0099CC'],
calculable: true,
series: [{
name: '测试结果',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
startAngle: 135,
data: [{
value: {{right_sum}},
name: '成功',
itemStyle: {
normal: {
label: {
formatter: '{b} : {c} ({d}%)',
textStyle: {
align: 'left',
fontSize: 15,
}
},
labelLine: {
length: 40,
}
}
}
}, {
value: {{error_sum}},
name: '失败',
itemStyle: {
normal: {
label: {
formatter: '{b} : {c} ({d}%)',
textStyle: {
align: 'right',
fontSize: 15,
}
},
labelLine: {
length: 40,
}
}
}
}, {
value: {{untreated_sum}},
name: '未检验',
itemStyle: {
normal: {
label: {
formatter: '{b} : {c} ({d}%)',
textStyle: {
align: 'right',
fontSize: 15,
}
},
labelLine: {
length: 40,
}
}
}
}],
}]
};
/
/ 为echarts对象加载数据
myChart.setOption(option);
</script>
</div>
</div>
"""
REPORT_TMPL_Lable = '''
<div><span> </span></div>
<div class="col-md-12">
<div class="tabbable" id="tabs-957640">
<ul class="nav nav-tabs">
<li class="active">
<a href="#panel-0" data-toggle="tab" >全 部 ({})</a> </li>
<li>
<a href="#panel-1" data-toggle="tab" >成 功 ({})</a> </li>
<li>
<a href="#panel-2" data-toggle="tab" >失 败 ({})</a> </li>
<li>
<a href="#panel-3" data-toggle="tab" >未验证 ({})</a> </li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane active" id="panel-0">
<table class="table table-hover table-bordered">
{}
</table>
</div>
<div class="tab-pane" id="panel-1">
<table class="table table-hover table-bordered">
{}
</table>
</div>
<div class="tab-pane" id="panel-2">
<table class="table table-hover table-bordered">
{}
</table>
</div>
<div class="tab-pane" id="panel-3">
<table class="table table-hover table-bordered">
{}
</table>
</div>
</div>
</div>
</div>
</body>
</html>
'''
REPORT_TMPL_Title = '''
<table class="table table-hover table-bordered" >
<thead>
<colgroup>
{}
</colgroup>
<tr>
{}
</tr>
</thead>
<tbody></tbody>
</table>
'''
REPORT_Title_Width = ''' <col width='{}%'/>
'''
REPORT_Title_Lable = ''' <td class="text-center" >{}</td>
'''
REPORT_Table_Data = ''' <td class="text-center">{}</td>
'''
REPORT_Table_Detail = ''' <td class="text-center"><a href="javascript:showClassDetail('{}','{}', '{}')" class="detail" id = "{}">详细</a></td>
'''
EXPORT_Detali_text = ''' <tr class='hiddenRow' id="{}" >
<td colspan='{}'>
<div>
<pre class="text-left">
{}
</pre>
</div>
</td>
</tr>
'''
class HTML_REPORT:
def __init__(self, html_title, pie_theme, test_info, report_table_title, report_cases):
'''
@parameter html_title:HTML标题,字符串类型,如html_title = u'接⼝测试报告'
@parameter pie_theme:,饼图名称,字符串类型,pie_theme = u'接⼝数据统计'
@parameter test_info:,饼图数据统计,列表类型,长度 = 6,如test_info = ['2016-12-02 15:59:17', '2016-12-02 16:10:22', '11 分 4 秒',
len(report_cases['all_cases']), len(report_cases['right_cases']) + len(report_cases['error_cases']), len(report_cases['untreaded_cases'])]
@parameter report_table_title:接⼝表格标题,列表类型,可以⾃定义,report_cases = ['项⽬名称', '⽤例编号', '⽤例名称', '接⼝地址', '接⼝⽅法', '测试结果', '详细信息'] @parameter report_cases:接⼝测试结果记录,字典格式且key不能变,report_cases = {'all_cases':[['WEB理财', '1', '登录', 'login', 'post', 'pass', '详细信息', ''],['WEB 理财', '2', '产品列表', 'list', 'post', 'error', '详细信息', '']],
'right_cases':[['WEB理财', '1', '登录', 'login', 'post', 'pass', '详细信息', '']],
'error_cases':[['WEB理财', '2', '产品列表', 'list', 'post', 'error', '详细信息', '']],
'untreaded_cases':[['WEB理财', '3', '测试', 'login', 'post', '/', '详细信息', '']]
}
'''
if isinstance(html_title, str) and len(html_title) > 0:
self.html_title = html_title
else:
self.html_title = u'接⼝测试报告'
if isinstance(pie_theme, str) and len(pie_theme) > 0:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论