def run_case(self): rows = excel_data.get_rows() for i in range(rows): # i是从0开始的,excel中第一行内容的行号是i=2 data = excel_data.get_rows_value(i + 2) #['imooc_001', '登录', 'yes', 'create_user', '/login/', 'post', '{"username":"******"}', 'yes', 'message', None] is_run = data[2] except_method = data[10] except_result = data[11] if is_run == "yes": url = data[5] method = data[6] data1 = data[7] res = request.run_main(method, url, data1) #int和str无法比较,需要强转一下 code = str(res['errorCode']) desc = res['errorDesc'] #如果预期结果方式为mec:message+errorcode if except_method == "mec": config_message = handle_result(url, code) if desc == config_message: excel_data.excel_write_data(i + 2, 12, "通过") print("case通过") else: excel_data.excel_write_data(i + 2, 12, "失败") excel_data.excel_write_data(i + 2, 13, json.dumps(res)) print("case失败") if except_method == "errorcode": if except_result == code: excel_data.excel_write_data(i + 2, 12, "通过") print("case通过") else: excel_data.excel_write_data(i + 2, 12, "失败") excel_data.excel_write_data(i + 2, 13, json.dumps(res)) print("case失败") # 如果预期结果方式为json格式 if except_method == "json": if code == 1000: status_str = "sucess" else: status_str = "error" except_result_json = get_result_json(url, status_str) # print(res,'-------',except_result_json) result = handle_result_json(res, except_result_json) if result: excel_data.excel_write_data(i + 2, 12, "通过") print("case通过") else: excel_data.excel_write_data(i + 2, 12, "失败") excel_data.excel_write_data(i + 2, 13, json.dumps(res)) print("case失败")
def test_main_case(self, data): cookie = None get_cookie = None header = None depend_data = None is_run = data[2] case_id = data[0] i = excel_data.get_rows_number(case_id) if is_run == 'yes': is_depend = data[3] data1 = json.loads(data[7]) try: if is_depend: #获取依赖数据 depend_key = data[4] depend_data = get_data(is_depend) #print(depend_data) data1[depend_key] = depend_data method = data[6] url = data[5] is_header = data[9] expect_method = data[10] expect_result = data[11] cookie_method = data[8] if cookie_method == 'yes': cookie = get_cookie_value('app') if cookie_method == 'write': ''' 必须是获取到cookie ''' get_cookie = {"is_cookie": "app"} if is_header == 'yes': header = get_header() res = request.run_main(method, url, data1, cookie, get_cookie, header) #print(code) code = str(res['errorCode']) #print(res['errorCode']) message = res['errorDesc'] #message+errorcode if expect_method == 'mec': config_message = handle_result(url, code) ''' if message == config_message: excel_data.excel_write_data(i,13,"通过") else: excel_data.excel_write_data(i,13,"失败") excel_data.excel_write_data(i,14,json.dumps(res)) ''' try: self.assertEqual(message, config_message) excel_data.excel_write_data(i, 13, "通过") except Exception: excel_data.excel_write_data(i, 13, "失败") excel_data.excel_write_data(i, 14, json.dumps(res)) raise Exception if expect_method == 'errorcode': ''' if expect_result == code: excel_data.excel_write_data(i,13,"通过") else: excel_data.excel_write_data(i,13,"失败") excel_data.excel_write_data(i,14,json.dumps(res)) ''' try: self.assertEqual(expect_result, code) excel_data.excel_write_data(i, 13, "通过") except Exception as e: excel_data.excel_write_data(i, 13, "失败") excel_data.excel_write_data(i, 14, json.dumps(res)) raise e if expect_method == 'json': if code == 1000: status_str = 'sucess' else: status_str = 'error' expect_result = get_result_json(url, status_str) result = handle_result_json(res, expect_result) ''' if result: excel_data.excel_write_data(i,13,"通过") else: excel_data.excel_write_data(i,13,"失败") excel_data.excel_write_data(i,14,json.dumps(res)) ''' try: self.assertTrue(result) excel_data.excel_write_data(i, 13, "通过") except Exception as e: excel_data.excel_write_data(i, 13, "失败") excel_data.excel_write_data(i, 14, json.dumps(res)) raise e except Exception as e: excel_data.excel_write_data(i, 13, "失败") raise e
def test_mainindex(self, data): """执行case主流程""" case_id = data[0] i = excel_data.get_rows_number(case_id) # 行号 header = None get_token = None is_run = data[2] if is_run == "yes": data1 = json.loads(data[7]) is_depend = data[3] try: if is_depend: """获取依赖数据""" depend_key = data[4] try: depend_value = get_data(is_depend) except: # 依赖接口失败启动 mock函数获取依赖数据 depend_value = mock_depend() # mock依赖 data1[depend_key] = depend_value url = data[5] method = data[6] expected_method = data[10] token_method = data[9] if token_method == 'yes': """携带token""" data2 = get_token_value("web") header = data2 if token_method == "write": """写入token""" get_token = {"is_token": "web"} res = BaseRequest.run(method, url, data1, get_token, header) code = res['meta']["status"] message = res['meta']["msg"] if expected_method == "mec": configmes = handle_result_msg(url, code) try: self.assertEqual(configmes, message) excel_data.excel_write_data(i, 13, "通过") except AssertionError as e: excel_data.excel_write_data(i, 13, "失败", "red") raise e if expected_method == "json": # expected_method自定义校验方法 if code == 200 or code == 201: status_str = "success" else: status_str = "error" except_res = get_result_json(url, status_str) result = handle_result_json(res, except_res) try: self.assertTrue(result) excel_data.excel_write_data(i, 13, "通过") except AssertionError as e: excel_data.excel_write_data(i, 13, "失败", "red") raise e except Exception as e: raise e finally: excel_data.excel_write_data( i, 14, json.dumps(res, indent=2, ensure_ascii=False))
def testrun_case(self, data): #rows = excel_data.get_rows() #for i in range(rows): cookie = None get_cookie = None header = None #data = excel_data.get_rows_value(i+2) is_run = data[2] if is_run == 'yes': method = data[5] url = data[4] data1 = data[6] is_header = data[8] excepect_method = data[9] excepect_result = data[10] codition = data[3] if codition: pass cookie_method = data[7] if cookie_method == 'yes': cookie = get_cookie_value('app') if cookie_method == 'write': ''' 必须是获取到cookie ''' get_cookie = {"is_cookie": "app"} if is_header == 'yes': header = get_header() res = request.run_main(method, url, data1, cookie, get_cookie, header) #print(res) code = str(res['errorCode']) message = res['errorDesc'] if excepect_method == 'mec': config_message = handle_result(url, code) self.assertEqual(message, config_message) ''' if message == config_message: excel_data.excel_write_data(i+2,12,"通过") else: excel_data.excel_write_data(i+2,12,"失败") excel_data.excel_write_data(i+2,13,json.dumps(res)) ''' if excepect_method == 'errorcode': self.assertEqual(excepect_result, code) ''' if excepect_result == code: excel_data.excel_write_data(i+2,12,"通过") else: excel_data.excel_write_data(i+2,12,"失败") excel_data.excel_write_data(i+2,13,json.dumps(res)) ''' if excepect_method == 'json': if code == 1000: status_str = 'sucess' else: status_str = 'error' excepect_result = get_result_json(url, status_str) result = handle_result_json(res, excepect_result) self.assertTrue(result) '''
def run_case(self): rows = excel_data.get_rows() for i in range(rows): cookie=None get_cookie = None header = None depend_data = None data = excel_data.get_rows_value(i+2) is_run = data[2] if is_run == 'yes': is_depend = data[3] data1 = json.loads(data[7]) if is_depend: ''' 获取依赖数据 ''' depend_key = data[4] depend_data = get_data(is_depend) #print(depend_data) data1[depend_key] = depend_data method = data[6] url = data[5] is_header = data[9] excepect_method = data[10] excepect_result = data[11] cookie_method = data[8] if cookie_method == 'yes': cookie = get_cookie_value('app') if cookie_method == 'write': ''' 必须是获取到cookie ''' get_cookie={"is_cookie":"app"} if is_header == 'yes': header = get_header() res = request.run_main(method,url,data1,cookie,get_cookie,header) #print(res) code = str(res['errorCode']) message = res['errorDesc'] if excepect_method == 'mec': config_message = handle_result(url,code) if message == config_message: excel_data.excel_write_data(i+2,13,"通过") else: excel_data.excel_write_data(i+2,13,"失败") excel_data.excel_write_data(i+2,14,json.dumps(res)) if excepect_method == 'errorcode': if excepect_result == code: excel_data.excel_write_data(i+2,14,"通过") else: excel_data.excel_write_data(i+2,13,"失败") excel_data.excel_write_data(i+2,14,json.dumps(res)) if excepect_method == 'json': if code == 1000: status_str='sucess' else: status_str='error' excepect_result = get_result_json(url,status_str) result = handle_result_json(res,excepect_result) if result: excel_data.excel_write_data(i+2,13,"通过") else: excel_data.excel_write_data(i+2,13,"失败") excel_data.excel_write_data(i+2,14,json.dumps(res))
def run_case(self): row = excel_data.get_row() for i in range(row): cookie = None get_cookie = None data = excel_data.get_row_value(i + 2) is_run = data[2] if is_run == 'yes': method = data[5] url = data[4] data1 = data[6] header = data[13] exthed_method = data[8] exthed_result = data[9] cookie_mother = data[7] if cookie_mother == "yes": cookie = get_cookid_valus("app") if cookie_mother == "write": get_cookie = {"is_cookie": "app"} if header == "yes": is_header = get_header() res = request.run_main(method, url, data1, cookie, get_cookie, is_header) if exthed_method == 'mec': code = "1003" # message=res['errorCodeMes'] message = "用户名错误" config_message = handle_result(url, code) if message == config_message: excel_data.excel_write_Data(i + 2, 11, "通过") print("测试通过") else: excel_data.excel_write_Data(i + 2, 11, "失败") excel_data.excel_write_Data(i + 2, 12, json.dumps(res)) print("测试失败") if exthed_method == 'errorcode': code = "1006" if exthed_result == code: excel_data.excel_write_Data(i + 2, 11, "通过") print("测试通过") else: excel_data.excel_write_Data(i + 2, 11, "失败") excel_data.excel_write_Data(i + 2, 12, json.dumps(res)) print("测试失败") if exthed_method == "json": code = res['errorCode'] # print("code=====",code) if code == "10067": status = "error" else: status = "succes" excute_result = get_result_json(url, status) result = handle_result_json(res, excute_result) if result: excel_data.excel_write_Data(i + 2, 11, "通过") else: excel_data.excel_write_Data(i + 2, 11, "失败") excel_data.excel_write_Data(i + 2, 12, json.dumps(res))