接口自动化测试(8)
接接口自动化测试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(r'C:\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生成报告的界面,效果如图
更新到这里,估计不会有什么更新了 在接口方面。感谢大家的支持
可以扫描二维码打赏我
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?