python接口自动化测试报告_python生成接口自动化测试报告模版

本文介绍如何利用Python创建接口自动化测试报告。通过读取HTML模板,替换关键数据,如测试结果、版本信息、通过数、失败数、错误数等,自动生成详细测试报告。并展示了具体实现代码。
摘要由CSDN通过智能技术生成

1:准备html模版

接口自动化

自动化测试报告:&test_data

被测版本:&version成功:&pass失败:&fail错误:&error最后时间:&lasttime
记录编号:记录编号:记录编号:记录编号:记录编号:记录编号:记录编号:记录编号:记录编号:记录编号:

&test_result

打开模版,数据替换

'''

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+="

"

content+="

%s" %str(all_data[i]["name"])

content+="

%s" %str(all_data[i]["age"])

content+="

%s" %str(all_data[i]["sex"])

content+="

%s" %str(all_data[i]["school"])

content+="

%s" %str(all_data[i]["work"])

content+="

%s" %str(all_data[i]["address"])

content+="

%s" %str(all_data[i]["sex1"])

content+="

%s" %str(all_data[i]["school2"])

content+="

%s" %str(all_data[i]["work3"])

content+="

%s" %str(all_data[i]["address4"])

content+="

"

content+="

"

content+="

%s" %str(all_data[i]["name"])

content+="

%s" %str(all_data[i]["age"])

content+="

%s" %str(all_data[i]["sex"])

content+="

%s" %str(all_data[i]["school"])

content+="

%s" %str(all_data[i]["work"])

content+="

%s" %str(all_data[i]["address"])

content+="

%s" %str(all_data[i]["sex1"])

content+="

%s" %str(all_data[i]["school2"])

content+="

%s" %str(all_data[i]["work3"])

content+="

%s" %str(all_data[i]["address4"])

content+="

"

# for result in all_data:

# content+="

"

# content+="

%s" %str(result[0])

# content+="

%s" %str(result[1])

# content+="

%s" %str(result[2])

# content+="

%s" %result[3]

# content+="

%s" %result[4]

# content+="

%s" %result[5]

# content+="

%s" %result[6]

# content+="

%s" %result[7]

# content+="

%s" %result[8]

# content+="

%s" %result[9]

# content+="

"

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)

生成报告

工程目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值