class OperationCookie(): def __init__(self, cookie_path=None): if cookie_path: self.cookie_path = cookie_path else: self.cookie_path = "../data/cookie.json" self.op_json = OperationJson(file_name=self.cookie_path) # self.op_json = op_json.data def write_cookie(self, value): self.op_json.write_data(value) def get_cookie(self, key): ck = self.op_json.get_value(key) return ck def get_cookie_file_data(self): ck_file = self.op_json.get_all_value() return ck_file def trans_response_cookie_value(self, response): # print(response.cookies,response.content) ck_value = requests.utils.dict_from_cookiejar(response.cookies) print('cookie value:', ck_value) return ck_value
def get_request_data_final(self, row): request_data = self._get_request_data(row) #请求数据,关键字 if str(request_data).startswith("json_"): #如果json_开头则进行json获取 opera_json = OperationJson() request_data = opera_json.get_value(request_data) return self.trans_value(request_data) elif str(request_data) != "": request_data = self.op_excel_value.replace_value( request_data) # 更新替换excel请求中带的变量 return self.trans_value( request_data) #如果不为空,不是json_开头,那么就替换变量再返回数据 else: return None #没有请求数据,则返回None
def get_expect_result_final(self, row): ''' 获取预期结果,返回数组类型 :param row: :return: type:list ''' expect_result = self._get_expect_result(row) if str(expect_result).startswith("json_"): # 如果json_开头则进行json获取 opera_json = OperationJson() expect_data = opera_json.get_value(expect_result) print('通过json配置的预期结果断言###值为:', expect_data) return list(str(self.trans_value(expect_data)).split(',')) elif str(expect_result) != "": expect_data = self.op_excel_value.replace_value( expect_result) # 更新替换excel请求中带的变量 return list(str(self.trans_value(expect_data)).split( ',')) # 如果不为空,不是json_开头,那么就替换变量再返回数据 elif str(expect_result) == "" or expect_result == None: return [] # 没有请求数据,则返回None else: return ["ERROR_FOUND_EXPECT_RESULT"]