def get_projectname_list(): projectspath = CreatorSettings.get_testproject_rootdir() projectname_list = [] for projectdir in os.listdir(projectspath): projectpath = projectspath + GlobalConfig.get_slash() + projectdir if os.path.isdir(projectpath): # python2 #project_package_init_file = file(projectpath + GlobalConfig.get_slash() + "__init__.py", "w") # python3 project_package_init_file = open( projectpath + GlobalConfig.get_slash() + "__init__.py", "w") project_package_init_file.close() if os.path.exists(projectpath + GlobalConfig.get_slash() + "datafiles"): projectname_list.append(projectdir) else: for subdir in os.listdir(projectpath): subprojectpath = projectpath + GlobalConfig.get_slash( ) + subdir if os.path.isdir(subprojectpath): if os.path.exists(subprojectpath + GlobalConfig.get_slash() + "datafiles"): projectname = projectdir + GlobalConfig.get_slash( ) + subdir subproject_package_init_file = open( subprojectpath + GlobalConfig.get_slash() + "__init__.py", "w") subproject_package_init_file.close() projectname_list.append(projectname) return projectname_list
def genreate_testcase(): rootdir = GlobalConfig.get_rootdir() projectname_list = get_projectname_list() for projectname in projectname_list: currentproject_path = CreatorSettings.get_testproject_rootdir( ) + GlobalConfig.get_slash() + projectname testcases_path = currentproject_path + GlobalConfig.get_slash( ) + "testcases" datafiles_path = currentproject_path + GlobalConfig.get_slash( ) + "datafiles" xml_report_path = currentproject_path + GlobalConfig.get_slash( ) + "report" + GlobalConfig.get_slash() + "xml" for xmlfile in os.listdir(datafiles_path): if xmlfile.endswith("cases.xml"): print("Get cases.xml file: {}".format(xmlfile)) testcaselist = get_testcaselist4xml(datafiles_path + GlobalConfig.get_slash() + xmlfile) print(testcaselist) # testcaselist=get_testcaselist(RunnerSettings.get_xml_folder()+GlobalConfig.get_slash()+xmlfile) testmethodcontent = "" for testcase in testcaselist: #print(create_testmethod_content(testcase, xmlfile)) testmethodcontent = testmethodcontent + create_testmethod_content( testcase, xmlfile) + "\n" #print(testmethodcontent) if "testcases.xml" not in xmlfile: classname_content = xmlfile.split("cases.xml")[0].replace( "test_", "Test") py_filename = xmlfile.split(".")[0] + ".py" else: classname_content = "Test" + xmlfile.split( "testcases.xml")[0] py_filename = "test_" + xmlfile.split( "testcases.xml")[0] + ".py" testclass_content = create_testclass_content( rootdir, classname_content, projectname, testmethodcontent, py_filename) testcasefile = open(testcases_path + GlobalConfig.get_slash() + py_filename, mode="w", encoding="utf-8") testcasefile.write(testclass_content) testcasefile.close() runpy_content = create_runpy_content(rootdir, xml_report_path) runpyfile = open(currentproject_path + GlobalConfig.get_slash() + "run.py", mode="w", encoding="utf-8") runpyfile.write(runpy_content) runpyfile.close()
def create_testproject(): projectname_list = get_projectname_list() for projectname in projectname_list: currentproject_path = CreatorSettings.get_testproject_rootdir( ) + GlobalConfig.get_slash() + projectname testcases_path = currentproject_path + GlobalConfig.get_slash( ) + "testcases" logtmp_folder = currentproject_path + GlobalConfig.get_slash( ) + "logtmp" project_log_path = currentproject_path + GlobalConfig.get_slash( ) + "log" testcases_log_path = testcases_path + GlobalConfig.get_slash() + "log" if os.path.exists(testcases_path): if os.path.exists(testcases_log_path): shutil.copytree(testcases_log_path, logtmp_folder) if sys.platform == "win32": #print("win system,force remove") os.system("rmdir /s /q %s" % testcases_path) else: shutil.rmtree(testcases_path) os.makedirs(testcases_path) if os.path.exists(logtmp_folder): shutil.copytree(logtmp_folder, testcases_log_path) shutil.rmtree(logtmp_folder) else: os.makedirs(testcases_log_path) if not os.path.exists(project_log_path): os.makedirs(project_log_path) testcases_package_init_file = open( testcases_path + GlobalConfig.get_slash() + "__init__.py", "w") testcases_package_init_file.close()
def create_loggerconf(): loggerconf_template = open(CreatorSettings.get_loggerconf_tempatepath(), mode='r', encoding="utf-8") loggerconf_content = loggerconf_template.read() loggerconf_content = loggerconf_content.replace('{log_folder}', GlobalConfig.get_logdir()) loggerconf_template.close() loogerconf_file = open(GlobalConfig.get_rootdir() + GlobalConfig.get_slash() + "logger.conf", mode='w', encoding="utf-8") loogerconf_file.write(loggerconf_content) loogerconf_file.close()
def get_step_project_and_file_name(self, teststep): step_peoject_name = "" step_file_name = "" StepParamsFileName = teststep["@StepParametersFileName"] if "/" not in StepParamsFileName: step_peoject_name = self.project_name step_file_name = StepParamsFileName else: project_and_file_list = StepParamsFileName.split("/") step_file_name = project_and_file_list[-1] project_floors = len(project_and_file_list) - 1 for i in range(project_floors): step_peoject_name += project_and_file_list[i] if i != project_floors - 1: step_peoject_name += GlobalConfig.get_slash() return step_peoject_name, step_file_name
def get_project_runpy(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "run.py"
def get_loggerconf_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "logger.conf"
def get_testclass_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "Test_class.txt"
def get_method_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "test_method.txt"
def get_datafiles_folder(projectname): return CreatorSettings.get_testproject_rootdir() + GlobalConfig.get_slash() + projectname + GlobalConfig.get_slash() + "datafiles"
def get_template_folder(): if CreatorSettings.ROOTDIR == None: return CreatorSettings.get_rootdir() + GlobalConfig.get_slash() + "CaseCreator" + GlobalConfig.get_slash() + "templates" else: return CreatorSettings.ROOTDIR + GlobalConfig.get_slash() + "CaseCreator" + GlobalConfig.get_slash() + "templates"
def get_testproject_rootdir(): if CreatorSettings.ROOTDIR == None: return (os.path.abspath("..") + GlobalConfig.get_slash() + GlobalConfig.AUTOPROJECTFOLDER) else: return (CreatorSettings.ROOTDIR + GlobalConfig.get_slash() + GlobalConfig.AUTOPROJECTFOLDER)