org.testng.xml.XmlClass Java Examples

The following examples show how to use org.testng.xml.XmlClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArkTestNGAlterSuiteListener.java    From sofa-ark with Apache License 2.0 6 votes vote down vote up
protected void resetSingleXmlSuite(XmlSuite suite) {
    for (XmlTest xmlTest : suite.getTests()) {
        for (XmlClass xmlClass : xmlTest.getClasses()) {
            Class testClass = xmlClass.getSupportClass();
            if (testClass.getAnnotation(TestNGOnArk.class) != null) {
                if (!DelegateArkContainer.isStarted()) {
                    DelegateArkContainer.launch(testClass);
                }

                try {
                    xmlClass.setClass(DelegateArkContainer.getTestClassLoader().loadClass(
                        testClass.getCanonicalName()));
                } catch (ClassNotFoundException ex) {
                    throw new ArkRuntimeException(String.format(
                        "Load testNG test class %s failed.", testClass.getCanonicalName()), ex);
                }
            }
        }
    }
}
 
Example #2
Source File: TestClass.java    From qaf with MIT License 6 votes vote down vote up
private void init(IClass cls,
                  ITestMethodFinder testMethodFinder,
                  IAnnotationFinder annotationFinder,
                  RunInfo runInfo,
                  XmlTest xmlTest,
                  XmlClass xmlClass)
{
  log(3, "Creating TestClass for " + cls);
  m_iClass = cls;
  m_testClass = cls.getRealClass();
  m_xmlTest = xmlTest;
  m_xmlClass = xmlClass;
  m_runInfo = runInfo;
  m_testMethodFinder = testMethodFinder;
  m_annotationFinder = annotationFinder;
  initTestClassesAndInstances();
  initMethods();
}
 
Example #3
Source File: DBSandboxer.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart(ITestContext context) {
    // This will only work if each test is run individually (test suite has only one running test)
    // If there are multiple tests the the sandbox folder name is not provided and the GraphSandboxUtil provisions
    // a unique name
    List<XmlClass> testClassesToRun = context.getCurrentXmlTest().getClasses();
    if (CollectionUtils.isNotEmpty(testClassesToRun) && 1 == testClassesToRun.size()) {
        XmlClass currentTestClass = testClassesToRun.get(0);
        if (null != currentTestClass && StringUtils.isNotEmpty(currentTestClass.getName())) {
            GraphSandboxUtil.create(currentTestClass.getName());
        } else {
            GraphSandboxUtil.create();
        }
    } else {
        GraphSandboxUtil.create();
    }
}
 
Example #4
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 6 votes vote down vote up
private List<XmlClass> writeXmlClass(List<String> testcases, Map<String,
    List<Method>> methods) {
    List<XmlClass> xmlClasses = new ArrayList<>();
    for (String className : methods.keySet()) {
        if (className.contains("Test")) {
            if (testcases.size() == 0) {
                xmlClasses.add(createClass(className));
            } else {
                for (String s : testcases) {
                    for (String item : items) {
                        String testName = item.concat("." + s);
                        if (testName.equals(className)) {
                            xmlClasses.add(createClass(className));
                        }
                    }
                }
            }
        }
    }
    return xmlClasses;
}
 
Example #5
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 6 votes vote down vote up
public XmlSuite constructXmlSuiteForDistribution(List<String> tests,
                                                 Map<String, List<Method>> methods,
                                                 String suiteName,
                                                 String category,
                                                 int deviceCount) {
    XmlSuite suite = new XmlSuite();
    suite.setName(suiteName);
    suite.setThreadCount(deviceCount);
    suite.setParallel(ParallelMode.CLASSES);
    suite.setVerbose(2);
    listeners.add("com.appium.manager.AppiumParallelMethodTestListener");
    listeners.add("com.appium.utils.RetryListener");
    include(listeners, LISTENERS);
    suite.setListeners(listeners);
    XmlTest test = new XmlTest(suite);
    test.setName(category);
    test.addParameter("device", "");
    include(groupsExclude, EXCLUDE_GROUPS);
    include(groupsInclude, INCLUDE_GROUPS);
    test.setIncludedGroups(groupsInclude);
    test.setExcludedGroups(groupsExclude);
    List<XmlClass> xmlClasses = writeXmlClass(tests, methods);
    test.setXmlClasses(xmlClasses);
    writeTestNGFile(suite);
    return suite;
}
 
