def test_run(self, tdata): ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls" caseid = int(tdata[0]) testcase_num = tdata[1] explain = tdata[3] url = tdata[4] type = tdata[5] expectation = tdata[6] m = 7 #前面有几个非参数字段这里写几 data = Change().list_dict(tdata, keys_list, m) result = Request(host).request(url, data, type) try: self.assertEqual(result["code"], expectation, "与期望值不符") test_result = "Pass" except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e)) test_result = "Faile" raise e else: self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain)) finally: writedata.write_onlydata(caseid, 0, testcase_num) writedata.write_onlydata(caseid, 1, explain) writedata.write_onlydata(caseid, 2, test_result) writedata.write_onlydata(caseid, 3, str(result)) for each in list(result.keys()): if each not in header: header.append(each) writedata.write_onlydata(0, header.index(each), each) for each in list(result.keys()): # print(str(result[each]) writedata.write_onlydata(caseid, header.index(each), str(result[each])) writedata.save_excel(ruselt_path)
def run(self, host): header = ["case_num", "explain", "result", "data", "code"] #第五个开始设置你需要的值(要和报文字典的key值对应) for n in range(len(header)): self.writedata.write_onlydata(0, n, header[n]) for i in range(len(self.test_data)): list_data = self.test_data[i] testcase_num = self.test_data[i][0] expalin = self.test_data[i][2] url = self.test_data[i][3] type = self.test_data[i][4] expectation = self.test_data[i][5] m = 6 #前面有几个非参数字段这里写几 data = Change().list_dict(list_data, self.keys_list, m) result = Request(host).request(url, data, type) try: assert int(result["code"]) == expectation, "结果与期望不一致" test_result = "Pass" except Exception as e: Logger().error("第%s条用例[%s]测试失败【%s】" % (testcase_num, expalin, e)) test_result = "Falie" else: Logger().info("第%s条用例[%s]测试通过" % (testcase_num, expalin)) finally: self.writedata.write_onlydata(i + 1, 0, testcase_num) self.writedata.write_onlydata(i + 1, 1, expalin) self.writedata.write_onlydata(i + 1, 2, test_result) self.writedata.write_onlydata(i + 1, 3, str(result)) for h in range(len(header)): if header[h] in list(result.keys()): self.writedata.write_onlydata(i + 1, h, str(result[header[h]])) self.writedata.save_excel(ruselt_path)
def test_run(self,tdata): global row ruselt_path = Project_path.TestResult_path +now + self.__class__.__name__ + ".xls" testcase_num = tdata[0] explain=tdata[2] url = tdata[3] type = tdata[4] expectation=tdata[5] m=6 #前面有几个非参数字段这里写几 data=Change().list_dict(tdata,keys_list,m) result=Request(host).request(url,data,type) try: self.assertEqual(result["code"],expectation,"与期望值不符") test_result = "Pass" except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num,explain,e)) test_result = "Faile" raise e else: self.Log.info("第%s条用例[%s]测试通过" %(testcase_num,explain)) finally: writedata.write_onlydata(row, 0, testcase_num) writedata.write_onlydata(row, 1, explain) writedata.write_onlydata(row, 2, test_result) writedata.write_onlydata(row, 3, str(result)) for h in range(len(header)): if header[h] in list(result.keys()): writedata.write_onlydata(row, h, str(result[header[h]])) row+=1 writedata.save_excel(ruselt_path)
def test_run(self, bookname): writedata.creattable(bookname) test_data = [] self.test_datas = self.r.read_data(bookname, 1) keys_list = self.r.read_data(bookname, 0)[0] if mode == 1: Logger().info("[mode:1],本次测试执行基本流测试用例") for i in range(len(self.test_datas)): if self.test_datas[i][1] == 1: test_data.append(self.test_datas[i]) i += 1 else: continue elif mode == 0: Logger().info("[mode:0],本次测试执行全部测试用例") test_data = self.test_datas datas = [] datas.append(keys_list) datas.append(test_data) keys_list = datas[0] test_data = datas[1] self.header = ["case_num", "explain", "result", "data", "code"] # 第四个开始设置你需要的值(要和报文字典的key值对应) for n in range(len(self.header)): writedata.write_onlydata(0, n, self.header[n]) for tdata in test_data: global row ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls" testcase_num = tdata[0] explain = tdata[2] url = tdata[3] type = tdata[4] expectation = tdata[5] m = 6 # 前面有几个非参数字段这里写几 data = Change().list_dict(tdata, keys_list, m) result = Request(host).request(url, data, type) try: self.assertEqual(result["code"], expectation, "与期望值不符") test_result = "Pass" except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e)) test_result = "Faile" raise e else: self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain)) finally: writedata.write_onlydata(row, 0, testcase_num) writedata.write_onlydata(row, 1, explain) writedata.write_onlydata(row, 2, test_result) writedata.write_onlydata(row, 3, str(result)) for h in range(len(self.header)): if self.header[h] in list(result.keys()): writedata.write_onlydata(row, h, str(result[self.header[h]])) row += 1 writedata.save_excel(ruselt_path) row = 1
def test_run(self, tdata): ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls" caseid = int(tdata[0]) testcase_num = tdata[1] explain = tdata[3] url = tdata[4] type = tdata[5] comparison_key = tdata[6] if tdata[7] == 0: expectation = tdata[8] elif tdata[7] == 1: expectation = sql.read_data(tdata[8]) else: return "sql类型错误" m = 9 #前面有几个非参数字段这里写几 data = Change().list_dict(tdata, keys_list, m) result = Request(host).request(url, data, type) try: self.assertEqual(str(result[comparison_key]), str(expectation), "与期望值不符") test_result = "Pass" except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e)) test_result = "Faile" raise e else: self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain)) finally: pass
def test_run(self, book_names): # 创建表格,建立表头 for book_name in book_names: datas = self.get_data(book_name) keys_list = datas[0] test_data = datas[1] self.writedata.creattable(book_name) self.header = ["case_num", "explain", "result", "data", "code"] # 第四个开始设置你需要的值(要和报文字典的key值对应) for n in range(len(self.header)): self.writedata.write_onlydata(0, n, self.header[n]) for tdata in test_data: global row ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls" testcase_num = tdata[0] explain = tdata[2] url = tdata[3] type = tdata[4] expectation = tdata[5] m = 6 # 前面有几个非参数字段这里写几 data = Change().list_dict(tdata, keys_list, m) result = Request(host).request(url, data, type) try: assert result["code"] == expectation, "与期望值不符" test_result = "Pass" except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e)) test_result = "Faile" raise e else: self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain)) finally: self.writedata.write_onlydata(row, 0, testcase_num) self.writedata.write_onlydata(row, 1, explain) self.writedata.write_onlydata(row, 2, test_result) self.writedata.write_onlydata(row, 3, str(result)) for h in range(len(self.header)): if self.header[h] in list(result.keys()): self.writedata.write_onlydata( row, h, str(result[self.header[h]])) row += 1 self.writedata.save_excel(ruselt_path) row = 1
def test_mission(self): url = '/api/user/mission/list' data = {'uid': uid} type = 'get' result = Request(host).request(url, data, type) try: self.assertEqual(str(result['code']), '1', "与期望值不符") except Exception as e: self.Log.error("%s测试失败【%s】" % (sys._getframe().f_code.co_name, e)) raise e else: self.Log.info("%s测试通过" % sys._getframe().f_code.co_name)
def test_run(self, tdata): # def run(*args): ruselt_path = Project_path.TestResult_path + now + self.__class__.__name__ + ".xls" caseid = int(tdata[0]) testcase_num = tdata[1] explain = tdata[3] url = tdata[4] type = tdata[5] comparison_key = tdata[6] if tdata[7] == 0: expectation = tdata[8] elif tdata[7] == 1: expectation = sql.read_data(tdata[8]) else: return "sql类型错误" m = 9 #前面有几个非参数字段这里写几 data = Change().list_dict(tdata, keys_list, m) # print(data,host,url) result = Request(host).request(url, data, type) try: self.assertEqual(str(result[comparison_key]), str(expectation), "与期望值不符") except Exception as e: self.Log.error("第%s条用例[%s]测试失败【%s】" % (testcase_num, explain, e)) test_result = "Faile" raise e else: test_result = "Pass" self.Log.info("第%s条用例[%s]测试通过" % (testcase_num, explain)) finally: # writedata.write_onlydata(caseid, 0, testcase_num) # writedata.write_onlydata(caseid, 1, explain) # writedata.write_onlydata(caseid, 2, test_result) # writedata.write_onlydata(caseid, 3, str(result)) # for each in list(result.keys()): # if each not in header: # header.append(each) # writedata.write_onlydata(0, header.index(each), each) # for each in list(result.keys()): # # print(str(result[each]) # writedata.write_onlydata(caseid, header.index(each), str(result[each])) # writedata.save_excel(ruselt_path) # if result['code'] == 1: # uid = result['user']['id'] uid = 500 gl._init() gl.set_value('uid', uid)
def test_login(self): global uid url = '/api/user/signin' data = { 'account': 13017600000, 'appKey': 'all', 'category_id': 81, 'password': 123456, 'terminal': 2 } type = 'get' result = Request(host).request(url, data, type) try: self.assertEqual(str(result['code']), '1', "与期望值不符") except Exception as e: self.Log.error("%s测试失败【%s】" % (sys._getframe().f_code.co_name, e)) raise e else: self.Log.info("%s测试通过" % sys._getframe().f_code.co_name) result['code'] == 1 uid = result['user']['id']