def __init__(self): read_conf = ReadConfig() # 邮件发送开关 self.is_on = read_conf.get_email_config_var('on_off') self.run_method = RunMethod() self.data = GetData() self.public_util = PublicUtil() self.headers_and_cookies = OperationJson() self.cookies = self.headers_and_cookies.get_key_words("cookie") self.headers = self.headers_and_cookies.get_key_words("header")
def __init__(self): read_conf = ReadConfig() # 获取发送邮件的服务器 self.email_server = read_conf.get_email_config_var('email_server') # 获取授权码 self.authorization_code = read_conf.get_email_config_var( 'authorization_code') # 获取发件人的邮件地址 self.sender = read_conf.get_email_config_var('sender') # 获取收件人的邮件地址,有多个时中间使用“;”进行分割 self.receivers = read_conf.get_email_config_var('receivers') # 获取抄送者的邮件地址,有多个时中间使用“;”进行分割 self.copy_user = read_conf.get_email_config_var('copy_user') # 获取邮件主题 self.subject = read_conf.get_email_config_var('subject') # 邮件正文 self.content = read_conf.get_email_config_var('content') # 附件昵称 self.attachment_nickname = read_conf.get_email_config_var( 'attachment_nicknames')
def __init__(self): # 接收初始化的数据 config = ReadConfig() self.host = config.get_mysql_config_var('db_host') self.port = int(config.get_mysql_config_var('db_port')) self.user = config.get_mysql_config_var('db_user') self.pwd = config.get_mysql_config_var('db_pwd') self.name = config.get_mysql_config_var('db_name') self.charset = config.get_mysql_config_var('db_charset') # 准备结果存储最后的结果 self.result = [] # 定义一个变量高速程序是否执行成功 self.flag = False # True表示执行成功,False表示执行失败 # 需要一个变量存储异常信息 self.msg = ""
def __init__(self, logger_name='logs…'): self.logger = logging.getLogger(logger_name) logging.root.setLevel(logging.NOTSET) get_config_var = ReadConfig() format_time = get_format_time('%Y%m%d_%H%M%S') # 日志文件的名称 self.log_file_short_path = get_config_var.get_logger_config_var( 'log_file_save_path') # 最多存放日志的数量 self.backup_count = int( get_config_var.get_logger_config_var('log_save_count')) # 打印在控制台上的日志输出级别 self.console_output_level = get_config_var.get_logger_config_var( 'console_output_level') # ;写在日志文件中的日志输出级别 self.file_output_level = get_config_var.get_logger_config_var( 'file_output_level') # 日志输出格式 self.formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
def __init__(self): self.operation_excel = OperationExcel() self.get_headers_cookies = GetHeadersCookies() self.get_config = ReadConfig()
class GetData: def __init__(self): self.operation_excel = OperationExcel() self.get_headers_cookies = GetHeadersCookies() self.get_config = ReadConfig() def get_sheet_names(self): """获取当前工作簿中所有工作表的名称""" return self.operation_excel.get_sheet_names() def get_sheet_data(self, sheet_name): """通过sheet页名称读取对应sheet页的数据""" return self.operation_excel.get_sheet_data(sheet_name) def get_sheet_lines(self): """获取当前sheet页的总行数""" return self.operation_excel.get_sheet_lines() def get_json_file_name(self, sheet_name): """获取json文件名称""" sheet_name = "../test_data/json_data/" + sheet_name + ".json" return sheet_name def get_save_result_path(self): '''获取结果文件路径''' return self.operation_excel.save_result_path def get_is_run(self, x): """获取case是否运行""" flag = None y = data_conf.get_run() run_value = self.operation_excel.get_cell_value(x, y) if run_value.lower() == 'yes': flag = True else: flag = False return flag def get_is_header(self, x): """是否携带headers""" y = data_conf.get_request_header() header = self.operation_excel.get_cell_value(x, y) if header == 'yes': return self.get_headers_cookies.get_headers_value() else: return None def get_is_cookie(self, x): """是否携带cookies""" y = data_conf.get_request_cookie() cookie = self.operation_excel.get_cell_value(x, y) if cookie == 'yes': return self.get_headers_cookies.get_cookies_value() return None def get_request_method(self, x): """获取请求方法""" y = data_conf.get_request_method() request_method = self.operation_excel.get_cell_value(x, y) return request_method def get_request_url(self, x): """获取请求地址""" y = data_conf.get_url() request_url = self.operation_excel.get_cell_value(x, y) base_url = self.get_config.get_http_config_var('baseurl') request_url = base_url + request_url return request_url def get_request_data(self, sheet_name, x): """获取请求数据""" y = data_conf.get_request_data() request_data_key = self.operation_excel.get_cell_value(x, y) if request_data_key == '': return None else: request_data = self.__get_data_for_json(sheet_name, request_data_key) return request_data def __get_data_for_json(self, sheet_name, request_data_key): """通过excel中关键字去获取json数据""" sheetName = self.get_json_file_name(sheet_name) op_json = OperationJson(file_path=sheetName) data = op_json.get_key_words(request_data_key) return data def get_expect_data(self, x): """获取预期结果数据""" y = data_conf.get_expect_result() expect_data = self.operation_excel.get_cell_value(x, y) if expect_data == '': return None else: return string_to_eval(x, y, expect_data) def get_module_name(self, x): """获取模块名称""" y = data_conf.get_name() module_name = self.operation_excel.get_cell_value(x, y) return module_name def write_real_result(self, sheet_name, row, value): """写测试结果到excel""" y = data_conf.get_real_results() self.operation_excel.write_value(sheet_name, row, y, value) def get_is_case_depend(self, x): """判断是否有case依赖""" y = data_conf.get_case_depend() case_depend = self.operation_excel.get_cell_value(x, y) if case_depend == "": return None else: return string_to_eval(x, y, case_depend) def get_depend_data(self, x): """获取响应结果中的依赖字段""" y = data_conf.get_data_depend() data_depend = self.operation_excel.get_cell_value(x, y) if data_depend == "": return None else: return string_to_eval(x, y, data_depend) def get_depend_filed(self, x): """获取数据依赖字段""" y = data_conf.get_filed_depend() filed_depend = self.operation_excel.get_cell_value(x, y) if filed_depend == "": return None else: return string_to_eval(x, y, filed_depend)
def __init__(self): self.read_config = ReadConfig() self.timeout = eval(self.read_config.get_http_config_var('timeout'))
class RunMethod: def __init__(self): self.read_config = ReadConfig() self.timeout = eval(self.read_config.get_http_config_var('timeout')) def get_main(self, url, data=None, headers=None, cookies=None): res = None if headers is not None and cookies is not None: res = requests.get(url=url, data=data, headers=headers, cookies=cookies, timeout=self.timeout, verify=False) elif headers is not None and cookies is None: res = requests.get(url=url, data=data, headers=headers, timeout=self.timeout, verify=False) elif headers is None and cookies is not None: res = requests.get(url=url, data=data, cookies=cookies, timeout=self.timeout, verify=False) else: res = requests.get(url=url, data=data, timeout=self.timeout, verify=False) return res.json() def post_main(self, url, data=None, headers=None, cookies=None): res = None if headers is not None and cookies is not None: res = requests.post(url=url, data=data, headers=headers, cookies=cookies, timeout=self.timeout, verify=False) elif headers is not None and cookies is None: res = requests.post(url=url, data=data, headers=headers, timeout=self.timeout, verify=False) elif headers is None and cookies is not None: res = requests.post(url=url, data=data, cookies=cookies, timeout=self.timeout, verify=False) else: res = requests.post(url=url, data=data, timeout=self.timeout, verify=False) return res.json() def run_method(self, method, url, data=None, headers=None, cookies=None): res = None if method.lower() == 'post': res = self.post_main(url, data, headers, cookies) elif method.lower() == 'get': res = self.get_main(url, data, headers, cookies) else: return "接口请求方式暂时不支持" """ # ensure_ascii=False会输出真正的中文,否则会输出ASCII字符 # sort_keys=True 是告诉编码器按照字典key排序(a到z)输出。 # indent参数根据数据格式缩进显示,读起来更加清晰, indent的值,代表缩进空格式 """ return json.dumps(res, ensure_ascii=False)