Example #6
Source File: MultiSuiteTest.java    From sofa-ark with Apache License 2.0 5 votes vote down vote up
protected List<XmlTest> generateXmlTest(Class testClass) {
    XmlTest xmlTest = new XmlTest();
    XmlClass xmlClass = new XmlClass();
    xmlClass.setClass(testClass);
    xmlTest.setClasses(Collections.singletonList(xmlClass));
    return Collections.singletonList(xmlTest);
}
 
Example #7
Source File: CreateXmlFile.java    From Leo with Apache License 2.0 5 votes vote down vote up
private void addClassToXmlTest(String pkgAndClsName,String testName) {
	XmlTest xmltest=new XmlTest();
	XmlClass classe=new XmlClass(pkgAndClsName);
	xmltest.setName(testName);
	xmltest.setClasses(Arrays.asList(classe));
	addTest(xmltest);
}
 
Example #8
Source File: AllureTestListenerConfigMethodsTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
private static XmlSuite createSuite(String testName) {
    XmlSuite suite = new XmlSuite();
    suite.setName(SUITE_PREFIX + testName);
    XmlTest test = new XmlTest(suite);
    test.setName(testName);
    List<XmlClass> classes = new ArrayList<>();
    classes.add(new XmlClass(ConfigMethodsTest.class));
    test.setXmlClasses(classes);
    return suite;
}
 
Example #9
Source File: TestNGTestUnit.java    From pitest with Apache License 2.0 5 votes vote down vote up
private XmlSuite createSuite() {
  final XmlSuite suite = new XmlSuite();
  suite.setName(this.clazz.getName());
  suite.setSkipFailedInvocationCounts(true);
  final XmlTest test = new XmlTest(suite);
  test.setName(this.clazz.getName());
  final XmlClass xclass = new XmlClass(this.clazz.getName());
  test.setXmlClasses(Collections.singletonList(xclass));

  if (!this.includedTestMethods.isEmpty()) {
    final List<XmlInclude> xmlIncludedTestMethods = new ArrayList<>();
    for (final String includedTestMethod : this.includedTestMethods) {
      final XmlInclude includedMethod = new XmlInclude(includedTestMethod);
      xmlIncludedTestMethods.add(includedMethod);
    }
    xclass.setIncludedMethods(xmlIncludedTestMethods);
  }

  if (!this.config.getExcludedGroups().isEmpty()) {
    suite.setExcludedGroups(this.config.getExcludedGroups());
  }

  if (!this.config.getIncludedGroups().isEmpty()) {
    suite.setIncludedGroups(this.config.getIncludedGroups());
  }

  return suite;
}
 
Example #10
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
public XmlSuite constructXmlSuiteForDistributionMethods(List<String> tests,
                                                        Map<String, List<Method>> methods,
                                                        String suiteName,
                                                        String category,
                                                        int deviceCount) {
    include(groupsInclude, INCLUDE_GROUPS);
    XmlSuite suite = new XmlSuite();
    suite.setName(suiteName);
    suite.setThreadCount(deviceCount);
    suite.setDataProviderThreadCount(deviceCount);
    suite.setVerbose(2);
    suite.setParallel(ParallelMode.METHODS);
    listeners.add("com.appium.manager.AppiumParallelMethodTestListener");
    listeners.add("com.appium.utils.RetryListener");
    include(listeners, LISTENERS);
    suite.setListeners(listeners);
    CreateGroups createGroups = new CreateGroups(tests, methods, category, suite).invoke();
    List<XmlClass> xmlClasses = createGroups.getXmlClasses();
    XmlTest test = createGroups.getTest();
    List<XmlClass> writeXml = createGroups.getWriteXml();
    for (XmlClass xmlClass : xmlClasses) {
        writeXml.add(new XmlClass(xmlClass.getName()));
        test.setClasses(writeXml);
    }
    writeTestNGFile(suite);
    return suite;
}
 
