1:准备html模版

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>接口自动化</title>
</head>
<body style="margin-top: 20px; font-style: '微软雅黑';"> <table border="1" cellspacing="0" cellpadding="5" width="100%" align="center">
<tr bgcolor="bisque" style="font-style: 30px"> <td height="60" colspan="5">
自动化测试报告:&test_data </td>
</tr>
<tr style="font-style: 20px">
<td width="20%">被测版本:&version</td>
<td width="15%">成功:&pass</td>
<td width="15%">失败:&fail</td>
<td width="15%">错误:&error</td>
<td width="30%">最后时间:&lasttime</td>
</tr>
</table>
<p></p> <table border="1" cellspacing="0" cellpadding="5" width="100%" align="center">
<tr height="40" bgcolor="darkseagreen">
<td width="7%">记录编号:</td>
<td width="10%">记录编号:</td>
<td width="9%">记录编号:</td>
<td width="7%">记录编号:</td>
<td width="20%">记录编号:</td>
<td width="7%">记录编号:</td>
<td width="15%">记录编号:</td>
<td width="15%">记录编号:</td>
<td width="10%">记录编号:</td>
<td width="10%">记录编号:</td>
</tr>
&test_result </table>
</body>
</html>

打开模版,数据替换

'''
Created on Aug 8, 2019 @author: liliang
'''
import os
import time
from ctypes.test.test_pickling import name
class MyClass():
'''
classdocs
'''
def __init__(self):
pass
def open_file(self):
tempfile=os.path.abspath("..")+"/demo/2.html"
tem=open(tempfile, mode='r', encoding='utf-8').read()
return tem
def write_file(self,file,test_data,version,passnum,faillnum,errornum,lasttime,all_data):
file=file.replace("&test_data",test_data)
file=file.replace("&version",version)
file=file.replace('&pass',passnum)
file=file.replace('&fail',faillnum)
file=file.replace('&error',errornum)
file=file.replace('&lasttime',lasttime)
content=''
for i in range(0,len(all_data)):
if all_data[i]["name"] =="粉丝":
content+="<tr height=40 bgcolor='red'>"
content+="<td width='7%%' >%s</d>" %str(all_data[i]["name"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["age"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["sex"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["school"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["work"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["address"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["sex1"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["school2"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["work3"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["address4"])
content+="</tr>"
else: content+="<tr height=40 bgcolor='bisque'>"
content+="<td width='7%%' >%s</d>" %str(all_data[i]["name"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["age"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["sex"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["school"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["work"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["address"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["sex1"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["school2"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["work3"])
content+="<td width='7%%'>%s</d>" %str(all_data[i]["address4"])
content+="</tr>" # for result in all_data:
# content+="<tr height=40>"
# content+="<td width='7%%'>%s</d>" %str(result[0])
# content+="<td width='7%%'>%s</d>" %str(result[1])
# content+="<td width='7%%'>%s</d>" %str(result[2])
# content+="<td width='7%%'>%s</d>" %result[3]
# content+="<td width='7%%'>%s</d>" %result[4]
# content+="<td width='7%%'>%s</d>" %result[5]
# content+="<td width='7%%'>%s</d>" %result[6]
# content+="<td width='7%%'>%s</d>" %result[7]
# content+="<td width='7%%'>%s</d>" %result[8]
# content+="<td width='7%%'>%s</d>" %result[9]
# content+="</tr>"
file=file.replace('&test_result',content)
file_folder=os.path.abspath("..")+"/demo/"
file_name=file_folder+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+".html"
report_file=open(file_name, mode="w+", encoding='utf-8')
report_file.write(file)
report_file.close()
def get_datetime(self):
now_time=time.strftime("%Y_%M_%d_%H:%M:%S",time.localtime())
return now_time
if __name__ == '__main__':
my=MyClass()
file=my.open_file()
all_data=[
{"name":"Tom","age":23,"sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学2","work3":"学生","address4":"上海"},
{"name":"数据","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小3学","work3":"学生","address4":"上海"},
{"name":"粉丝","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学4","work3":"学生","address4":"上海"},
{"name":"阿道夫","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小fs学","work3":"学生","address4":"上海"},
{"name":"二娃","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学fa","work3":"学生","address4":"上海"},
{"name":"我确认","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学","work3":"学生","address4":"上海"},
{"name":"特务","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学fa","work3":"学生","address4":"上海"},
{"name":"突然","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学ddd","work3":"学生","address4":"上海"},
{"name":"圈儿","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小asss学","work3":"学生","address4":"上海"},
{"name":"让他","age":"13","sex":"男","school":"希望小学","work":"学生","address":"上海","sex1":"男","school2":"希望小学fdsaa","work3":"学生","address4":"上海"},
]
my.write_file(file, "2019_07_08_03:07:59", "1.3.0", "90", "7", "key error", "2019_07_08_03:07:59", all_data)
 生成报告

工程目录

python生成接口自动化测试报告模版的更多相关文章

  1. pytest+allure生成接口自动化测试报告

    准备环境 1.安装pytest pip install pytest -i http://pypi.douban.com/simple pytest-ordering pytest.main([ &q ...

  2. jmeter生成html格式接口自动化测试报告

    jmeter生成html格式接口自动化测试报告 jmeter自带执行结果查看的插件,但是需要在jmeter工具中才能查看,如果要向领导提交测试结果,不够方便直观. 笔者刚做了这方面的尝试,总结出来分享 ...

  3. python+request接口自动化框架

    python+request接口自动化框架搭建 1.数据准备2.用python获取Excel文件中测试用例数据3.通过requests测试接口4.根据接口返回的code值和Excel对比 但本章只讲整 ...

  4. unittest接口自动化测试报告

    unittest接口自动化测试报告 展示: 代码: __author__ = "Wai Yip Tung, Findyou" __version__ = "0.8.2.1 ...

  5. python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装

    前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...

  6. Python&Selenium&Unittest&BeautifuReport 自动化测试并生成HTML自动化测试报告

    一.摘要 本篇博文将介绍如何借助BeautifulReport和HTML模版,生成HTML测试报告的BeautifulReport 源码Clone地址为 https://github.com/Test ...

  7. Python+Selenium框架 ---自动化测试报告的生成

    本文来介绍如何生成自动化测试报告,前面文章尾部提到了利用HTMLTestRunner.py来生成自动化测试报告.关于HTMLTestRunner不过多介绍,只需要知道是一个能生成一个HTML格式的网页 ...

  8. python+requests接口自动化完整项目设计源码

    前言 有很多小伙伴吵着要完整的项目源码,完整的项目属于公司内部的代码,这个是没法分享的,违反职业道德了,就算别人分享了,也只适用于本公司内部的业务. 所以用例的代码还是得自己去一个个写,我只能分享项目 ...

  9. python+requests接口自动化完整项目设计源码(一)

    原文地址https://www.cnblogs.com/yoyoketang/tag/python接口自动化/ 原文地址https://www.cnblogs.com/yoyoketang/ 原文地址 ...

随机推荐

  1. 洛谷P2330 [SCOI2005]繁忙的都市——kruskal

    给一手链接 https://www.luogu.com.cn/problem/P2330 这道题实质就是最小生成树 TIPS:最小生成树不仅是整体权值最小,也是最大边最小 #include<cs ...

  2. Spring Security 04

    转至:Elim的博客http://elim.iteye.com/blog/2161648 Filter Porxy DelegatingFilterProxy DelegationFilterProx ...

  3. final-finally-finalize有什么区别

    一.final 1.final用于声明属性.方法和类,分别表示属性不可变,方法不可覆盖类和类不可能被继承(不可能再派生出新的子类). final属性:被final修饰的变量不可变. 1).引用不可变 ...

  4. Stupid cat & Doge (分形图)

    [题目描述] [题目链接] http://noi.openjudge.cn/ch0204/8463/ [算法] 为求等级N下的点的坐标可由几何关系找到其与等级N-1下对应点的关系,然后递归直至所有点的 ...

  5. LeetCode 852. Peak Index in a Mountain Array(C++)

    Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists som ...

  6. 【刷题】java 常见的几种运行时异常RuntimeException

    常见的几种罗列如下: -NullPointerException - 空指针引用异常 ClassCastException - 类型强制转换异常. IllegalArgumentException - ...

  7. Css中的!important

    转载自:https://www.cnblogs.com/cang12138/p/7326280.html !important为开发者提供了一个增加样式权重的方法,比直接在元素的 style 属性中设 ...

  8. JavaScript 中JSON

    JSON是JavaScript Object Notation的缩写,它是一种数据交换格式. 在JSON出现之前,大家一直用XML来传递数据.因为XML是一种纯文本格式,所以它适合在网络上交换数据.X ...

  9. 2019-9-2-win10-uwp-兴趣线

    title author date CreateTime categories win10 uwp 兴趣线 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 17 ...

  10. rpm - RPM 软件包管理器

    SYNOPSIS 查询和校验软件包: rpm {-q|--query} [select-options] [query-options] rpm {-V|--verify} [select-optio ...