class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.asserts=Assert(self.data) self.od=OpenrationData() self.log=Log() def run_test_case(self): try: res = None rows_count = self.data.get_case_lines() for row in range(1, rows_count): is_run = self.data.get_is_run(row) if is_run: name = self.data.get_request_name(row) url = self.data.get_request_url(row) method = self.data.get_request_method(row) expect = self.data.get_expcet_data(row) is_update = self.data.get_is_update(row) header = self.data.get_is_header(row) depend_case = self.data.get_is_depend(row) if is_update: self.od.update_requests(row) if depend_case: self.od.replace_requests_data(depend_case,row) request_data = self.data.get_data_for_json(row) if header: res = self.run_method.run_main(method, url, request_data,header) else: res = self.run_method.run_main(method, url, request_data) self.asserts.assertIn(expect, res, row) self.log.test_log(name, method + '/' + url, request_data, res) except Exception as er: self.log.error_log(er)
def run_dependent(self): run_method = RunMethod() row_num = self.opera_excel.get_row_num(self.case_id) request_data = self.data.get_data_for_json(row_num) #header = self.data.is_header(row_num) method = self.data.get_request_method(row_num) header = self.data.is_header(row_num) url = self.data.get_request_url(row_num) files = {'file': ( 'new1.xlsx', open("C:\\Users\\Aaron\\Desktop\\new1.xlsx", 'rb'), 'application/vnd.ms-excel')} if header == "yes": op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = { 'apsid': cookie } headers1 = op_json.get_data('Authorization') headers = { 'Authorization': headers1 } res = run_method.run_main(method, url,request_data,headers,files,cookies) else: res = run_method.run_main(method,url,request_data) return json.loads(res)
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.commonutil = Commonutil() self.sendmail = SendEmail() def go_on_run(self): # 程序执行 pass_count = [] fail_count = [] rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) data = self.data.get_data_for_json(i) # expect = self.data.get_expect_data(i) # Excel写入预期结果 expect = self.data.get_expect_data_for_mysql(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) res = self.run_method.run_main(method, url, data, header) values = {"resultCode": res["resultCode"]} # print(res["resultData"]["access_id"]) value = json.dumps(values) # 字典转字符串匹配 if depend_case is not None: self.depend_data = DependentDate(depend_case) # 依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) # 获取依赖的key data = json.loads(data) depend_key = self.data.get_depend_field(i) data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method, url, data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperationJson('../dataconfig/cooking.json') cookie = op_json.get_data('apsid') cookies = { 'apsid': cookie } value = self.run_method.run_main(method, url, data, cookies) else: value = self.run_method.run_main(method, url, data) if self.commonutil.is_equal_dict(expect, value): self.data.write_result(i, '通过') pass_count.append(i) print('测试通过') else: self.data.write_result(i, '失败') fail_count.append(i) print('测试失败') print(pass_count, fail_count) self.sendmail.send_main(pass_count, fail_count)
class RunTest(): def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() #不带文件发送 self.send_email=Email() #带文件发送 get_user_log=UserLog() self.logger = get_user_log.get_log() #程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3 rows_count = self.data.get_case_lines() for i in range(1,rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) case_name=self.data.get_case_name(i) if depend_case != None: self.depend_data = DependdentData(depend_case) #获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_field(i) request_data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method,url,request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('./dataconfig/cookie.json') cookie = op_json.get_data('apsid') # cookies = { # 'apsid':cookie # } res = self.run_method.run_main(method,url,request_data,cookie) self.logger.info("用例名称:"+case_name+"--->返回值:"+res) #print(res) else: res = self.run_method.run_main(method,url,request_data) self.logger.info("用例名称:" + case_name + "--->返回值:" + res) #print(res) if self.com_util.is_contain(expect,res) == True: self.data.write_result(i,'pass') pass_count.append(i) else: self.data.write_result(i,res) fail_count.append(i) self.send_mai.send_main(pass_count,fail_count) #不带文件发送
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() #程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3 rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) #通过数据库获取预期结果 #expect = self.data.get_expcet_data_for_mysql(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) if depend_case != None: self.depend_data = DependdentData(depend_case) #获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_field(i) request_data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = {'apsid': cookie} res = self.run_method.run_main(method, url, request_data, cookies) else: res = self.run_method.run_main(method, url, request_data) if self.com_util.is_equal_dict(expect, res) == 0: self.data.write_result(i, 'pass') pass_count.append(i) res = pass_count else: self.data.write_result(i, res) fail_count.append(i) res = fail_count self.send_mai.send_main(pass_count, fail_count)
def run_dependent(self): run_method = RunMethod() row = self.opera_excel.get_rows_data(self.case_id) request_data = self.data.get_data_for_json(row_num) header = self.data.is_header(row_num) method = self.data.get_request_method(row) url = self.data.get_request_url(row) run_method.run_main(method, url, request_data, header) return res
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() #程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3 rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) # expect = self.data.get_expcet_data_for_mysql(i) expect = self.data.get_expcet_data(i) # sql_data = expect.strip("[]") sql_data1 = eval(expect) # sql_result = eval(sql_data1) header = self.data.is_header(i) depend_case = self.data.is_depend(i) if depend_case != None: self.depend_data = DependdentData(depend_case) #获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_field(i) request_data[depend_key] = depend_response_data # print(request_data[depend_key]) # res = self.run_method.run_main(method,url,request_data) if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': res = self.run_method.run_main(method, url, request_data) # print(5,res) else: res = self.run_method.run_main(method, url, request_data) print(4, res) if self.com_util.is_equal_dict(res, sql_data1): self.data.write_result(i, 'pass') pass_count.append(i) else: self.data.write_result(i, str(res)) fail_count.append(i) #将运行结果通过钉钉发送 dd_mes(pass_count, fail_count) exit()
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() #程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3 depend_data = '' rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_request_data(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) if depend_case != None: self.depend_data = DependdentData(depend_case) #获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) depend_data = depend_response_data #获取依赖的key depend_key = self.data.get_depend_field(i) #数据依赖自动未填写,则不处理;请求自动无数据依赖字段,则不处理 if depend_key != None and request_data.haskey(depend_key): request_data[depend_key] = depend_response_data if header == None: res = self.run_method.run_main(method, url, request_data) elif header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_header() #op_header.write_cookie() else: res = self.run_method.run_main(method, url, request_data, header) #函数判断 if expect.find('${') >= 0: self.data.find_def(expect) elif self.com_util.is_contain(expect, res): self.data.write_result(i, 'pass') pass_count.append(i) else: self.data.write_result(i, res) fail_count.append(i)
class RunTest(object): def __init__(self): self.runmethod = RunMethod() self.getdata = GetData() self.commonutil = CommonUtil() self.sendmail = SendMail() def go_on_run(self): pass_count = [] fail_count = [] cookies = None rows = self.getdata.get_case_lines() for i in range(1, rows): is_run = self.getdata.get_is_run(i) if is_run: url = self.getdata.get_url(i) is_depend = self.getdata.is_depend(i) request_method = self.getdata.get_request_method(i) expect = self.getdata.get_expect(i) # print(expect) is_cookie = self.getdata.is_cookie(i) is_header = self.getdata.is_header(i) data = self.getdata.get_data_for_json(i) print(data) depend_case = self.getdata.is_depend(i) if is_depend: self.depend_data = DependentData(depend_case) field_depend = self.getdata.get_field_depend(i) data_depend = self.depend_data.get_data_for_key(i) data[field_depend] = data_depend if is_cookie == 'write': res = self.runmethod.run_main(url, request_method, data) op_cookie = OperationCookie(json.loads(res)) op_cookie.write_cookie() if is_cookie == 'yes': op_json = OperationJson('../dataconfig/cookie.json') cookie = op_json.get_data("apsid") cookies = {"apsid": cookie} res = self.runmethod.run_main(url, request_method, data, is_header, cookies) if self.commonutil.iscontain(expect, res): print("测试通过") self.getdata.write_result(i, "测试通过") pass_count.append(i) else: print(expect) print(res) print("测试失败") self.getdata.write_result(i, res) fail_count.append(i) else: return None
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() #程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3 rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) # expect = self.data.get_expcet_data_for_mysql(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) if depend_case != None: self.depend_data = DependdentData(depend_case) #获取依赖的响应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_field(i) request_data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = {'apsid': cookie} res = self.run_method.run_main(method, url, request_data, cookies) else: res = self.run_method.run_main(method, url, request_data) # print(res["data"][2]["context"]) print(res) # print(type(res)) #自己写的:这个是判断字段是否在结果中 if expect in res: self.data.write_result(i, "pass") pass_count.append(i) else: self.data.write_result(i, "fail") fail_count.append(i)
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() # 程序执行的 def go_on_run(self): res = None pass_count = [] fail_count = [] # 10 0,1,2,3 rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) expect = self.data.get_expcet_data_for_mysql(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) if depend_case != None: self.depend_data = DependdentData(depend_case) # 获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) # 获取依赖的key depend_key = self.data.get_depend_field(i) request_data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = { 'apsid': cookie } res = self.run_method.run_main(method, url, request_data, cookies) else: res = self.run_method.run_main(method, url, request_data) if self.com_util.is_equal_dict(expect, res) == 0: self.data.write_result(i, 'pass') pass_count.append(i) else: self.data.write_result(i, res) fail_count.append(i) self.send_mai.send_main(pass_count, fail_count)
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() #程序执行的主入口 def go_on_run(self): res = None pass_count = [] fail_count = [] #10 0,1,2,3,4,5,6...... 第一行不需要 rows_count = self.data.get_case_lines() for i in range(1, rows_count): url = self.data.get_request_url(i) method = self.data.get_request_method(i) is_run = self.data.get_is_run(i) data = self.data.get_data_for_json(i) #不能调用get_request_data()方法 expect = self.data.get_expect_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) # 有依赖后 需要把需要的数据组装起来 返回结果 if depend_case != None: self.sepend_data = DependentData() #获取的依赖相应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_filed(i) request_data[depend_key] = depend_response_data res = self.run_method.run_main(method, url, data, header) if is_run: #method,url,data=None,header=None run_main里边变量的顺序不能错 res = self.run_method.run_main(method, url, data, header) # print (type(res)) if self.com_util.is_contain(expect, res): # print ("测试通过") self.data.write_result(i, 'pass') pass_count.append(i) print(pass_count) print(len(pass_count)) else: # print ("测试失败") self.data.write_result(i, 'fail') fail_count.append(i) # print (len(fail_count)) print(fail_count) return res self.send_mai.send_main([1, 2], [1]) self.send_mai.send_main([1, 2], [1])
class MainCase(unittest.TestCase): def setUp(self): self.run_method = RunMethod() self.com_util = CommonUtil() @data(*case_list) @unpack def test_main(self, sheet_name, case_name, sheet_id, case_id): self.data = GetData(sheet_id) is_run = self.data.get_is_run(case_id) if is_run: url = self.data.get_request_url(case_id) method = self.data.get_request_method(case_id) #request_data = self.data.get_data_for_json(i) request_data = self.data.get_request_data(case_id) # expect = self.data.get_expcet_data_for_mysql(i) expect = self.data.get_expcet_data(case_id) header = self.data.is_header(case_id) depend_case = self.data.is_depend(case_id) if depend_case != None: self.depend_data = DependdentData(sheet_id, depend_case) # 获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(case_id) # 获取依赖的key depend_key = self.data.get_depend_field(case_id) request_data[depend_key] = depend_response_data if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = { 'apsid': cookie } res = self.run_method.run_main(method, url, request_data, cookies) else: res = self.run_method.run_main(method, url, request_data) print(res) if self.com_util.is_contain(expect, res): self.data.write_result(case_id,'pass') else: self.data.write_result(case_id, res) #self.assertIn(expect,res,"预期结果:{0} 未在实际返回结果:{1} 中! ".format(expect,res)) #添加最后结果时间戳 self.data.write_result(0, '实际结果 {}'.format(time.strftime("%Y_%m_%d_%H_%M_%S"))) self.assertIn(expect,res)
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_uitl = CommonUitl() #程序执行的主入口 def go_on_run(self): res = None #获取excel行数 即case个数 rows_count = self.data.get_case_lines() for i in range(1, rows_count): url = self.data.get_url(i) method = self.data.get_request_method(i) is_run = self.data.get_is_run(i) data = self.data.get_data_for_json(i) #预期结果值 except_data = self.data.get_except_data(i) #header = self.data.is_header(i) if is_run: #method,url,data=None,header=None 顺序不能错 res = self.run_method.run_main(method, url, data) print res if self.com_uitl.is_contain(except_data, res): #print "测试通过" self.data.write_data(i, "pass") else: #print "测试失败" self.data.write_data(i, "fail")
class DependentData: def __init__(self, case_id): self.case_id = case_id self.opera_excel = OpertionExcel() self.run = RunMethod() self.data = GetData() #通过case_id去获得该case_id的数据 def get_case_line_data(self): rows_data = self.opera_excel.get_rows_data(self.case_id) return rows_data #执行依赖测试获取的数据 def run_dependent(self): row_num = self.opera_excel.get_rows_num(self.case_id) request_data = self.data.get_data_for_json(row_num) url = self.data.get_url(row_num) method = self.data.get_request_way(row_num) header = self.data.is_header(row_num) #method,url,data=None,header=None run_depen = self.run.run_main(method, url, request_data, header) return json.loads(run_depen) #根据依赖的key去获取执行依赖测试case的响应,然后返回 def get_data_for_key(self, rowx): depend_data = self.data.get_dependent_data(rowx) response_data = self.run_dependent() # print(depend_data) # print(response_data) json_exe = parse(depend_data) madle = json_exe.find(response_data) return [math.value for math in madle][0]
def run_dependent(self): run_method = RunMethod() row_num = self.opera_excel.get_row_num(self.case_id) request_data = self.data.get_data_for_json(row_num) header = self.data.is_header(row_num) method = self.data.get_request_method(row_num) url = self.data.get_request_url(row_num) # res = run_method.run_main(method,url,request_data) res = None if header == "yes": op_json = OperetionJson('./dataconfig/cookie.json') cookie = op_json.get_data('apsid') res = run_method.run_main(method, url, request_data, cookie) else: res = run_method.run_main(method, url, request_data) return json.loads(res)
class GetLogininfo: def __init__(self, case_line): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.case_line = case_line def get_logininfo(self): userinfolist = [] url = self.data.request_url(self.case_line) print(url) method = self.data.get_request_method(self.case_line) print(method) op_json = OperationJson('../dataconfig/cookie.json') cookies = op_json.get_data('header') # print(cookies) request_data = self.data.get_data_for_json(7) print(request_data) res = self.run_method.run_main(method, url, request_data, cookies) # print(type(res)) res = json.loads(res) # print(type(res)) usercheck = res['info']['usercheck'] userid = res['info']['userid'] userinfolist = [usercheck, userid] # print(userinfolist) return userinfolist
class RunTest(): def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() # 程序执行 def go_on_run(self): rows_count = self.data.get_case_lines() for i in range(1,rows_count): url = self.data.get_request_url(i) method = self.data.get_request_method(i) is_run = self.data.get_is_run(i) data = self.data.get_data_for_json(i) expect = self.data.get_except_data(i) header = self.data.get_is_header(i) if is_run: res = self.run_method.run_main(method,url,data,header) if self.com_util.is_contain(expect,res): print(res) #print("测试通过") #self.data.write_result(i,"pass") else: print(res)
class RunTest(): def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() # 程序执行 def go_on_run(self): res = None rows_count = self.data.get_case_line() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_data_for_json(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) depend_case = self.data.is_depend(i) res = self.run_method.run_main(method, url, data, header) if depend_case != None: self.dependent_data = DependdentData() depend_response_data = self.depend_data.get_data_for_key(i) if self.com_util.is_contain(expect, res): self.data.write_result(i, 'pass') else: self.data.write_result(i, 'fail')
class RunTest: def __init__(self): self.runmet = RunMethod() self.getdata = GetDat() self.comm = CommUtil() def goto_run(self): pass_count = [] fail_count = [] res = None # run_col = self.getdata.get_cell_col()#列 run_now = self.getdata.get_cell_row()#行 #使用range()函数从第二列获取 for i in range(1,run_now): url = self.getdata.get_is_url(i) monet = self.getdata.get_is_request(i) is_run = self.getdata.get_is_run(i) header = self.getdata.get_is_header(i) data = self.getdata.get_info_json(i) expect = self.getdata.get_is_get_expect(i) # print(expect) if is_run == True: res = self.runmet.run_main(url,monet,header,data) if self.comm.is_comm(expect,res): self.getdata.get_is_get_result(i,'测试通过') pass_count.append(i) else: self.getdata.get_is_get_result(i,res) fail_count.append(i) print("通过",len(pass_count)) print("失败",len(fail_count))
class DependentData: def __init__(self, case_id): self.case_id = case_id self.run_method = RunMethod() self.opera_excel = OperationExcel() self.data = GetData() # 获取依赖数据的行号 def get_depend_row(self): row_num = self.opera_excel.get_row_num(self.case_id) return row_num # 获取依赖行的数据 def get_depend_line_data(self): row_data = self.opera_excel.get_row_data(self.case_id) return row_data # 执行依赖数据,获取接口返回的数据 def get_dependent_data(self): row_num = self.opera_excel.get_row_num( self.case_id) # 根据依赖的case_id获取依赖数据的行号 request_data = self.data.get_request_data(row_num) # 根据行号获取请求的数据 url = self.data.get_request_url(row_num) headers = self.data.get_is_header(row_num) method = self.data.get_request_method(row_num) res = self.run_method.run_main(method, url, request_data, headers) return json.loads(res) # 根据接口返回的数据,获取依赖字段对应的值 def get_dependent_values(self, row): depend_key = self.data.get_depend_key(row) # 获取依赖的字段key response_data = self.get_dependent_data() # 获取依赖接口返回的数据 json_exe = parse(depend_key) madle = json_exe.find(response_data) return [math.value for math in madle][0]
class DependentData(object): def __init__(self, case_id): self.opexcel = OperationExcel() self.getdata = GetData() self.case_id = case_id self.runmethod = RunMethod() def get_case_line_data(self): row_data = self.opexcel.from_case_id_get_row_data(self.case_id) return row_data def rundependent(self): row_num = self.opexcel.from_case_id_get_row_num(self.case_id) request_data = self.getdata.get_data_for_json(row_num) url = self.getdata.get_url(row_num) method = self.getdata.get_request_method(row_num) header = self.getdata.is_header(row_num) res = self.runmethod.run_main(url, method, request_data, header) return res #在依赖response中查找依赖数据 def get_data_for_key(self, row): depend_data = self.getdata.get_data_depend(row) response_data = self.rundependent() print(depend_data) print("************************") print(response_data) p_depend_data = parse(depend_data) madle = p_depend_data.find(response_data) return [math.value for math in madle][0]
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() #程序执行的 def go_on_run(self): res = None rows_count = self.data.get_case_lines() for i in range(1, rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) method = self.data.get_request_method(i) is_run = self.data.get_is_run(i) data = self.data.get_data_for_json(i) header = self.data.is_header(i) expect = self.data.get_expect_data(i) depend_case = self.data.is_depend(i) res = self.run_method.run_main(method, url, data, header) if depend_case != None: self.depend_data = DependdentData() #获取 响应数据 depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key depend_key = self.data.get_depend_filed(i) if self.com_util.is_contain(expect, res): self.data.write_result(i, "通过") else: self.data.write_result(i, "失败") print(res)
class Order(unittest.TestCase): def setUp(self): self.runmain =RunMethod() @data("0","8","9") def test_GetUserOrders(self,status): url = "https://appapi-test.yaochufa.com/v2/Order/GetUserOrders" data = { "securityKey": "fPpxatGz1GRLdhlWUuCspp8IjXfYSW8qjhSWy4WFd%2Bd6nyIlF4SRFNCW7B6BqOqstWzhyz4TnFczVAFxSnmOvEAEjYqPLmFeefrpNyirU0XgY3DNutfJFDgXSn05Gcw1CwwSeh2AeT6v4SPgvOVUSCmgQ1V03Sim", "machineType":"0", "channel": "AppStore", "imei": "F99067E6-F1EA-4451-8007-15BFDE5372B1", "lang": "app", "machineCode": "F99067E6-F1EA-4451-8007-15BFDE5372B1", "system": "ios", "version":"5.9.1", "offset":"0", "orderStatus":status, "pageSize":"10"} res = self.runmain.run_main("GET", url=url, data=data) #print json.dumps(res,indent=2,ensure_ascii=True) print u"订单数---->>>>%s"%(res["data"]["total"]) items_key = res["data"]["items"] for i in range(len(items_key)): print u"订单ID----->>>%s"%(items_key[i]["orderId"]) print u"订单号----->>>%s"%(items_key[i]["orderNo"]) print u"订单状态----->>>%s"%(items_key[i]["orderStatus"])
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.common_util = CommonUtil() def go_on_run(self): rows_count = self.data.get_case_line() res_arr = [] for i in range(1, rows_count): # print(i) url = self.data.get_request_url(i).strip() is_run = self.data.get_is_run(i) request_method = self.data.get_request_method(i) header = self.data.is_header(i) request_data = self.data.get_json_data(i) expect_data = self.data.get_expect_value(i) res = None if is_run: res = self.run_method.run_main(request_method, url, header, request_data) if self.common_util.is_contain(expect_data, res): print('测试通过') else: print('测试失败') res_arr.append(res) return res_arr
class RunTest: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mai = SendEmail() def go_on_run(self): res = None pass_count = [] fail_count = [] rows_count = self.data.get_case_lines() for i in range(1, rows_count): # is_run = self.data.get_is_run(i) # if is_run: cid = self.data.get_case_id(i) url = self.data.get_request_url(i) method = self.data.get_request_method(i) request_data = self.data.get_request_data(i) # request_data = self.data.get_data_for_json(i) expect = self.data.get_expcet_data(i) header = self.data.is_header(i) # depend_case = self.data.is_depend(i) # if depend_case != None: # self.depend_data = DependdentData(depend_case) #获取的依赖响应数据 # depend_response_data = self.depend_data.get_data_for_key(i) #获取依赖的key # depend_key = self.data.get_depend_field(i) # request_data[depend_key] = depend_response_data # res = self.run_method.run_main(method, url, request_data) # op_header = OperationHeader(res) # op_header.write_cookie() if header == None: header = OperationHeader().get_header() # elif header == 'yes': # op_json = OperetionJson('../dataconfig/cookie.json') # cookie = op_json.get_data('apsid') # cookies = { # 'apsid':cookie # } # res = self.run_method.run_main(method, url, request_data,cookies) res = str(self.run_method.run_main(method, url, request_data, header).status_code) if self.com_util.is_equal_str(expect, res) == 1: # print(f'第{i+1}行' + '测试通过') # print(expect) # print(res) self.data.write_result(i, 'pass') # pass_count.append(i) else: self.data.write_result(i, 'fail' + res) # fail_count.append(i) print(cid + '测试不通过')
def run_dependent(self): run_method = RunMethod() row_num = self.opera_excel.get_row_num(self.case_id) request_data = self.data.get_data_for_json(row_num) #header = self.data.is_header(row_num) method = self.data.get_request_method(row_num) url = self.data.get_request_url(row_num) res = run_method.run_main(method, url, request_data) return json.loads(res)
class RunTest: def __init__(self): self.run = RunMethod() self.data = GetData() self.com_util = CommonUtil() self.send_mail = SendEmail() self.log = UserLog() self.logger = UserLog.get_log() # 程序执行的主入口 def go_on_run(self): res = None pass_count = [] fail_count = [] rows_count = self.data.get_case_lines() for i in range(1,rows_count): is_run = self.data.get_is_run(i) if is_run: url = self.data.get_request_url(i) # if i == 7: # print("已经成年") # url = 'http://192.168.2.81:10003/shop/goods/new-list' method = self.data.get_request_method(i) is_run = self.data.get_is_run(i) data = self.data.get_data_for_json(i) expect = self.data.get_expcet_data(i) # expect = self.data.get_expcet_data_for_mysql(i) # data = {'pageNum': 1, 'pageSize': 10} header = self.data.is_header(i) depend_case = self.data.is_depend(i) # header = {'Content-Type': 'application/json'} if depend_case != None: self.depend_data = DependentData(depend_case) # 获取的依赖响应数据 depend_response_data = self.depend_data.get_data_for_key(i) print("this is dependResponseData = ",depend_response_data) # 获取依赖的key depend_key = self.data.get_depend_fileld(i) print("*************this is depend_key = ",depend_key) # 根据获取的依赖key,将depend_kay更新成depend_response_data data[depend_key] = depend_response_data print("*************this is data[depend_key]",data[depend_key]) res = self.run.run_main(method, url, data, header) if self.com_util.is_contain(expect,res): self.data.write_result(i,'Pass') pass_count.append(i) else: self.data.write_result(i,res) fail_count.append(i) else: self.data.write_result(i, 'N/A') continue # print(res) # print(len(pass_count)) # print(len(fail_count)) self.send_mail.send_main(pass_count,fail_count)
class RunText: def __init__(self): self.run_method = RunMethod() self.data = GetData() self.common_util = CommonUtil() self.sendmail = SendEmail() # 执行程序的主入口 def go_on_run(self, pr=None): res = None pass_count = [] fail_count = [] row_count = self.data.get_case_lines() for i in range(1, row_count): url = self.data.get_request_url(i) method = self.data.get_request_method(i) data = self.data.get_data_for_json(i) is_run = self.data.get_is_run(i) header = self.data.get_data_header_json(i) expect = self.data.get_expect_data(i) depend_case = self.data.is_depend(i) # if depend_case != None: # self.depend_data = DependdentData(depend_case) # #获取相应数据的依赖 # depend_response_data = self.data.get_depend_key(i) # #获取依赖的key # depend_key = self.data.get_depend_field(i) # data[depend_key] = depend_response_data # res = self.run_method.run_main(method,url,header,data) # print res''' '''if header == 'write': res = self.run_method.run_main(method, url, request_data) op_header = OperationHeader(res) op_header.write_cookie() elif header == 'yes': op_json = OperetionJson('../dataconfig/cookie.json') cookie = op_json.get_data('apsid') cookies = { 'apsid': cookie } res = self.run_method.run_main(method, url, request_data, cookies) else: res = self.run_method.run_main(method, url, request_data)''' if is_run: res = self.run_method.run_main(method, url, header, data) if self.common_util.is_contain(expect, res): # print "测试通过" print self.data.write_value(i, "pass") pass_count.append(i) else: # print "测试失败" print self.data.write_value(i, res) fail_count.append(i) self.sendmail.send_main(pass_count, fail_count)
def run_dependent(self): run_method = RunMethod() row_num = self.opera_excel.get_row_num(self.case_id) request_data = self.data.get_data_for_json(row_num) # header = self.data.is_header(row_num) method = self.data.get_request_method(row_num) url = self.data.get_request_url(row_num) res = run_method.run_main(method, url, request_data, {'Content-Type': 'application/x-www-form-urlencoded'}) return json.loads(res)
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