def __init__(self): self.getdata = GetData() self.run_method = RunMethod() self.oper_excel = OperationExcel() self.common_util = CommonUtil() self.oper_mysql = OperationMysql() self.sen_mail = SendEmail()
class GetData: def __init__(self): self.opera_exl = OperationExcel() self.dataconfig = DataConfig() def get_commodity(self, row): col = int(self.dataconfig.get_commodity_id()) return self.opera_exl.get_cell_values(row, col) def get_price(self, row): col = int(self.dataconfig.get_price_id()) return int(self.opera_exl.get_cell_values(row, col))
def add_commodity_info(self, flag): for index, i in enumerate(range(1, self.opera_exl.get_rows())): print(index, self.opera_exl.get_row_values(i)) add_commodity_name = input('请输入商品名称:') if add_commodity_name == 'q': print('已退出') flag = False add_commodity_price = input('请输入商品金额:') if add_commodity_price.isdigit(): add_commodity_price = int(add_commodity_price) self.opera_exl.write_data(self.opera_exl.get_rows(), 0, add_commodity_name) self.opera_exl.write_data(self.opera_exl.get_rows(), 1, add_commodity_price) self.opera_exl = OperationExcel() elif add_commodity_price == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') return flag
class 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): #获取是否执行 flag = None col = data_config.get_run() run_model = self.opera_excel.get_cell_value(col) if run_model == 'yes': Flag = True else: flag = False return False def is_header(self, row): #是否携带header col = data_config.get_headr() header = self.opera_excel.get_cell_value(col) if header == 'yes': return data_config.get_header_value() else: return None def get_request_method(self, row): #获取请求方式 col = data_config.get_request_way() request_method = self.opera_excel.get_cell_value(col) return request_method def get_request_url(self, row): #获取url col = data_config.get_url() request_url = self.opera_excel.get_cell_value(col) return request_url def get_request_data(self, rpw): #获取请求数据 col = data_config.get_data() data = self.opera_excel.get_cell_value(col) if data == '': return None return data def get_data_for_json(self, row): #通过关键字拿到数据 opera_json = OperetionJson() request_data = opera_json.get_data(self.get_request_data(row)) return request_data def get_expect_data(self, row): #获取预期结果 col = data_config.get_expext() expect = self.opera_excel.get_cell_value(row, col) if expect == '': return None return expect
def update_commodity_info(self, flag): for index, i in enumerate(range(1, self.opera_exl.get_rows())): print(index, self.opera_exl.get_row_values(i)) choose_id = input('请输入商品ID号:') if choose_id.isdigit(): choose_id = int(choose_id) + 1 print(self.opera_exl.get_row_values(choose_id)) updata_price = input('请输入修改后的金额:') if updata_price.isdigit(): updata_price = int(updata_price) self.opera_exl.write_data(choose_id, 1, updata_price) self.opera_exl = OperationExcel() print('修改成功', self.opera_exl.get_row_values(choose_id)) elif updata_price == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') elif choose_id == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') return flag
class Dependent: def __init__(self,case_id): self.case_id = case_id self.oper_excel = OperationExcel() self.data = GetData() self.run = RunMethod() def dependent_run(self): #运行依赖的用例 case_row = self.oper_excel.get_case_row(self.case_id) method = self.data.get_request_way_value(case_row) url = self.data.get_url_value(case_row) data = self.data.get_data_for_json(case_row) header = self.data.get_is_header_value(case_row) res = self.run.run_method(method,url,data,header) return res def dependent_key_values(self,row): #获取需要依赖键的值 response_data = self.dependent_run() #运行依赖用例,获取其返回值 requests_data = self.data.get_response_dependent_value(row) #获取返回值里的某个键的值 response_data = json.loads(response_data) #将json数据转换成python可识别的对象 json_exe = parse(requests_data) #定义一个规则,以json格式去格式化接口返回的数据 mable = json_exe.find(response_data) #按照规则来查找整个结果集 return [math.value for math in mable] #官方写法,从结果集查找某部分数据
def __init__(self): self.opera_excel = OperationExcel() self.gol_bar = GlobalBar()
class GetData: def __init__(self): self.opera_excel = OperationExcel() self.gol_bar = GlobalBar() def get_case_lines(self): return self.opera_excel.get_lines() # 判断是否执行 def get_is_run(self, row): col = int(self.gol_bar.get_run()) run_model = self.opera_excel.get_cell_value(row, col) if run_model == "yes": flag = True else: flag = False return flag # 是否携带header def is_header(self, row): col = int(self.gol_bar.get_header()) header = self.opera_excel.get_cell_value(row, col) if header == "yes": col1 = int(self.gol_bar.get_header_value()) header_value = self.opera_excel.get_cell_value(row, col1) return header_value else: return None # 获取token def get_token(self, row): col = int(self.gol_bar.get_token()) token = self.opera_excel.get_cell_value(row, col) return token # 获取请求方式 def get_request_method(self, row): col = int(self.gol_bar.get_requset_way()) requset_method = self.opera_excel.get_cell_value(row, col) return requset_method # 获取url def get_request_url(self, row): col = int(self.gol_bar.get_url()) url = self.opera_excel.get_cell_value(row, col) return url # 获取请求数据 def get_request_data(self, row): col = int(self.gol_bar.get_data()) data = self.opera_excel.get_cell_value(row, col) return data # 通过关键字获取json数据 def get_data_for_json(self, row): opera_json = OperationJson() data = self.get_request_data(row) if data == "none": return None else: request_data = opera_json.get_data(self.get_request_data(row)) return request_data # 获取预期结果 def get_expect_data(self, row): col = int(self.gol_bar.get_expect()) expect = self.opera_excel.get_cell_value(row, col) if expect == "none": return None return expect def write_result(self, row, value): col = int(self.gol_bar.get_result()) self.opera_excel.write_value(row, col, value) # 获取依赖的case def get_depend_key(self, row): col = int(self.gol_bar.get_data_depend()) depent_key = self.opera_excel.get_cell_value(row, col) if depent_key == "": return None else: return depent_key # 判断是否有case依赖 def is_depend(self, row): col = int(self.gol_bar.get_case_depend()) depend_case_id = self.opera_excel.get_cell_value(row, col) if depend_case_id == "none": return None else: return depend_case_id # 从返回值中获取接口依赖字段的结果 def get_depend_field(self, row): col = int(self.gol_bar.get_field_depend()) data = self.opera_excel.get_cell_value(row, col) if data == "none": return None else: return data
def __init__(self): self.opera_exl = OperationExcel()
class Seller: def __init__(self): self.opera_exl = OperationExcel() def update_commodity_info(self, flag): for index, i in enumerate(range(1, self.opera_exl.get_rows())): print(index, self.opera_exl.get_row_values(i)) choose_id = input('请输入商品ID号:') if choose_id.isdigit(): choose_id = int(choose_id) + 1 print(self.opera_exl.get_row_values(choose_id)) updata_price = input('请输入修改后的金额:') if updata_price.isdigit(): updata_price = int(updata_price) self.opera_exl.write_data(choose_id, 1, updata_price) self.opera_exl = OperationExcel() print('修改成功', self.opera_exl.get_row_values(choose_id)) elif updata_price == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') elif choose_id == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') return flag def add_commodity_info(self, flag): for index, i in enumerate(range(1, self.opera_exl.get_rows())): print(index, self.opera_exl.get_row_values(i)) add_commodity_name = input('请输入商品名称:') if add_commodity_name == 'q': print('已退出') flag = False add_commodity_price = input('请输入商品金额:') if add_commodity_price.isdigit(): add_commodity_price = int(add_commodity_price) self.opera_exl.write_data(self.opera_exl.get_rows(), 0, add_commodity_name) self.opera_exl.write_data(self.opera_exl.get_rows(), 1, add_commodity_price) self.opera_exl = OperationExcel() elif add_commodity_price == 'q': print('已退出') flag = False else: print('输入错误,请重新输入:') return flag def choose_do(self): flag = True while flag: choose_do = input('请输入要做的操作:(u/a)') if choose_do == 'u': flag = self.update_commodity_info(flag) elif choose_do == 'a': flag = self.add_commodity_info(flag) elif choose_do == 'q': print('已退出') flag = False break else: print('输入错误,请重新输入:') return flag
def __init__(self,case_id): self.case_id = case_id self.oper_excel = OperationExcel() self.data = GetData() self.run = RunMethod()
def __init__(self): self.opera_excel = OperationExcel() self.data = GetData()
def __init__(self): self.opera_exl = OperationExcel() self.dataconfig = DataConfig()
def __init__(self): self.opera_excel = OperationExcel() self.flag = None self.opera_json = OperationJson()
class GetData: def __init__(self): self.opera_excel = OperationExcel() self.flag = None self.opera_json = OperationJson() # 用于获取excel行数,就是我们的case个数 def get_case_lines(self): return self.opera_excel.get_lines() # 获取是否执行 def get_is_run(self, row): # flag = None 试试在构造函数里新建flag变量 col = int(data_config.get_run()) run_model = self.opera_excel.get_cell_value(row, col) if run_model == '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_value(row, col) if header == 'yes': return 'header' else: return None # 获取请求方式 def get_request_method(self, row): col = int(data_config.get_request_way()) request_method = self.opera_excel.get_cell_value(row, col) return request_method # 获取URL def get_request_url(self, row): col = int(data_config.get_url()) url = self.opera_excel.get_cell_value(row, col) return url # 获取请求数据 def get_request_data(self, row): col = int(data_config.get_data()) data = self.opera_excel.get_cell_value(row, col) if data == '': return '没有data' return data # 通过获取关键字拿到data数据 def get_data_for_json(self, row): opera_json = OperationJson() id = self.get_request_data(row) request_data = opera_json.get_data(id) return request_data # 获取预期结果 def get_expect_data(self, row): col = int(data_config.get_expect()) expect = self.opera_excel.get_cell_value(row, col) if expect == '': return None return expect
class RunTest: def __init__(self): self.getdata = GetData() self.run_method = RunMethod() self.oper_excel = OperationExcel() self.common_util = CommonUtil() self.oper_mysql = OperationMysql() self.sen_mail = SendEmail() def run_test(self): id = 0 pass_count = [] fail_count = [] row = self.oper_excel.get_data_lines() for id in range(1, row): is_run = self.getdata.get_is_run_value(id) if is_run: url = self.getdata.get_url_value(id) method = self.getdata.get_request_way_value(id) is_header = self.getdata.get_is_header_value(id) case_dependent = self.getdata.get_case_dependent_value(id) response_dependent = self.getdata.get_response_dependent_value( id) data_dependent = self.getdata.get_data_dependent_value(id) data = self.getdata.get_data_for_json(id) #expect = self.getdata.get_expect_from_mysql(id) expect = self.getdata.get_expect_value(id) result = self.getdata.get_result_value(id) if case_dependent != None: self.dependent = Dependent(case_dependent) dependent_data = self.dependent.dependent_key_values(id) data[data_dependent] = dependent_data #print(type(expect)) if is_header == 'write': res = self.run_method.run_method(method, url, data) #print(res['data']['url']) res = json.loads(res) #print(type(res)) oper_header = OperationHeader(res) oper_header.write_cookie() elif is_header == 'yes': oper_json = OperationJson( 'D:\pycharm\python2\\testdjango\demo\detaconfig\cookie.json' ) is_header = oper_json.get_json_data('apsid') cookie = {'apsid': is_header} res = self.run_method.run_method(method, url, data, cookie) else: res = self.run_method.run_method(method, url, data) #print(id,res,type(res),type(expect)) #print(expect,res) #self.sen_mail.sen_main(pass_count,fail_count) if self.common_util.is_contain(expect, res): self.getdata.write_data(id, 'pass') pass_count.append(id) print('pass') else: self.getdata.write_data(id, 'fail') fail_count.append(id) print('fail') print(len(pass_count)) self.sen_mail.sen_main(pass_count, fail_count)