2017-06-05 17:35:28 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
|
"""
|
|
|
|
|
@author: lileilei
|
|
|
|
|
@site:
|
|
|
|
|
@software: PyCharm
|
2017-06-06 11:05:50 +08:00
|
|
|
@file: py_Html.py
|
2017-06-05 17:35:28 +08:00
|
|
|
@time: 2017/6/5 17:04
|
|
|
|
|
"""
|
2017-06-05 21:50:25 +08:00
|
|
|
import os
|
2017-06-05 17:35:28 +08:00
|
|
|
titles='接口测试'
|
2017-06-05 21:50:25 +08:00
|
|
|
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>
|
|
|
|
|
'''%(titles)
|
|
|
|
|
return title
|
2017-06-05 17:35:28 +08:00
|
|
|
connent='''
|
2017-06-06 11:05:50 +08:00
|
|
|
<div style='width: 1170px;margin-left: 20%'>
|
2017-06-05 17:35:28 +08:00
|
|
|
<h1>接口测试的结果</h1>'''
|
2017-06-05 21:50:25 +08:00
|
|
|
def time(starttime,endtime,passge,fail):
|
|
|
|
|
beijing='''
|
|
|
|
|
<p><strong>开始时间:</strong> %s</p>
|
2017-06-06 11:05:50 +08:00
|
|
|
<p><strong>结束时间:</strong> %s</p>
|
|
|
|
|
<p><strong>耗时:</strong> %s</p>
|
2017-06-05 21:50:25 +08:00
|
|
|
<p><strong>结果:</strong>
|
|
|
|
|
<span >Pass: <strong >%s</strong>
|
|
|
|
|
Fail: <strong >%s</strong>
|
|
|
|
|
</span></p>
|
2017-06-06 11:05:50 +08:00
|
|
|
<p ><strong>测试详情如下</strong></p> </div> '''%(starttime,endtime,(endtime-starttime),passge,fail)
|
2017-06-05 21:50:25 +08:00
|
|
|
return beijing
|
2017-06-05 17:35:28 +08:00
|
|
|
shanghai='''
|
2017-06-05 21:50:25 +08:00
|
|
|
|
|
|
|
|
|
2017-06-05 17:35:28 +08:00
|
|
|
<p> </p>
|
2017-06-05 21:50:25 +08:00
|
|
|
<table border='2'cellspacing='1' cellpadding='1' width='1100'align="center" >
|
|
|
|
|
<tr >
|
|
|
|
|
<td ><strong>用例ID </strong></td>
|
|
|
|
|
<td><strong>用例名字</strong></td>
|
|
|
|
|
<td><strong>key</strong></td>
|
2017-06-06 11:05:50 +08:00
|
|
|
<td><strong>请求内容</strong></td>
|
2017-06-05 21:50:25 +08:00
|
|
|
<td><strong>url</strong></td>
|
|
|
|
|
<td><strong>请求方式</strong></td>
|
|
|
|
|
<td><strong>预期</strong></td>
|
|
|
|
|
<td><strong>实际返回</strong></td>
|
|
|
|
|
<td><strong>结果</strong></td>
|
|
|
|
|
</tr>
|
2017-06-05 17:35:28 +08:00
|
|
|
'''
|
2017-06-05 21:50:25 +08:00
|
|
|
def passfail(tend):
|
|
|
|
|
if tend =='pass':
|
|
|
|
|
htl=' <td bgcolor="green">pass</td>'
|
|
|
|
|
elif tend =='fail':
|
|
|
|
|
htl=' <td bgcolor="fail">fail</td>'
|
|
|
|
|
else:
|
|
|
|
|
htl='<td bgcolor="#8b0000">error</td>'
|
|
|
|
|
return htl
|
|
|
|
|
def ceshixiangqing(id,name,key,coneent,url,meth,yuqi,json,relust):
|
|
|
|
|
xiangqing='''
|
|
|
|
|
<tr>
|
|
|
|
|
<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))
|
|
|
|
|
return xiangqing
|
|
|
|
|
weibu='''
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
</html>'''
|
2017-06-06 11:05:50 +08:00
|
|
|
|
2017-06-05 21:50:25 +08:00
|
|
|
def relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relust):
|
|
|
|
|
if type(name) ==list:
|
|
|
|
|
relus=' '
|
|
|
|
|
for i in range(len(name)):
|
2017-06-06 11:05:50 +08:00
|
|
|
relus+=(ceshixiangqing(id[i],name[i],key[i],coneent[i],url[i],meth[i],int(yuqi[i]),json[i],relust[i]))
|
2017-06-05 21:50:25 +08:00
|
|
|
text=title(titles)+connent+time(starttime,endtime,passge,fail)+shanghai+relus+weibu
|
|
|
|
|
else:
|
2017-06-06 11:05:50 +08:00
|
|
|
text=title(titles)+connent+time(starttime,endtime,passge,fail)+shanghai+ceshixiangqing(id,name,key,coneent,url,meth,int(yuqi),json,relust)+weibu
|
2017-06-05 21:50:25 +08:00
|
|
|
return text
|
|
|
|
|
def createHtml(filepath,titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts):
|
|
|
|
|
texts=relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts)
|
|
|
|
|
with open(filepath,'wb') as f:
|
|
|
|
|
f.write(texts.encode())
|