def initlogging(): log_conf_path = _path('Config/Config.yaml') log_flie_path = _path("LogFiles") if os.path.exists(log_flie_path): pass else: os.mkdir(log_flie_path) dictconfig = yaml_load(log_conf_path)("loggings") dictconfig["handlers"]["info_file_handler"]["filename"] = _path("LogFiles/info.log") dictconfig["handlers"]["error_file_handler"]["filename"] = _path("LogFiles/errors.log") logging.config.dictConfig(dictconfig)
def runMain(): """ 通过模拟命令行运行 TemplateCase 生成单个的方法函数 再运行pytest allure 命令行进行运行生成报告""" del_list() case_path = _path(r"TapiAut/testCase") result_path = _path(r"result") html_path = _path(r"report/html") allure_path = _path(r"allure-2.13.7/bin") pytest.main(["-s", "-n", "auto", case_path, "--alluredir", result_path]) command_str = fr"{allure_path}/allure generate {result_path} -o {html_path} --clean" command_server = fr"{allure_path}/allure serve {result_path}" os.system(command_str)
def runCreatTemplate(self): """ 模板创建的方法run方法""" yamlfilepath = self.file_path codefilename = os.path.basename(yamlfilepath).split(".") codefilepath = _path(f"TapiAut/testCase/test_{codefilename[0]}.py") requestdata = yaml_load(yamlfilepath)() class_Remarks = requestdata.get("Remarks") with open(_path(codefilepath), "w+", encoding="UTF-8") as f: f.write(self.import_string) class_any = self.code_class_Create(yamlfilepath, class_Remarks) f.write(class_any) for k in requestdata: if "api" in k: def_any = self.code_def_Create(k, requestdata[k]) f.write(def_any) f.write(""" if __name__=="__main__": pytest.main(["-sq",__file__])""")
def __init__(self, yamlfilepath): self.reqkeys = [ 'method', 'url', 'data', 'headers', 'cookies', 'files', 'auth', 'timeout', 'allow_redirectsTrue', 'proxies', 'hooks', 'stream', 'verify', 'cert', 'json' ] self.import_string = Template(import_code).substitute() self.yaml_path = yamlfilepath self.file_path = _path(yamlfilepath)
def del_list(): filepath = _path("report/result") del_list = os.listdir(filepath) for f in del_list: file_path = os.path.join(filepath, f) if os.path.isfile(file_path): os.remove(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path)
def Creat_Template(path = "TapiAut/CaseFile/H5.yaml" ): """ 传入 要呗生成方法的yanl 文件 生成 def 方法""" yamllist = [] path = _path(path) if os.path.isdir(path): files = os.listdir(_path(path)) for i in files: if "yaml" in i: yamllist.append(os.path.join(path, i)) elif os.path.isfile(path): yamllist.append(path) else: print("it's a special file(socket,FIFO,device file)") if yamllist: for j in yamllist: template = CreateTemplate(yamlfilepath=j) template.runCreatTemplate()
def __init__(self): Config_path = _path("Core", "Config.yaml") self.Congfig = yaml_load(Config_path) driver_path = f"{_path()}\\{ self.Congfig('driver_path')}\\chromedriver.exe" driver_options = yaml_load(Config_path)("driver_options") if driver_options: option = webdriver.ChromeOptions() for i in driver_options: option.add_argument(i) super().__init__(executable_path=driver_path, options=option) self.implicitly_wait(20) self.father_number = {0: 0} self.number = 0 self.OUTIME = self.Congfig("outtime") self.POLL_FREQUENCY = self.Congfig("POLL_FREQUENCY")