class DependdentData: # 通过caseID获取其整行数据 def __init__(self, case_id): self.case_id = case_id self.opera_excel = OperationExcel() self.data = GetData() # 通过case_id 去获取该case_id的整行数据 def get_case_line_data(self, case_id): rows_data = self.opera_excel.get_rows_data(self.case_id) return rows_data # 执行依赖测试,获取结果集 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) # 根据依赖的key去获取执行依赖测试case的响应,然后找到需要数据! def get_data_for_key(self, row): # 获取依赖的值 depend_data = self.data.get_depend_key(row) response_data = self.run_dependent() print("----------》") print(type(depend_data)) print(depend_data) print(type(response_data)) print(response_data) # 需要jsonpath_rw,解析为json格式 json_exe = parse(depend_data) # 在相应数数据里面去寻找指定的key对应的值 madle = json_exe.find(response_data) # 相当于for i in madle return [math.value for math in madle][0]
class DependentData: def __init__(self, case_id): self.excel = OperationExcel() self.data = GetSheetData() self.run_method = RunMethod() self.case_id = case_id def get_case_line_data(self, case_id): row_data = self.excel.get_row_data(case_id) return row_data def run_dependent(self): row = self.excel.get_row_num(self.case_id) url = self.data.get_url(row) method = self.data.get_method(row) header = self.data.get_header(row) data = self.data.get_request_data(row) res = self.run_method.main(method, url, header, data) return res def get_depend_key(self, row): depend_data = self.data.get_depend_key(row) response_data = self.run_dependent()
def __init__(self): self.excel = OperationExcel() self.data_config = global_var() self.read = ReadIni(conftest.env_dir) self.op_json = OperationJson()
class GetSheetData: def __init__(self): self.excel = OperationExcel() self.data_config = global_var() self.read = ReadIni(conftest.env_dir) self.op_json = OperationJson() """获取case行数""" def get_case_lines(self): lines = self.excel.get_rows() return lines """是否运行""" def is_run(self, row): col = self.data_config.get_col_run() run_model = self.excel.get_cell_value(row, col) flag = None if run_model == 'yes': flag = True else: flag = False return flag """获取case id""" def get_id(self, row): col = self.data_config.get_col_id() case_id = self.excel.get_cell_value(row, col) return case_id """获取api,拼接接口地址""" def get_url(self, row): col = self.data_config.get_col_api() api = self.excel.get_cell_value(row, col) url = self.read.get_value('base_url', 'api') + api return url """获取请求方法""" def get_method(self, row): col = self.data_config.get_col_method() method = self.excel.get_cell_value(row, col) return method """获取是否有header,是则从json数据中获取headers""" def get_header(self, row): col = self.data_config.get_col_header() header = self.excel.get_cell_value(row, col) header_data = self.op_json.get_data('headers') if header == 'yes': return header_data else: return None """获取依赖的case id""" def get_depend_id(self, row): col = self.data_config.get_col_depend_id() depend_id = self.excel.get_cell_value(row, col) if depend_id == '': return None else: return depend_id """获取依赖的数据""" def get_depend_data(self, row): col = self.data_config.get_col_depend_data() depend_data = self.excel.get_cell_value(row, col) if depend_data == '': return None else: return depend_data """获取依赖数据的字段""" def get_depend_key(self, row): col = self.data_config.get_col_depend_key() depend_key = self.excel.get_cell_value(row, col) if depend_key == '': return None else: return depend_key """根据命名的请求json名,获取请求数据""" def get_request_data(self, row): col = self.data_config.get_col_request_data() request_data_key = self.excel.get_cell_value(row, col) request_data = self.op_json.get_data(request_data_key) if request_data == '': return None else: return request_data """根据sql语句,获取期望值""" def get_expect(self, row): col = self.data_config.get_col_expect() expect = self.excel.get_cell_value(row, col) return expect """把结果写入实际结果中""" def write_result(self, row, result,): col = self.data_config.get_col_result() self.excel.write_data(row, col, result)
def __init__(self, case_id): self.excel = OperationExcel() self.data = GetSheetData() self.run_method = RunMethod() self.case_id = case_id
def __init__(self): self.opera_excel = OperationExcel()
class GetData: """docstring for GetData""" def __init__(self): self.opera_excel = OperationExcel() # 去获取excel行数,就是case的数量 def get_case_lines(self): return self.opera_excel.get_lines() # 获取是否执行 def get_is_run(self, row): col = int(data_config.get_run()) run_model = self.opera_excel.get_cell_vaule(row, col) flag = None if run_model.lower() == 'yes': flag = True else: flag = False return flag # 是否携带header def is_header(self, row): col = int(data_config.get_header()) header = self.opera_excel.get_cell_vaule(row, col) if header == 'yes': return data_config.get_header_value() else: return None # 获取请求方式 def get_request_method(self, row): col = int(data_config.get_run_way()) requests_method = self.opera_excel.get_cell_vaule(row, col) return requests_method # 获取url def get_request_url(self, row): col = int(data_config.get_url()) url = self.opera_excel.get_cell_vaule(row, col) return url # 获取请求数据 def get_request_data(self, row): col = int(data_config.get_data()) data = self.opera_excel.get_cell_vaule(row, col) if data == '': return None else: return data # 通过获取关键字拿到data数据 # 获取json配置中的值 def get_data_for_json(self, row): opera_json = OperationJson() request_data = opera_json.get_data(self.get_request_data(row)) return request_data # 获取预期结果 def get_expcet_data(self, row): col = int(data_config.get_expect()) expcet = self.opera_excel.get_cell_vaule(row, col) if expcet == '': return None else: return expcet # 封装写入数据的方法 def write_result(self, row, value): # 获取实际结果的列 col = int(data_config.get_result()) self.opera_excel.write_value(row, col, value) # 获取依赖数据的key def get_depend_key(self, row): col = int(data_config.get_data_depend()) depent_key = self.opera_excel.get_cell_vaule(row, col) if depent_key == "": return None else: return depent_key # 判断是否有case依赖 def is_depend(self, row): col = int(data_config.get_case_depend()) depend_case_id = self.opera_excel.get_cell_vaule(row, col) if depend_case_id == "": return None else: return depend_case_id # 获取数据依赖字段 def get_depend_field(self, row): col = int(data_config.get_field_depend()) data = self.opera_excel.get_cell_vaule(row, col) if data == "": return None else: return data
def __init__(self): self.opera_excel = OperationExcel() self.xls_config = XlsConfiger()
class GetData: def __init__(self): self.opera_excel = OperationExcel() self.xls_config = XlsConfiger() #获取excel行数(case个数) def get_lines(self): return self.opera_excel.get_lines() #获取是否执行 def get_isrun(self, row): flag = None col = int(self.xls_config.col_isrun()) run_model = self.opera_excel.get_cell_value(row, col) if run_model == 'yes': flag = True else: flag = False return flag #获取项目名 def get_proname(self, row): col = int(self.xls_config.col_name()) name = self.opera_excel.get_cell_value(row, col) return name #获取本地目录 def get_localdir(self, row): col = int(self.xls_config.col_localdir()) localdir = self.opera_excel.get_cell_value(row, col) return localdir #获取ftp目录 def get_ftpdir(self, row): col = int(self.xls_config.col_ftpdir()) ftpdir = self.opera_excel.get_cell_value(row, col) return ftpdir #获取remote上war包的目录 def get_remote_package(self, row): col = int(self.xls_config.col_remote_package()) remote_package = self.opera_excel.get_cell_value(row, col) return remote_package #获取remote上config文件的目录 def get_remote_config(self, row): col = int(self.xls_config.col_remote_config()) remote_config = self.opera_excel.get_cell_value(row, col) return remote_config #获取tomcat目录 def get_tomcatdir(self, row): col = int(self.xls_config.col_tomcatdir()) tomcatdir = self.opera_excel.get_cell_value(row, col) return tomcatdir #获取war包文件名 def get_warname(self, row): col = int(self.xls_config.col_warname()) warname = self.opera_excel.get_cell_value(row, col) return warname #获取配置文件名 def get_configname(self, row): col = int(self.xls_config.col_configname()) configname = self.opera_excel.get_cell_value(row, col) return configname #获取remoteIP def get_remoteIP(self, row): col = int(self.xls_config.col_remoteIP()) remoteIP = self.opera_excel.get_cell_value(row, col) return remoteIP #获取remoteIP def get_testurl(self, row): col = int(self.xls_config.col_testurl()) testurl = self.opera_excel.get_cell_value(row, col) return testurl
def __init__(self, case_id): self.case_id = case_id self.opera_excel = OperationExcel() self.data = GetData()