码迷,mamicode.com
首页 > 其他好文 > 详细

接口自动化测试(8)

时间:2017-06-09 15:18:23      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:logs   creat   方式   htm   site   文字   测试结果   create   project   

  接接口自动化测试7 ,由于提给我反馈说,想要用Excel管理测试报告,这两天由于加班,一直没有吧Excel的给搞出来,今天中午,花费了九牛二虎之力,虽然有点丑陋,但是做出来了,最近太忙,连夜加班加点改善这东西,好辛苦的节奏,

  后续可能的版本就不更新到GitHub,也不更新到这里了,小编这里的系列更新代码就到这里了,

  这里主要增加了xlwt模块的使用,这里呢,犹豫对于这个模块没有深入的探究,所以做出来的界面丑爆了,可以去GitHub 网站去看看官方的介绍,我的思路是这样的设置两个界面,第一展示测试报告结果啥的,第二个展示详情

  上我的代码实现

# encoding: utf-8
"""
@author: lileilei
@site: 
@software: PyCharm
@file: pyreport_excel.py
@time: 2017/6/7 8:47
"""
import xlrd ,os,xlwt,yaml #导入库
from xlwt import *
def yangshi1():
    style = XFStyle()
    fnt = Font()
    fnt.name = u微软雅黑
    fnt.bold = True
    style.font = fnt
    alignment = xlwt.Alignment()
    style.alignment = alignment  # 给样式添加文字居中属性
    style.font.height = 430  # 设置字体大小
    alignment = xlwt.Alignment()
    alignment.horz = xlwt.Alignment.HORZ_CENTER
    alignment.vert = xlwt.Alignment.VERT_CENTER
    style.alignment = alignment  # 给样式添加文字居中属性
    style.font.height = 430  #
    return style
def yangshi2():
    alignment = xlwt.Alignment()
    alignment.horz = xlwt.Alignment.HORZ_CENTER
    alignment.vert = xlwt.Alignment.VERT_CENTER
    style1 = XFStyle()
    style1.alignment = alignment  # 给样式添加文字居中属性
    style1.font.height = 330  # 设置字体大小
    alignment = xlwt.Alignment()
    alignment.horz = xlwt.Alignment.HORZ_CENTER
    alignment.vert = xlwt.Alignment.VERT_CENTER
    style1.alignment = alignment  # 给样式添加文字居中属性
    style1.font.height = 300  #
    return style1
def create(filename,list_pass,list_fail,listids,listnames,listkeys,listconeents,listurls,listfangshis,listqiwangs,list_json,listrelust):
    filepath = open(rC:\Users\Administrator\Desktop\jiekou\config\ceshibaogao.yaml, encoding=utf-8)
    file_config = yaml.load(filepath)
    file = Workbook(filename)
    table = file.add_sheet(测试结果,cell_overwrite_ok=True)
    style=yangshi1()
    for i in range(0, 7):
        table.col(i).width = 380*20
    style1=yangshi2()
    table.write_merge(0,0,0,6,测试报告,style=style)
    table.write_merge(1,1,0,6,‘‘,style=style)
    table.write_merge(2,3,0,6,测试详情,style=style1)
    table.write(4,0,项目名称,style=style1)
    table.write(5,0,接口版本,style=style1)
    table.write(6,0,提测时间,style=style1)
    table.write(7,0,提测人,style=style1)
    table.write(4,2,测试人,style=style1)
    table.write(5,2,测试时间,style=style1)
    table.write(6,2,审核人,style=style1)
    table.write(4,4,通过,style=style1)
    table.write(5,4,失败,style=style1)
    table.write(6,4,成功率,style=style1)
    table.write(4, 1, (file_config[projectname]),style=style1)
    table.write(5, 1, file_config[interfaceVersion],style=style1)
    table.write(6, 1, file_config[tijiao_time],style=style1)
    table.write(7, 1, file_config[tijiao_person],style=style1)
    table.write(4, 3, file_config[ceshi_person],style=style1)
    table.write(5, 3, file_config[ceshi_time],style=style1)
    table.write(6, 3, file_config[shenhename],style=style1)
    table.write(4, 5, (list_pass), style=style1)
    table.write(5, 5, (list_fail), style=style1)
    table.write(6, 5, (%.2f%%%((list_pass)/(len(listrelust)))), style=style1)
    table1 = file.add_sheet(测试详情,cell_overwrite_ok=True)
    table1.write_merge(0,0,0,8,测试详情,style=style)
    for i in range(0, 8):
        table1.col(i).width = 400*20
    table1.write(1,0,用例ID,style=style1)
    table1.write(1,1,用例名字,style=style1)
    table1.write(1,2,key,style=style1)
    table1.write(1,3,请求内容,style=style1)
    table1.write(1,4,    url,style=style1)
    table1.write(1,5,请求方式,style=style1)
    table1.write(1,6,预期,style=style1)
    table1.write(1,7,实际返回,style=style1)
    table1.write(1,8,结果,style=style1)
    for i in range(2,len(listids)):
        table1.write(i, 0, listids[i-2], style=style1)
        table1.write(i, 1, listnames[i-2], style=style1)
        table1.write(i, 2, listkeys[i-2], style=style1)
        table1.write(i, 3, listconeents[i-2], style=style1)
        table1.write(i, 4, listurls[i-2], style=style1)
        table1.write(i, 5, listfangshis[i-2], style=style1)
        table1.write(i, 6, listqiwangs[i-2], style=style1)
        table1.write(i, 7, str(list_json[i-2]), style=style1)
        table1.write(i, 8, listrelust[i-2], style=style1)
    file.save(filename)

最后我有加入了相应的Excel生成报告的界面,效果如图

技术分享

技术分享

 

 

 

 

  更新到这里,估计不会有什么更新了 在接口方面。感谢大家的支持

 

可以扫描二维码打赏我

 技术分享

 

 

 

 

 

  

接口自动化测试(8)

标签:logs   creat   方式   htm   site   文字   测试结果   create   project   

原文地址:http://www.cnblogs.com/leiziv5/p/6971842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!