@Override public File tests() throws SuiteException { XmlSuite xmlSuite = new XmlSuite(); xmlSuite.setName(SUITE_NAME); try { for (SunshineTest sunshineTest : this.artifacts.tests()) { XmlTest test = new TestNGTest(sunshineTest).object(); test.setSuite(xmlSuite); xmlSuite.addTest(test); } this.suiteXml.write(xmlSuite.toXml()); return this.suiteXml; } catch (TestException | IOException e) { throw new SuiteException(e); } }
@Override public void generateReport( List<XmlSuite> arg0, List<ISuite> arg1, String arg2 ) { //we just need the report format, that why we set other fields null ReportFormatter reportFormatter = new ReportFormatter(ReportAppender.getRuns(), mailSubjectFormat, null, null, 0, null); // send report by mail MailReportSender mailReportSender = new MailReportSender(reportFormatter.getDescription(), reportFormatter.toHtml()); mailReportSender.send(); }
/** * Creates summary of the run */ public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) { try { m_out = createWriter(outdir); } catch (IOException e) { L.error("output file", e); return; } startHtml(m_out); generateSuiteSummaryReport(suites); generateMethodSummaryReport(suites); generateMethodDetailReport(suites); endHtml(m_out); m_out.flush(); m_out.close(); }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { StringBuilder sb = new StringBuilder(); for (ISuite suite : suites) { Map<String, ISuiteResult> results = suite.getResults(); for (Map.Entry<String, ISuiteResult> result : results.entrySet()) { String report = buildReport(result.getValue().getTestContext()); sb.append(report); } } try { FileUtils.writeToFile(new File(FAILED_REPORT_FILE), sb.toString()); } catch (IOException e) { e.printStackTrace(); } }
@Override public void alter(List<XmlSuite> suites) { List<XmlSuite> cloned = new ArrayList<>(suites); suites.clear(); for (XmlSuite suite : cloned) { String logLevels = suite.getParameter(LOG_LEVELS_PARAM_NAME); if (StringUtils.isNotEmpty(logLevels)) { List<XmlSuite> newSuites = createSuites(logLevels, suite); if (!newSuites.isEmpty()) { suites.addAll(newSuites); } } else { suites.add(suite); } } }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { List<ITestResult> list = new ArrayList<ITestResult>(); for (ISuite suite : suites) { Map<String, ISuiteResult> suiteResults = suite.getResults(); for (ISuiteResult suiteResult : suiteResults.values()) { ITestContext testContext = suiteResult.getTestContext(); IResultMap passedTests = testContext.getPassedTests(); IResultMap failedTests = testContext.getFailedTests(); IResultMap skippedTests = testContext.getSkippedTests(); IResultMap failedConfig = testContext.getFailedConfigurations(); list.addAll(this.listTestResult(passedTests)); list.addAll(this.listTestResult(failedTests)); list.addAll(this.listTestResult(skippedTests)); list.addAll(this.listTestResult(failedConfig)); } } this.sort(list); this.outputResult(list, outputDirectory+"/test.txt"); }
protected ITestResult prepareMock(Class<?> tClass, Method method) { ITestResult result = mock(ITestResult.class); IClass clazz = mock(IClass.class); ITestNGMethod testNGMethod = mock(ITestNGMethod.class); ConstructorOrMethod cm = mock(ConstructorOrMethod.class); String methodName = method.getName(); when(result.getTestClass()).thenReturn(clazz); when(result.getTestClass().getRealClass()).thenReturn(tClass); when(clazz.getName()).thenReturn(this.getClass().getName()); when(result.getMethod()).thenReturn(testNGMethod); when(cm.getMethod()).thenReturn(method); when(result.getMethod().getConstructorOrMethod()).thenReturn(cm); when(testNGMethod.getMethodName()).thenReturn(methodName); ITestContext context = mock(ITestContext.class); when(result.getTestContext()).thenReturn(context); XmlTest xmlTest = new XmlTest(); XmlSuite suite = new XmlSuite(); xmlTest.setXmlSuite(suite); suite.setListeners(Arrays.asList(VideoListener.class.getName())); when(context.getCurrentXmlTest()).thenReturn(xmlTest); return result; }
@Test public void testOneTestMethod() throws Exception { final XmlSuite suite = new XmlSuite(); final XmlTest test = new XmlTest(); final XmlClass xmlClass = new XmlClass("a.ATest", false); xmlClass.getIncludedMethods().add(new XmlInclude("test1")); test.getClasses().add(xmlClass); suite.getTests().add(test); doTest(suite,"##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[0|]']\n"); }
@Test public void testOneTestMethodWithMultipleInvocationCount() throws Exception { final XmlSuite suite = new XmlSuite(); final XmlTest test = new XmlTest(); final XmlClass xmlClass = new XmlClass("a.ATest", false); xmlClass.getIncludedMethods().add(new XmlInclude("test1", Arrays.asList(0, 1, 2), 0)); test.getClasses().add(xmlClass); suite.getTests().add(test); doTest(suite, "##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[0|]']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[1|] (1)' locationHint='java:test://a.ATest.test1|[1|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[1|] (1)']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[2|] (2)' locationHint='java:test://a.ATest.test1|[2|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[2|] (2)']\n"); }
private static void doTest(XmlSuite suite, String expected) { final StringBuffer buf = new StringBuffer(); final IDEATestNGRemoteListener listener = createListener(buf); for (XmlTest test : suite.getTests()) { for (XmlClass aClass : test.getClasses()) { final String classFQName = aClass.getName(); for (XmlInclude include : aClass.getIncludedMethods()) { final String methodName = include.getName(); List<Integer> numbers = include.getInvocationNumbers(); if (numbers.isEmpty()) { numbers = Collections.singletonList(0); } for (Integer integer : numbers) { final MockTestNGResult result = new MockTestNGResult(classFQName, methodName, null, new Object[] {integer}); listener.onTestStart(result); listener.onTestFinished(result); } } } } Assert.assertEquals("output: " + buf, expected, StringUtil.convertLineSeparators(buf.toString())); }
/** * Initialize logging to trace REST request/response input/ouput for tests * Call in @BeforeClass method for tests * @param testContext of current test/suite */ public static void initLogging(ITestContext testContext) { XmlSuite currentSuite = testContext.getCurrentXmlTest().getSuite(); String suiteName = currentSuite.getName(); String service = currentSuite.getParameter("service"); PrintStream defaultLogStream = null; Path outDirPath; try { if(service != null) outDirPath = Files.createDirectories(Paths.get(System.getProperty("java.io.tmpdir"), "test-output", service)); else outDirPath = Files.createDirectories(Paths.get(System.getProperty("java.io.tmpdir"), "test-output")); Path logFilePath = Files.createTempFile(outDirPath, suiteName, ".out"); defaultLogStream = new PrintStream(logFilePath.toFile()); } catch(IOException e) { e.printStackTrace(); } LogConfig testLogConfig = new LogConfig(defaultLogStream, true); RestAssured.config = RestAssuredConfig.config().logConfig(testLogConfig); }
private void run() { LOG.debug("running tempto with options: {}", options); if (options.isHelpRequested()) { parser.printHelpMessage(); return; } XmlSuite testSuite = getXmlSuite(); testSuite.setThreadCount(options.getThreadCount()); setupTestsConfiguration(); System.setProperty(CONVENTION_TESTS_DIR_KEY, options.getConventionTestsDirectory()); TestNG testNG = new TestNG(); testNG.setXmlSuites(singletonList(testSuite)); testNG.setOutputDirectory(options.getReportDir()); setupTestsFiltering(testNG); options.getConventionResultsDumpPath() .ifPresent(path -> System.setProperty(CONVENTION_TESTS_RESULTS_DUMP_PATH_KEY, path)); testNG.run(); if (testNG.hasFailure()) { System.exit(1); } }
private XmlSuite getXmlSuite() { // we cannot use singletonLists here as testNG later // modifies lists stored in XmlSuite ... zonk XmlSuite testSuite = new XmlSuite(); testSuite.setName("tempto-tests"); testSuite.setFileName("tempto-tests"); XmlTest test = new XmlTest(testSuite); test.setName("all"); XmlPackage testPackage = new XmlPackage(options.getTestsPackage()); List<XmlPackage> testPackages = newArrayList(testPackage); test.setPackages(testPackages); XmlClass conventionBasedTestsClass = new XmlClass("io.prestodb.tempto.internal.convention.ConventionBasedTestFactory"); List<XmlClass> classes = newArrayList(conventionBasedTestsClass); test.setClasses(classes); test.setParallel(XmlSuite.ParallelMode.METHODS); return testSuite; }
@Override public void run() { try { initializeSuitesAndJarFile(); List<XmlSuite> suites = new ArrayList<>(); flatSuites(m_suites, suites); if (suites.isEmpty()) { TestingMessageHelper.reporterAttached(System.out); System.err.print("No test found to run."); } else { addCheListeners(); super.run(); System.exit(0); } } catch (Throwable throwable) { throwable.printStackTrace(System.err); } }
public void generateConsolidatedReportByOwner(java.util.List<XmlSuite> xmlSuites, java.util.List<ISuite> suites, java.lang.String outputDirectory) { Map<String, List<ITestResult>> ownersOfFailedTests = new HashMap<String, List<ITestResult>>(); Map<String, List<ITestResult>> ownersOfPassedTests = new HashMap<String, List<ITestResult>>(); for (ISuite suite : suites) { for (ISuiteResult result : suite.getResults().values()) { ownersOfPassedTests = getTestByOwnerSiteBrowser(result.getTestContext().getPassedTests().getAllResults()); ownersOfFailedTests = getTestByOwnerSiteBrowser(result.getTestContext().getFailedTests().getAllResults()); } } // Send consolidated failures to the Team group email id. TestNGEmailSender.sendConsolidatedFailureEmail(ownersOfPassedTests, ownersOfFailedTests); }
private void executeInCurrentLoader(final ResultCollector rc) { final TestNGAdapter listener = new TestNGAdapter(this.clazz, this.getDescription(), rc); final XmlSuite suite = createSuite(); TESTNG.setDefaultSuiteName(suite.getName()); TESTNG.setXmlSuites(Collections.singletonList(suite)); LISTENER.setChild(listener); try { TESTNG.run(); } finally { // yes this is hideous LISTENER.setChild(null); } }
/** * Generates a set of XML files (JUnit format) that contain data about the * outcome of the specified test suites. * * @param suites Data about the test runs. * @param outputDirectoryName The directory in which to create the report. */ public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectoryName) { removeEmptyDirectories(new File(outputDirectoryName)); File outputDirectory = new File(outputDirectoryName, REPORT_DIRECTORY); outputDirectory.mkdirs(); Collection<TestClassResults> flattenedResults = flattenResults(suites); for (TestClassResults results : flattenedResults) { VelocityContext context = createContext(); context.put(RESULTS_KEY, results); try { generateFile(new File(outputDirectory, results.getTestClass().getName() + '_' + RESULTS_FILE), RESULTS_FILE + TEMPLATE_EXTENSION, context); } catch (Exception | AssertionError ex) { throw new ReportNGException("Failed generating JUnit XML report.", ex); } } }
/** * Adds the entries from the properties document to the set of test suite * parameters. An entry is skipped if its value is an empty string. */ @Override public void alter(List<XmlSuite> xmlSuites) { if (null == this.testRunArgs || this.testRunArgs.getElementsByTagName("entry").getLength() == 0) { return; } for (XmlSuite xmlSuite : xmlSuites) { Map<String, String> params = xmlSuite.getParameters(); NodeList entries = this.testRunArgs.getElementsByTagName("entry"); for (int i = 0; i < entries.getLength(); i++) { Element entry = (Element) entries.item(i); String value = entry.getTextContent().trim(); if (value.isEmpty()) { continue; } params.put(entry.getAttribute("key"), value); LOGR.log(Level.FINE, "Added parameter: {0}={1}", new Object[] { entry.getAttribute("key"), value }); } params.put("uuid", this.testRunId.toString()); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { ITestClass testClass = method.getTestMethod().getTestClass(); Class testClassToBeInvoked = testClass.getRealClass(); if (testClassToBeInvoked != currentTestClass) { currentTestClass = testClassToBeInvoked; startTime.set(System.currentTimeMillis()); MDC.put("testClass", currentTestClass.getSimpleName()); logger.info("STARTING TEST CLASS"); if (seleniumConfig != null) { seleniumConfig.destroy(); } seleniumConfig = new JCommuneSeleniumConfig(); XmlSuite suite = testClass.getXmlTest().getSuite(); try { seleniumConfig.init(suite.getParameter("webDriverUrl"), suite.getParameter("appUrl"), currentTestClass.getSimpleName()); } catch (Exception e) { logger.error("Unexpected error during Selenium configuration.", e); throw new RuntimeException(e); } seleniumConfig.printSeleniumSessionId(testClass.getName()); } }
public static Optional<XmlConfig> getSuiteBrowserConfiguration(final XmlSuite xmlSuite, final String method) { final Map<String, String> parameters = new HashMap<>(); ofNullable(xmlSuite.getParameter(BROWSER_NAME)).ifPresent(val -> parameters.put(BROWSER_NAME, val)); ofNullable(xmlSuite.getParameter(VERSION)).ifPresent(val -> parameters.put(VERSION, val)); ofNullable(xmlSuite.getParameter(PLATFORM_NAME)).ifPresent(val -> parameters.put(PLATFORM_NAME, val)); parameters.putIfAbsent(TEST_NAME, method); return Optional.of(new XmlConfig(unmodifiableMap(parameters))); }
/** Creates summary of the run */ @Override public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) { try { m_out = createWriter(outdir); } catch (IOException e) { L.error("output file", e); return; } ConfigUtil cr = ConfigUtil.getInstance(); if (cr.getSrouceCodeEncoding() != null) { builder.setEncoding(cr.getSrouceCodeEncoding()); } else { builder.setEncoding("UTF-8"); } builder.addSourceTree(new File(cr.getSourceCodeDir())); startHtml(m_out); generateSuiteSummaryReport(suites); testIds.clear(); generateMethodSummaryReport(suites); testIds.clear(); generateMethodDetailReport(suites); testIds.clear(); endHtml(m_out); m_out.flush(); m_out.close(); }
public ReporterAPI(List<XmlSuite> arg0, List<ISuite> suites, String outputDir) throws IOException { this.suites = suites; for (ISuite suite : suites) { suiteName = suite.getName(); parallelRunParam = suite.getParallel(); } config = ProjectConfigurator.initializeProjectConfigurationsFromFile("project.properties"); }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { super.generateReport(xmlSuites, suites, outputDirectory); String content = buffer.getBuffer().toString(); try { sendEmail(content); } catch (Exception e) { e.printStackTrace(); } }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String huh) { for (ISuite suite : suites) { Map<String, ISuiteResult> results = suite.getResults(); for (String resultName : results.keySet()) { ISuiteResult result = results.get(resultName); log.info("Results for {}", resultName); IResultMap passedConfigs = result.getTestContext().getPassedConfigurations(); if (passedConfigs != null) { passedConfigs.getAllResults().forEach(passedConfig -> log.info("{} successful", passedConfig.getMethod())); } IResultMap passedTests = result.getTestContext().getPassedTests(); if (passedTests != null) { passedTests.getAllResults().forEach(passedTest -> log.info("{} passed", passedTest.getMethod())); } IResultMap skippedTests = result.getTestContext().getSkippedTests(); if (skippedTests != null) { skippedTests.getAllResults().forEach(iTestResult -> log.warn("{} skipped", iTestResult.getMethod())); } IResultMap failedConfigurations = result.getTestContext().getFailedConfigurations(); if (failedConfigurations != null) { failedConfigurations.getAllResults().forEach(failedConfig -> { log.error("{} configuration failed", failedConfig.getMethod()); log.error(failedConfig.getThrowable().getMessage(), failedConfig.getThrowable()); }); } IResultMap failedTests = result.getTestContext().getFailedTests(); if (failedTests != null) { failedTests.getAllResults().forEach(failedTest -> { if (failedTest.getParameters().length > 0) { log.error("{}({}) failed", failedTest.getMethod(), failedTest.getParameters()); } else { log.error("{} failed", failedTest.getMethod()); } log.error(failedTest.getThrowable().getMessage(), failedTest.getThrowable()); }); } } } }
/** * 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; }
private static void runTestNG(int threadCount, Filter filter) { TestNG testng = new TestNG(); testng.setTestClasses(new Class[]{DBTestCompare.class}); String suiteName = "Compare SQL results suite"; if (filter != null && ((filter.getIncludes() != null && !filter.getIncludes().isEmpty()) || (filter.getExcludes() != null && !filter.getExcludes().isEmpty()))) { suiteName = "FILTERED compare SQL results suite"; } testng.setDefaultSuiteName(suiteName); testng.setParallel(XmlSuite.PARALLEL_INSTANCES); testng.setThreadCount(threadCount); // testng.setDataProviderThreadCount(cmpSqlResultsConfig.getThreads()); testng.run(); }
public void runTests(KWDTestCase kwdTestCase, String testSuiteName, String outputDirectory) { this.kwdTestCase = kwdTestCase; XmlSuite suite = new XmlSuite(); suite.setName(testSuiteName); XmlTest xmlTest = new XmlTest(suite); xmlTest.setName(kwdTestCase.getTestCaseName()); xmlTest.setVerbose(0); System.out.println("Total number of Tests to be run: " + kwdTestCase.getTestMethods().size()); { XmlClass xmlClass = new XmlClass("com.carteblanche.kwd.testng.TestNGDriver"); xmlTest.getClasses().add(xmlClass); List<XmlInclude> xmlIncludeMethods = xmlClass.getIncludedMethods(); XmlInclude xmlInclude = new XmlInclude("runnableTest"); xmlIncludeMethods.add(xmlInclude); xmlClass.setIncludedMethods(xmlIncludeMethods); } System.out.println("Running Tests using command .."); testNG.setXmlSuites(Arrays.asList(suite)); testNG.setPreserveOrder(true); testNG.setUseDefaultListeners(true); testNG.setOutputDirectory(outputDirectory); testNG.run(); }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { List<ITestResult> list = new ArrayList<ITestResult>(); for (ISuite suite : suites) { Map<String, ISuiteResult> suiteResults = suite.getResults(); for (ISuiteResult suiteResult : suiteResults.values()) { ITestContext testContext = suiteResult.getTestContext(); IResultMap passedTests = testContext.getPassedTests(); IResultMap failedTests = testContext.getFailedTests(); IResultMap skippedTests = testContext.getSkippedTests(); IResultMap failedConfig = testContext.getFailedConfigurations(); list.addAll(this.listTestResult(passedTests)); list.addAll(this.listTestResult(failedTests)); list.addAll(this.listTestResult(skippedTests)); //list.addAll(this.listTestResult(failedConfig)); } } CopyReportResources reportReource=new CopyReportResources(); try { reportReource.copyResources(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } this.sort(list); this.outputResult(list, outputDirectory+"/report.html"); }
/** * Create a list of workers to run the methods passed in parameter. * Each test method is run in its own worker except in the following cases: * - The method belongs to a class that has @Test(sequential=true) * - The parallel attribute is set to "classes" * In both these cases, all the methods belonging to that class will then * be put in the same worker in order to run in the same thread. */ @Override public List<IWorker<ITestNGMethod>> createWorkers(List<ITestNGMethod> methods) { List<IWorker<ITestNGMethod>> result; if (XmlSuite.ParallelMode.INSTANCES.equals(m_xmlTest.getParallel())) { result = createInstanceBasedParallelWorkers(methods); } else { result = createClassBasedParallelWorkers(methods); } return result; }
public static File writeSuite(Map<String, Map<String, List<String>>> map, Map<String, String> testParams, String name, String rootPath, Logger logger) { File xmlFile; final XmlSuite xmlSuite = new XmlSuite(); xmlSuite.setParameters(testParams); XmlTest xmlTest = new XmlTest(xmlSuite); xmlTest.setName(name); List<XmlClass> xmlClasses = new ArrayList<XmlClass>(); int idx = 0; for (String className : map.keySet()) { final XmlClass xmlClass = new XmlClass(className, idx++, false); final Map<String, List<String>> collection = map.get(className); if (collection != null) { final ArrayList<XmlInclude> includedMethods = new ArrayList<XmlInclude>(); int mIdx = 0; for (String methodName : collection.keySet()) { final List<Integer> includes = new ArrayList<Integer>(); for (String include : collection.get(methodName)) { try { includes.add(Integer.parseInt(include)); } catch (NumberFormatException e) { logger.log(e); } } includedMethods.add(new XmlInclude(methodName, includes, mIdx++)); } xmlClass.setIncludedMethods(includedMethods); } xmlClasses.add(xmlClass); } xmlTest.setXmlClasses(xmlClasses); xmlFile = new File(rootPath, "temp-testng-customsuite.xml"); final String toXml = xmlSuite.toXml(); writeToFile(logger, xmlFile, toXml); return xmlFile; }
protected TestNG createTests(String suiteName, Class<?>... testClasses) { XmlSuite suite = createXmlSuite(suiteName); int i=0; for (Class<?> testClass : testClasses) { createXmlTest(suite, testClass.getName() + i, testClass); i++; } return create(suite); }
protected XmlTest createXmlTest(XmlSuite suite, String name, String... classes) { XmlTest result = new XmlTest(suite); int index = 0; result.setName(name); for (String c : classes) { XmlClass xc = new XmlClass(c, index++, true /* load classes */); result.getXmlClasses().add(xc); } return result; }
/** Creates summary of the run */ @Override public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) { try { m_out = createWriter(outdir); } catch (IOException e) { L.error("output file", e); return; } ConfigReader cr = ConfigReader.getInstance(); if(cr.getSrouceCodeEncoding()!=null){ builder.setEncoding(cr.getSrouceCodeEncoding()); }else{ builder.setEncoding("UTF-8"); } builder.addSourceTree(new File(cr.getSourceCodeDir())); startHtml(m_out); generateSuiteSummaryReport(suites); testIds.clear(); generateMethodSummaryReport(suites); testIds.clear(); generateMethodDetailReport(suites); testIds.clear(); endHtml(m_out); m_out.flush(); m_out.close(); }
/** * {@inheritDoc} */ @Override public void generateReport(List<XmlSuite> arg0, List<ISuite> arg1, String arg2) { if (log.isDebugEnabled()) { log.debug("Generating paxml report ... "); } overwriteReport(); }
/** * Creates the suite which is represented by one XML file with name che-testng-suite.xml. It can * contain one or more tests. * * @param suitePath path to the suite file * @param suiteName the name of the suite * @param classesAndMethods classes and methods which should be included to the suite. * @return created file with suite */ public File writeSuite( String suitePath, String suiteName, Map<String, List<String>> classesAndMethods) { XmlSuite suite = new XmlSuite(); XmlTest test = new XmlTest(suite); test.setName(suiteName); List<XmlClass> xmlClasses = new ArrayList<>(); for (String className : classesAndMethods.keySet()) { XmlClass xmlClass = new XmlClass(className, false); xmlClasses.add(xmlClass); List<String> methods = classesAndMethods.get(className); if (methods != null) { List<XmlInclude> includedMethods = new ArrayList<>(); for (String method : methods) { includedMethods.add(new XmlInclude(method)); } xmlClass.setIncludedMethods(includedMethods); } } test.setXmlClasses(xmlClasses); File result = new File(suitePath, "che-testng-suite.xml"); try { com.google.common.io.Files.write(suite.toXml().getBytes("UTF-8"), result); } catch (IOException e) { LOG.error("Can't write TestNG suite xml file.", e); } return result; }
public XmlSuite constructXmlSuiteForParallel(String pack, List<String> testcases, Map<String, List<Method>> methods, int deviceCount, ArrayList<String> 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("TestNG Forum"); 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("TestNG Test" + i); test.setPreserveOrder("false"); test.addParameter("device", deviceSerail.get(i)); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); List<XmlClass> xmlClasses = new ArrayList<>(); writeXmlClass(testcases, methods, xmlClasses); test.setXmlClasses(xmlClasses); } System.out.println(suite.toXml()); writeTestNGFile(suite); return suite; }
public XmlSuite constructXmlSuiteForDistribution(String pack, List<String> tests, Map<String, List<Method>> methods, int deviceCount) { include(listeners, "LISTENERS"); include(groupsInclude, "INCLUDE_GROUPS"); XmlSuite suite = new XmlSuite(); suite.setName("TestNG Forum"); suite.setThreadCount(deviceCount); suite.setParallel(ParallelMode.CLASSES); suite.setVerbose(2); listeners.add("com.appium.manager.AppiumParallelMethodTestListener"); listeners.add("com.appium.utils.RetryListener"); suite.setListeners(listeners); if (prop.getProperty("LISTENERS") != null) { suite.setListeners(listeners); } XmlTest test = new XmlTest(suite); test.setName("TestNG Test"); test.addParameter("device", ""); include(groupsExclude, "EXCLUDE_GROUPS"); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); List<XmlClass> xmlClasses = new ArrayList<>(); writeXmlClass(tests, methods, xmlClasses); test.setXmlClasses(xmlClasses); System.out.println(suite.toXml()); writeTestNGFile(suite); return suite; }
public XmlSuite constructXmlSuiteForDistributionMethods(String pack, List<String> tests, Map<String, List<Method>> methods, int deviceCount) { include(listeners, "LISTENERS"); include(groupsInclude, "INCLUDE_GROUPS"); XmlSuite suite = new XmlSuite(); suite.setName("TestNG Forum"); 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"); suite.setListeners(listeners); if (prop.getProperty("LISTENERS") != null) { suite.setListeners(listeners); } List<XmlClass> xmlClasses = new ArrayList<>(); xmlClasses = writeXmlClass(tests, methods, xmlClasses); XmlTest test = new XmlTest(suite); test.setName("TestNG Test"); test.addParameter("device", ""); include(groupsExclude, "EXCLUDE_GROUPS"); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); List<XmlClass> writeXml = new ArrayList<>(); for (int i = 0; i < xmlClasses.size(); i++) { writeXml.add(new XmlClass(xmlClasses.get(i).getName())); test.setClasses(writeXml); } System.out.println(suite.toXml()); writeTestNGFile(suite); return suite; }
private void writeTestNGFile(XmlSuite suite) { try { FileWriter writer = new FileWriter(new File( System.getProperty("user.dir") + "/target/parallel.xml")); writer.write(suite.toXml()); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }