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