Java Code Examples for org.testng.xml.XmlSuite#setName()

The following examples show how to use org.testng.xml.XmlSuite#setName() . 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 6 votes vote down vote up
public XmlSuite constructXmlSuiteForParallelCucumber(
    int deviceCount, List<AppiumDevice> deviceSerail) {
    ArrayList<String> listeners = new ArrayList<>();
    listeners.add("com.cucumber.listener.CucumberListener");
    XmlSuite suite = new XmlSuite();
    suite.setName("TestNG Forum");
    suite.setThreadCount(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("TestNG Test" + i);
        test.setPreserveOrder(false);
        test.addParameter("device", deviceSerail.get(i).getDevice().getUdid());
        test.setPackages(getPackages());
    }
    return getXmlSuite(suite);
}
 
Example 3
Source File: TestStarter.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This will provide a test suite for TestNG which will be based on the package.
 * It delegates any class inspection / reflection to TestNG.
 *
 * @return the XmlSuite for com.salesforce.dockerfileimageupdate.itest.tests.*
 */
private List<XmlSuite> getXmlSuites() {
    XmlSuite suite = new XmlSuite();
    suite.setName("Full Integration Test");
    XmlTest test = new XmlTest(suite);
    test.setName("all-tests");
    XmlRun xmlRun = new XmlRun();
    xmlRun.onInclude(test.getName());
    List<XmlPackage> packages = new ArrayList<>();
    packages.add(new XmlPackage("com.salesforce.dockerfileimageupdate.itest.tests.*"));
    test.setXmlPackages(packages);
    List<XmlSuite> suites = new ArrayList<>();
    suites.add(suite);
    return suites;
}
 
Example 4
Source File: LogLevelChangeListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the suite list with given parameters.
 *
 * @param logLevels
 * @param suite
 * @return
 */
private List<XmlSuite> createSuites(String logLevels, XmlSuite suite) {
    String[] levels = logLevels.split(",");
    ArrayList<XmlSuite> result = new ArrayList<>();
    for (String level : levels) {
        level = level.trim();
        if (StringUtils.isNotEmpty(level)) {
            suite.getParameters().put(LOG_LEVEL_PARAM_NAME, level);
        }
        XmlSuite suite1 = (XmlSuite) suite.clone();
        suite1.setName(suite1.getName() + "-" + level);
        result.add(suite1);
    }
    return result;
}
 
Example 5
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 6
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 7
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
public XmlSuite constructXmlSuiteDistributeCucumber(int deviceCount) {
    ArrayList<String> listeners = new ArrayList<>();
    listeners.add("com.cucumber.listener.CucumberListener");
    XmlSuite suite = new XmlSuite();
    suite.setName("TestNG Forum");
    suite.setThreadCount(deviceCount);
    suite.setParallel(ParallelMode.CLASSES);
    suite.setVerbose(2);
    suite.setListeners(listeners);
    XmlTest test = new XmlTest(suite);
    test.setName("TestNG Test");
    test.addParameter("device", "");
    test.setPackages(getPackages());
    return getXmlSuite(suite);
}
 
Example 8
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 9
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 10
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 + "'");
            }
        }
    }