Skip to content

Commit

Permalink
�优化测试报告
Browse files Browse the repository at this point in the history
  • Loading branch information
liwanlei committed Apr 30, 2018
1 parent 49a5375 commit ee3372e
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 255 deletions.
17 changes: 17 additions & 0 deletions Public/get_excel_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
@author: lileilei
@file: get_excel_new.py
@time: 2018/4/30 11:04
"""
import xlrd
def datacel(filrpath):
all_case=[]
file=xlrd.open_workbook(filrpath)
me=file.sheets()[0]
nrows=me.nrows
for i in range(1,nrows):
all_case.append({"id":me.cell(i,0).value,'key':me.cell(i,2).value,
'coneent':me.cell(i,3).value,'url':me.cell(i,4).value,
'name':me.cell(i,1).value,'fangshi':me.cell(i,5).value,
'assert':me.cell(i,6).value})
return all_case
131 changes: 95 additions & 36 deletions Public/py_Html.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,61 @@
titles='接口测试'
def title(titles):
title='''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>%s</title>
<style type="text/css">
td{ width:40px; height:50px;}
</style>
</head>
<body>
<html>
<head>
<title>%s</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<style type="text/css">
.hidden-detail,.hidden-tr{
display:none;
}
</style>
</head>
<body>
'''%(titles)
return title
connent='''
<div style='width: 1170px;margin-left: 15%'>
<div class='col-md-4 col-md-offset-4'>
<h1>接口测试的结果</h1>'''
def shouye(starttime,endtime,passge,fail,excepthions,weizhicuowu):
beijing='''
<p><strong>开始时间:</strong> %s</p>
<p><strong>结束时间:</strong> %s</p>
<p><strong>耗时:</strong> %s</p>
<p><strong>结果:</strong>
<table class="table table-hover table-condensed">
<tbody>
<tr>
<td><strong>开始时间:</strong> %s</td>
</tr>
<td><strong>结束时间:</strong> %s</td></tr>
<td><strong>耗时:</strong> %s</td></tr>
<td><strong>结果:</strong>
<span >Pass: <strong >%s</strong>
Fail: <strong >%s</strong>
exception: <strong >%s</strong>
weizhicuowu : <strong >%s</strong></span></p>
<p ><strong>测试详情如下</strong></p> </div> '''%(starttime,endtime,(endtime-starttime),passge,fail,excepthions,weizhicuowu)
weizhicuowu : <strong >%s</strong></span></td>
</tr>
</tbody></table>
</div> '''%(starttime,endtime,(endtime-starttime),passge,fail,excepthions,weizhicuowu)
return beijing
shanghai='''
<p>&nbsp;</p>
<table border='2'cellspacing='1' cellpadding='1' width='1100'align="center" >
shanghai='''<div class="row " style="margin:60px">
<div style=' margin-top: 18%;' >
<div class="btn-group" role="group" aria-label="...">
<button type="button" id="check-all" class="btn btn-primary">所有用例</button>
<button type="button" id="check-success" class="btn btn-success">成功用例</button>
<button type="button" id="check-danger" class="btn btn-danger">失败用例</button>
<button type="button" id="check-warning" class="btn btn-warning">错误用例</button>
<button type="button" id="check-except" class="btn btn-defult">异常用例</button>
</div>
<div class="btn-group" role="group" aria-label="...">
</div>
<table class="table table-hover table-condensed table-bordered" style="word-wrap:break-word; word-break:break-all; margin-top: 7px;">
<tr >
<td ><strong>用例ID&nbsp;</strong></td>
<td><strong>用例名字</strong></td>
Expand All @@ -51,46 +77,79 @@ def shouye(starttime,endtime,passge,fail,excepthions,weizhicuowu):
'''
def passfail(tend):
if tend =='pass':
htl=' <td bgcolor="green">pass</td>'
htl='''<td bgcolor="green">pass</td>'''
elif tend =='fail':
htl=' <td bgcolor="fail">fail</td>'
htl='''<td bgcolor="fail">fail</td>'''
elif tend=='weizhi':
htl='<td bgcolor="red">error</td>'
htl='''<td bgcolor="red">error</td>'''
else:
htl = '<td bgcolor="#9300">error</td>'
htl = '<td bgcolor="crimson">exect</td>'
return htl
def ceshixiangqing(id,name,key,coneent,url,meth,yuqi,json,relust):
def ceshixiangqing(reslt,id,name,key,coneent,url,meth,yuqi,json,relust):
xiangqing='''
<tr>
<tr class="case-tr %s">
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s
</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
%s
</tr>
'''%(id,name,key,coneent,url,meth,yuqi,json,passfail(relust))
'''%(reslt,id,name,key,coneent,url,meth,yuqi,json,passfail(relust))
return xiangqing
weibu='''
</table>
</body>
</html>'''
weibu='''</div></div></table><script src="https://code.jquery.com/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript">
$("#check-danger").click(function(e){
$(".case-tr").removeClass("hidden-tr");
$(".success").addClass("hidden-tr");
$(".warning").addClass("hidden-tr");
$(".error").addClass("hidden-tr");
});
$("#check-warning").click(function(e){
$(".case-tr").removeClass("hidden-tr");
$(".success").addClass("hidden-tr");
$(".danger").addClass("hidden-tr");
$(".error").addClass("hidden-tr");
});
$("#check-success").click(function(e){
$(".case-tr").removeClass("hidden-tr");
$(".warning").addClass("hidden-tr");
$(".danger").addClass("hidden-tr");
$(".error").addClass("hidden-tr");
});
$("#check-except").click(function(e){
$(".case-tr").removeClass("hidden-tr");
$(".warning").addClass("hidden-tr");
$(".danger").addClass("hidden-tr");
$(".success").addClass("hidden-tr");
});
$("#check-all").click(function(e){
$(".case-tr").removeClass("hidden-tr");
});
</script>
</body></html>'''
def relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relust,exceptions,weizhi):
if type(name) ==list:
relus=' '
for i in range(len(name)):
relus+=(ceshixiangqing(id[i],name[i],key[i],coneent[i],url[i],meth[i],yuqi[i],json[i],relust[i]))
if relust[i] == "pass":
clazz = "success"
elif relust[i]== "fail":
clazz = "warning"
elif relust[i]== "weizhi":
clazz = "danger"
else:
clazz='error'
relus+=(ceshixiangqing(clazz,id[i],name[i],key[i],coneent[i],url[i],meth[i],yuqi[i],json[i],relust[i]))
text=title(titles)+connent+shouye(starttime,endtime,passge,fail,exceptions,weizhi)+shanghai+relus+weibu
else:
text=title(titles)+connent+shouye(starttime,endtime,passge,fail,exceptions,weizhi)+shanghai+ceshixiangqing(id,name,key,coneent,url,meth,yuqi,json,relust)+weibu
return text
def createHtml(filepath,titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts,exceptions,weizhi):
texts=relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts,exceptions,weizhi)
with open(filepath,'wb') as f:
f.write(texts.encode())
f.write(texts.encode('utf-8'))
Binary file modified img/cebaogaotu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ee3372e

Please sign in to comment.