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. jmeter两种录制方式

    jmeter两种录制方式 一.Badboy Badboy是一款不错web自动化测试工具,利用它来录制脚本,并且录制的脚本可以直接保存为JMeter文件来使用. Badboy  version 2.1. ...

  2. 牛客 打印N个数组整体最大的Top K

    题目链接:https://www.nowcoder.com/practice/5727b69bf80541c98c06ab90cf4c509e?tpId=101&tqId=33102& ...

  3. SEC6 - MySQL 查询语句--------------进阶2:条件查询

    # 进阶2:条件查询 /* 语法: select 查询列表 from 表名 where 筛选条件; 分类: 一.按照条件表达式筛选 条件运算符:> < = !=(等价于<>) ...

  4. Android深度探索-卷1第五章心得体会

    S3C6410是由三星公司推出的一款低功耗.高性价比的RISC处理器,开发是,首先安装minicom串口调试工具: 第一步:检测当前系统是否支持USB转串口. Lsmod | grep usseria ...

  5. 排序算法三:堆排序(Heapsort)

    堆排序(Heapsort)是一种利用数据结构中的堆进行排序的算法,分为构建初始堆,减小堆的元素个数,调整堆共3步. (一)算法实现 protected void sort(int[] toSort) ...

  6. JavaScript LinkedList

    function LinkedList() { var Node = function(element) { this.element = element; this.next = null } va ...

  7. Linux 安装jdk+mysql+tomcat

    参考: 安装 jdk+mysql+tomcat   https://www.w3h5.com/post/65.html 安装 mysql  https://blog.csdn.net/qq_23123 ...

  8. 10: Django + Uwsgi + Nginx 的生产环境部署

    1.1 一些重要概念 1.Web协议介绍 Web协议出现顺序: CGI -> FCGI -> WSGI -> uwsgi 1. CGI:  最早的协议 2. FCGI:  比CGI快 ...

  9. 我心中的ASP.NET Core 新核心对象WebHost(二)

    这是ASP.NET Core新核心对象系列的第二篇,上一篇 WebHost准备阶段 我们讲到了WebHostBuilder的初始化及配置.我们给WebHostBuilder进行以下配置 UseKest ...

  10. https://blog.csdn.net/eguid_1/article/category/6270094

    https://blog.csdn.net/eguid_1/article/category/6270094