class login(): def __init__(self): self.Opexl = OperationExcle('../dataCase/login.xls', 0) self.data = GetData() self.com_util = CommonUtil() self.run_method = RunMethod() def test_Login(self): rownums = self.data.get_case_line() for i in range(1, rownums): is_run = self.data.get_is_run(i) # print(is_run) url = self.data.get_url(i) # print(url) method = self.data.get_request_method(i) request_data = self.data.request_data_type_change(i) # print(request_data) expect = self.data.get_expect_data(i) # print(expect) header = self.data.is_header(i) select_str = 'select' insert_str = 'INSERT' update_str = 'UPDATE' delete_str = 'DELETE' for except_num in select_str, insert_str, update_str, delete_str: except_str = self.com_util.is_contain(except_num, expect) if except_str is True: expect = self.data.get_sql_expect_data(i) else: expect = self.data.get_expect_data(i) # print(expect) if is_run is True: res = self.run_method.run_main(method, url, request_data, header) if except_str is False: if self.com_util.is_contain(expect, res) == True: self.data.write_result(i, 'pass') print("测试通过") else: self.data.write_result(i, 'Filed') print('测试失败') # print(res) if except_str is True: if self.com_util.is_equal_dict(expect, res) == True: # 判断字典是否相等 self.data.write_result(i, 'pass') print('测试通过') else: self.data.write_result(i, res) print('测试失败') print(res) else: pass
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mail = SendEmail() self.op_testReport = Write_testReport_excle() # 程序执行 def go_on_run(self): global pass_count, fail_count res = None pass_count = [] fail_count = [] rows_count = self.data.get_case_line() # print(rows_count) for i in range(1, rows_count): is_run = self.data.get_is_run(i) # print(is_run) url = self.data.get_url(i) # print(url) method = self.data.get_request_method(i) request_data = self.data.request_data_type_change(i) # print(request_data) expect = self.data.get_expect_data(i) # print(expect) header = self.data.is_header(i) select_str = 'select' insert_str = 'INSERT' update_str = 'UPDATE' delete_str = 'DELETE' for except_num in select_str, insert_str, update_str, delete_str: except_str = self.com_util.is_contain(except_num, expect) if except_str is True: expect = self.data.get_sql_expect_data(i) else: expect = self.data.get_expect_data(i) # print(expect) errorNum = 0 if is_run is True: while errorNum <= Config_Try_Num: # 判段失败次数是否小于等于配置失败重试次数 res = self.run_method.run_main(method, url, request_data, header) if except_str is False: if self.com_util.is_contain(expect, res) == True: self.data.write_result(i, 'pass') print("测试通过") pass_count.append(i) errorNum = 0 break else: self.data.write_result(i, 'Filed') # print('测试失败,重试中') if errorNum < Config_Try_Num: errorNum += 1 print("测试失败,重试中,当前重试次数为第%s次" % (errorNum)) else: print("重试次数已用完,测试失败") fail_count.append(i) break # print(res) if except_str is True: if self.com_util.is_equal_dict( expect, res) == True: # 判断字典是否相等 self.data.write_result(i, 'pass') pass_count.append(i) print('测试通过') else: self.data.write_result(i, 'Filed') # print('测试失败,重试中') if errorNum < Config_Try_Num: errorNum += 1 print("测试失败,重试中,当前重试次数为第%s次" % (errorNum)) else: print("重试次数已用完,测试失败") fail_count.append(i) break else: pass print(res) # print(self.com_util.is_contain(expect,res)==True) # 发送邮件、生成测试报告 def create_test_report(self): self.op_testReport.write_TestReport(pass_count, fail_count) # 生成excel表格测试报告 self.op_testReport.excle_to_html() # 将测试报告转换为html输出 self.send_mail.send_main(pass_count, fail_count) # 发送测试报告邮件