Java Code Examples for org.testng.xml.XmlTest#setXmlClasses()

The following examples show how to use org.testng.xml.XmlTest#setXmlClasses() . 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: 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 2
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 3
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 4
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 5
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 + "'");
            }
        }
    }