Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()