标签:
博主尝试了下更换python版本
之前很多脚本改正运行错误后、还是不能正常运行
忙会了半天还是没有成功
只好还原版本
所以下面的代码还没实际运行成功、先记录下
1 #!/usr/bin/env python 2 3 import subprocess 4 from project.createtest import CreateTest 5 import json 6 from xml.dom import minidom 7 8 txt_name = "case_login.txt" 9 excel_name = "case_list.txt" 10 cmd = "pict " + txt_name + " > " + excel_name 11 path = "E:\work\python case\project" 12 case_list = [] 13 data_list = [] 14 15 16 # noinspection PyTypeChecker 17 class CreateCase: 18 @classmethod 19 def case_cmd(cls): 20 subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, cwd=path) 21 print("接口测试用例生成成功") 22 23 @classmethod 24 def case_data(cls): 25 file_txt = open(r‘E:\work\python case\project\case_list.txt‘, "r+") 26 for line in file_txt.readlines(): 27 line = line.replace(‘\n‘, ‘‘).split("\t") 28 case_list.append(line) 29 for l in range (1, len(case_list)): 30 data_dict = {case_list[0][0]: case_list[l][0], case_list[0][1]: case_list[l][1]} 31 data_str = json.JSONEncoder().encode(data_dict) 32 data = json.loads(data_str) 33 data_list.append(data) 34 return data_list 35 # txt读取拆分截取、创建字典转化json字符串、再转化成json格式 36 37 @classmethod 38 def case_result(cls): 39 xml = minidom.Document() 40 xml.appendChild(xml.createComment("测试报告")) 41 caselist = xml.createElement("caselist") 42 xml.appendChild(caselist) 43 method = "post" 44 url = "http://localhost:8081/swcw/back/sysLogin.action" 45 for l in range (0, len(CreateCase.case_data())): 46 case_result = CreateTest.test_api(method, url, CreateCase.case_data()[l]) 47 case_code = str(case_result.status_code) 48 try: 49 CreateTest.test_http(case_result.status_code) 50 except AttributeError: 51 pass 52 53 # 生成xml文件 54 case = xml.createElement("case") 55 case.setAttribute("id", l) 56 # 输入用例ID 57 58 name = xml.createElement("name") 59 name.appendChild(xml.createTextNode("登录测试用例")) 60 # 输入用例名称 61 method = xml.createElement("method") 62 method.appendChild(xml.createTextNode("post")) 63 # 输入接口类型 64 code = xml.createElement("code") 65 code.appendChild((xml.createTextNode(case_code))) 66 # 输入用例返回状态码 67 result = xml.createElement("result") 68 result.appendChild(xml.createTextNode(CreateTest.test_result("个人中心", case_result.text))) 69 # 输入用例测试结果 70 time = xml.createElement("time") 71 time.appendChild(xml.createTextNode(CreateTest.test_time())) 72 # 输入用例执行时间 73 74 case.appendChild(name) 75 case.appendChild(method) 76 case.appendChild(code) 77 case.appendChild(result) 78 case.appendChild(time) 79 80 caselist.appendChild(case) 81 # xml文件生成结束 82 filename = open(CreateTest.test_report(), "w+") 83 # 生成以当前时间命名的测试报告文件 84 xml.writexml(filename) 85 filename.close() 86 # 关闭文件 87 88 if __name__ == ‘__main__‘: 89 CreateCase.case_result()
标签:
原文地址:http://www.cnblogs.com/cllovewxq/p/5408577.html