def get_data_for_json(self, row): try: opera_json = OperationJson() request_data = opera_json.get_data(self.get_request_data(row)) return request_data except Exception as e: logging.info("错误为:", e)
def get_header_for_json(self, row): if self.get_req_header(row) != None: for_json = OperationJson(filename="../dataconfig/header.json") req_header = for_json.get_data(self.get_req_header(row)) return req_header else: return None
def get_data_for_json(self, row): ecl_data = self.get_request_data(row) if self.get_request_data(row) != None: datas = ecl_data.split(":") if len(datas) > 1: for_json = OperationJson("../dataconfig/" + datas[0] + ".json") req_data = for_json.get_data(datas[1]) return req_data else: print("请求数据格式不对!格式必须为 filename:jsonname") return None else: return None
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 GetData(object): def __init__(self, filename=None, sheet_id=None): self.opera_excel = OperationExcel(filename, sheet_id) def get_case_lines(self): return self.opera_excel.get_lines() def get_is_run(self, row): flag = None col = data_config.global_val.get_run() run_model = self.opera_excel.get_cell_value(row, int(col)) if run_model == 'yes': flag = True else: flag = False return flag def is_cookie(self, row): col = data_config.global_val.get_cookie() cookie = self.opera_excel.get_cell_value(row, int(col)) return cookie def is_header(self, row): col = data_config.global_val.get_header() header = self.opera_excel.get_cell_value(row, int(col)) if header == 'yes': return data_config.global_val.get_header_value() else: return None def get_request_method(self, row): col = data_config.global_val.get_request_way() request_method = self.opera_excel.get_cell_value(row, int(col)) return request_method def get_url(self, row): col = data_config.global_val.get_url() url = self.opera_excel.get_cell_value(row, int(col)) return url def get_request_data(self, row): col = data_config.global_val.get_data() data = self.opera_excel.get_cell_value(row, int(col)) if data == '': return None else: return data def get_data_for_json(self, row): self.opera_json = OperationJson() data_json = self.opera_json.get_data(self.get_request_data(row)) return data_json def get_expect(self, row): col = data_config.global_val.get_expect() expect = self.opera_excel.get_cell_value(row, int(col)) if expect == '': return None else: return expect def write_result(self, row, value): col = data_config.global_val.get_result() self.opera_excel.write_value(row, int(col), value) def get_data_depend(self, row): col = data_config.global_val.get_data_depend() data_depend = self.opera_excel.get_cell_value(row, int(col)) if data_depend == "": return None else: return data_depend def is_depend(self, row): col = data_config.global_val.get_case_depend() case_depend = self.opera_excel.get_cell_value(row, int(col)) if case_depend is not None: return case_depend else: return None def get_field_depend(self, row): col = data_config.global_val.get_field_depend() field_depend = self.opera_excel.get_cell_value(row, int(col)) if field_depend is not None: return field_depend else: return None