接接口自動化測試7 ,因爲提給我反饋說,想要用Excel管理測試報告,這兩天因爲加班,一直沒有吧Excel的給搞出來,今天中午,花費了九牛二虎之力,雖然有點醜陋,可是作出來了,最近太忙,連夜加班加點改善這東西,好辛苦的節奏,html
後續可能的版本就不更新到GitHub,也不更新到這裏了,小編這裏的系列更新代碼就到這裏了,python
這裏主要增長了xlwt模塊的使用,這裏呢,猶豫對於這個模塊沒有深刻的探究,因此作出來的界面醜爆了,能夠去GitHub 網站去看看官方的介紹,個人思路是這樣的設置兩個界面,第一展現測試報告結果啥的,第二個展現詳情git
上個人代碼實現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生成報告的界面,效果如圖json
更新到這裏,估計不會有什麼更新了 在接口方面。感謝你們的支持測試
能夠掃描二維碼打賞我字體