Example #11
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
public XmlSuite constructXmlSuiteForParallel(String pack, List<String> testcases,
                                             Map<String, List<Method>> methods,
                                             String suiteName, String category,
                                             int deviceCount,
                                             List<AppiumDevice> deviceSerail) {
    ArrayList<String> listeners = new ArrayList<>();
    listeners.add("com.appium.manager.AppiumParallelTestListener");
    listeners.add("com.appium.utils.RetryListener");
    include(listeners, LISTENERS);
    include(groupsInclude, INCLUDE_GROUPS);
    include(groupsExclude, EXCLUDE_GROUPS);
    XmlSuite suite = new XmlSuite();
    suite.setName(suiteName);
    suite.setThreadCount(deviceCount);
    suite.setDataProviderThreadCount(deviceCount);
    suite.setParallel(ParallelMode.TESTS);
    suite.setVerbose(2);
    suite.setListeners(listeners);
    for (int i = 0; i < deviceCount; i++) {
        XmlTest test = new XmlTest(suite);
        test.setName(category + "-" + i);
        test.setPreserveOrder(false);
        test.addParameter("device", deviceSerail.get(i).getDevice().getUdid());
        test.addParameter("hostName", deviceSerail.get(i).getHostName());
        test.setIncludedGroups(groupsInclude);
        test.setExcludedGroups(groupsExclude);
        List<XmlClass> xmlClasses = writeXmlClass(testcases, methods);
        test.setXmlClasses(xmlClasses);
    }
    writeTestNGFile(suite);
    return suite;
}
 
Example #12
Source File: TestClass.java    From qaf with MIT License 5 votes vote down vote up
protected TestClass(IClass cls,
                 ITestMethodFinder testMethodFinder,
                 IAnnotationFinder annotationFinder,
                 RunInfo runInfo,
                 XmlTest xmlTest,
                 XmlClass xmlClass) {
  init(cls, testMethodFinder, annotationFinder, runInfo, xmlTest, xmlClass);
}
 
Example #13
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
private XmlClass createClass(String className) {
    XmlClass clazz = new XmlClass();
    clazz.setName(className);
    return clazz;
}
 
Example #14
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
public List<XmlClass> getXmlClasses() {
    return xmlClasses;
}
 
Example #15
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
public List<XmlClass> getWriteXml() {
    return writeXml;
}
 
Example #16
Source File: TestClass.java    From qaf with MIT License 4 votes vote down vote up
@Override
public XmlClass getXmlClass() {
  return m_xmlClass;
}
 
Example #17
Source File: CarinaListener.java    From carina with Apache License 2.0 4 votes vote down vote up
private void checkHealth(ISuite suite, String className, String[] methods) {

        if (className.isEmpty()) {
            return;
        }

        // create runtime XML suite for health check
        XmlSuite xmlSuite = new XmlSuite();
        xmlSuite.setName("HealthCheck XmlSuite - " + className);

        XmlTest xmlTest = new XmlTest(xmlSuite);
        xmlTest.setName("HealthCheck TestCase");
        XmlClass xmlHealthCheckClass = new XmlClass();
        xmlHealthCheckClass.setName(className);

        // TestNG do not execute missed methods so we have to calulate expected
        // methods count to handle potential mistakes in methods naming
        int expectedMethodsCount = -1;
        if (methods != null) {
            // declare particular methods if they are provided
            List<XmlInclude> methodsToRun = constructIncludes(methods);
            expectedMethodsCount = methodsToRun.size();
            xmlHealthCheckClass.setIncludedMethods(methodsToRun);
        }

        xmlTest.setXmlClasses(Arrays.asList(new XmlClass[] { xmlHealthCheckClass }));
        xmlSuite.setTests(Arrays.asList(new XmlTest[] { xmlTest }));

        LOGGER.info("HealthCheck '" + className + "' is started.");
        LOGGER.debug("HealthCheck suite content:" + xmlSuite.toXml());

        // Second TestNG process to run HealthCheck
        TestNG testng = new TestNG();
        testng.setXmlSuites(Arrays.asList(xmlSuite));

        TestListenerAdapter tla = new TestListenerAdapter();
        testng.addListener(tla);

        testng.run();
        synchronized (this) {
            boolean passed = false;
            if (expectedMethodsCount == -1) {
                if (tla.getPassedTests().size() > 0 && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            } else {
                LOGGER.info("Expected passed tests count: " + expectedMethodsCount);
                if (tla.getPassedTests().size() == expectedMethodsCount && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            }
            if (passed) {
                LOGGER.info("HealthCheck suite '" + className + "' is finished successfully.");
            } else {
                throw new SkipException("Skip test(s) due to health check failures for '" + className + "'");
            }
        }
    }