How to use XMLSuiteResultWriter class of org.testng.reporters package

Best Testng code snippet using org.testng.reporters.XMLSuiteResultWriter

Source:Listener.java Github

copy

Full Screen

...9import com.leroy.core.configuration.DriverFactory;10import com.leroy.core.configuration.Log;11import com.leroy.core.configuration.TestInfo;12import com.leroy.core.listeners.helpers.RetryAnalyzer;13import com.leroy.core.listeners.helpers.XMLSuiteResultWriter;14import com.leroy.core.pages.AnyPage;15import io.qameta.allure.Issue;16import org.apache.commons.lang3.RandomStringUtils;17import org.apache.commons.lang3.StringUtils;18import org.openqa.selenium.remote.RemoteWebDriver;19import org.testng.*;20import org.testng.annotations.ITestAnnotation;21import org.testng.internal.Utils;22import org.testng.reporters.XMLReporterConfig;23import org.testng.reporters.XMLStringBuffer;24import org.testng.util.Strings;25import org.testng.xml.XmlSuite;26import java.io.File;27import java.io.FileOutputStream;28import java.io.IOException;29import java.lang.reflect.Constructor;30import java.lang.reflect.Method;31import java.text.SimpleDateFormat;32import java.util.*;33import java.util.regex.Matcher;34import java.util.regex.Pattern;35public class Listener implements ITestListener, ISuiteListener,36 IInvokedMethodListener, IReporter, IAnnotationTransformer {37 private String BROWSER_PROFILE;38 private boolean outputDirExist = false;39 private Map<String, String> outputConfig = new HashMap<String, String>();40 private int testPassed = 0;41 private int testFailed = 0;42 private int testSkipped = 0;43 private static final String TEST_CASE_ID_PATTERN = "C\\d+";44 private static final ThreadLocal<String> context = new ThreadLocal<>();45 public static final String FILE_NAME = "testng-results.xml";46 protected final XMLReporterConfig config = new XMLReporterConfig();47 private XMLStringBuffer rootBuffer;48 public Listener() {49 BROWSER_PROFILE = readBrowserFromPropertyFile();50 }51 //right now only AFTER_SUITE and AFTER_ALL methods are working correctly52 enum ResultGenerationMode {53 AFTER_TEST, AFTER_CLASS, AFTER_SUITE, AFTER_ALL54 }55 private static Listener.ResultGenerationMode resultGenerationMode;56 private ArrayList<ISuite> suites = new ArrayList<>();57 private static boolean processFail;58 private static boolean disableScreenshots;59 protected String currentScreenshotPath;60 private static ObjectMapper mapper = new ObjectMapper();61 static {62 try {63 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);64 String mode = System.getProperty("resultGenerationMode", "all");65 switch (mode) {66 case "test":67 resultGenerationMode = Listener.ResultGenerationMode.AFTER_TEST;68 break;69 case "class":70 resultGenerationMode = Listener.ResultGenerationMode.AFTER_CLASS;71 break;72 case "suite":73 resultGenerationMode = Listener.ResultGenerationMode.AFTER_SUITE;74 break;75 default:76 resultGenerationMode = Listener.ResultGenerationMode.AFTER_ALL;77 break;78 }79 processFail = Boolean.parseBoolean(System.getProperty("processFail", "true"));80 disableScreenshots = Boolean.parseBoolean(System.getProperty("disableScreenshots", "false"));81 } catch (Exception e) {82 e.printStackTrace();83 }84 }85 // Retry analyzer86 @Override87 public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {88 annotation.setRetryAnalyzer(RetryAnalyzer.class);89 if (isTestNeedToDisable(testMethod)) {90 annotation.setEnabled(false);91 }92 }93 private String readBrowserFromPropertyFile() {94 String pathPropsFile = System.getProperty("mpropsFile");95 if (pathPropsFile == null)96 return null;97 Map<String, Object> properties = (Map<String, Object>)98 DriverFactory.loadPropertiesFromFile(pathPropsFile);99 Map<String, Object> settings = (Map<String, Object>) properties.get("settings");100 return DriverFactory.getPropertyValue("", settings, "browser",101 System.getProperty("mBrowser"));102 }103 private boolean isTestNeedToDisable(Method method) {104 String smoke = System.getProperty("smoke");105 String withIssues = System.getProperty("runWithIssues");106 if (Strings.isNotNullAndNotEmpty(withIssues) && withIssues.equalsIgnoreCase("false")) {107 return method.isAnnotationPresent(Issue.class);108 }109 if (Strings.isNotNullAndNotEmpty(smoke) && smoke.equals("true")) {110 return !method.isAnnotationPresent(Smoke.class);111 }112 if (method.isAnnotationPresent(DisableTestWhen.class)) {113 String[] browsers = method.getAnnotation(DisableTestWhen.class).browsers();114 return Arrays.asList(browsers).contains(BROWSER_PROFILE);115 }116 return false;117 }118 // This belongs to ISuiteListener and will execute before the Suite start119 @Override120 public void onStart(ISuite arg0) {121 System.setProperty("current.date", new SimpleDateFormat("E_yyyy.MM.dd_HH.mm.ss_z").format(new Date()));122 arg0.getXmlSuite().setName(arg0.getName());123 // Continue with the rest of the initialization of the system properties124 if (!outputDirExist) {125 System.setProperty("suite.name", "TestResults");126 System.setProperty(127 "output.path",128 "data-output/" + "__Run_"129 + System.getProperty("suite.name") + "_"130 + System.getProperty("current.date"));131 // if TestDataOutput doesn't exist, create it132 File TestDataOutputDir = new File(System.getProperty("output.path"));133 if (!TestDataOutputDir.exists()) {134 TestDataOutputDir.mkdirs();135 }136 this.outputConfig.put("outputDir",137 System.getProperty("output.path"));138 this.outputConfig.put("ExecutionStatus", "started");139 this.outputConfig.put("Started_Time",140 new SimpleDateFormat("E_yyyy.MM.dd_HH.mm.ss_z").format(new Date()));141 generateRunConfig();142 outputDirExist = true;143 }144 Log.info("About to begin executing Suite " + arg0.getName());145 System.setProperty("suitename", arg0.getName());146 String threadCount = System.getProperty("threadCount");147 // Setting the environment parameters148 if (threadCount != null) {149 arg0.getXmlSuite().setThreadCount(Integer.parseInt(threadCount));150 arg0.getXmlSuite().setPreserveOrder(true);151 }152 suites.add(arg0);153 }154 @Override155 // This belongs to ISuiteListener and will execute, once the Suite is156 // finished157 public void onFinish(ISuite arg0) {158 if (resultGenerationMode == Listener.ResultGenerationMode.AFTER_SUITE) {159 generateReport();160 }161 }162 private void generateReport() {163 String outDir = config.getOutputDirectory();164 if (outDir == null || outDir.isEmpty()) {165 outDir = "test-output";166 }167 generateReport(null, suites, outDir);168 }169 // This belongs to ITestListener and will execute before starting of Test170 // set/batch171 @Override172 public void onStart(ITestContext arg0) {173 Log.startTestCase(arg0.getName());174 Log.info("About to begin executing Test " + arg0.getName());175 //find out Test Case ID and set in threadLocal for DriverFactory to set up tag176 Pattern testIDpattern = Pattern.compile(TEST_CASE_ID_PATTERN);177 Matcher matcher = testIDpattern.matcher(arg0.getName());178 if (matcher.find()) {179 Log.info("@@@Test Case ID: " + matcher.group(0));180 context.set(matcher.group(0));181 }182 }183 // This belongs to ITestListener and will execute, once the Test set/batch184 // is finished185 @Override186 public void onFinish(ITestContext arg0) {187 Log.info("Completed executing test " + arg0.getName());188 Log.endTestCase(arg0.getName());189 }190 // This belongs to ITestListener and will execute only when the test is passed191 @Override192 public void onTestSuccess(ITestResult arg0) {193 printTestResults(arg0);194 }195 // This belongs to ITestListener and will execute only when the test is failed196 @Override197 public void onTestFailure(ITestResult arg0) {198 printTestResults(arg0);199 }200 // This belongs to ITestListener and will execute before the main test start201 // (@Test)202 @Override203 public void onTestStart(ITestResult arg0) {204 currentScreenshotPath = null;205 Object currentClass = arg0.getInstance();206 try {207 RemoteWebDriver driver = (RemoteWebDriver) ContextProvider.getDriver();208 if (driver != null) {209 Log.info("Test started on the following configuration " + driver.getCapabilities().toString());210 // Add run configuration211 arg0.setAttribute("configuration::Browser", System.getProperty("mbrowserfullname"));212 arg0.setAttribute("configuration::Platform", System.getProperty("mplatformfullname"));213 arg0.setAttribute("configuration::Environment", System.getProperty("menv"));214 setGenerateTestResultAttributes(true);215 }216 } catch (Exception e) {217 // do nothing.218 }219 }220 // This belongs to ITestListener and will execute only if any of the main221 // test(@Test) get skipped222 @Override223 public void onTestSkipped(ITestResult arg0) {224 Log.info("Skipping Test");225 printTestResults(arg0);226 }227 @Override228 public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {229 //Not implemented at the moment230 }231 // This belongs to IInvokedMethodListener and will execute before every232 // method including @Before @After @Test233 @Override234 public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) {235 Log.info("Started execution of the following method: "236 + returnMethodName(arg0.getTestMethod()));237 }238 // This belongs to IInvokedMethodListener and will execute after every239 // method including @Before @After @Test240 @Override241 public void afterInvocation(IInvokedMethod arg0, ITestResult arg1) {242 if (processFail) {243 if (arg1.getStatus() == ITestResult.FAILURE)244 updateResultWithScreenshot(arg1);245 }246 try {247 ITestNGMethod testMethod = arg0.getTestMethod();248 if (resultGenerationMode == Listener.ResultGenerationMode.AFTER_CLASS249 && testMethod.isAfterClassConfiguration() && !testMethod.hasMoreInvocation()) {250 generateReport();251 } else if (resultGenerationMode == Listener.ResultGenerationMode.AFTER_TEST && testMethod.isTest()) {252 generateReport();253 }254 if (!arg1.getMethod().isTest()) {255 printTestResults(arg1);256 }257 } catch (Exception e) {258 e.printStackTrace();259 }260 }261 @Override262 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,263 String outputDirectory) {264 if (Utils.isStringEmpty(config.getOutputDirectory())) {265 config.setOutputDirectory(outputDirectory);266 }267 // Calculate passed/failed/skipped268 int passed = 0;269 int failed = 0;270 int skipped = 0;271 for (ISuite s : suites) {272 Map<String, ISuiteResult> suiteResults = s.getResults();273 synchronized (suiteResults) {274 for (ISuiteResult sr : suiteResults.values()) {275 ITestContext testContext = sr.getTestContext();276 passed += testContext.getPassedTests().size();277 failed += testContext.getFailedTests().size();278 skipped += testContext.getSkippedTests().size();279 }280 }281 }282 rootBuffer = new XMLStringBuffer();283 Properties p = new Properties();284 p.put("passed", passed);285 p.put("failed", failed);286 p.put("skipped", skipped);287 p.put("total", passed + failed + skipped);288 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);289 // skipped the full report-output in favor of individual suite290 // output291 // writeReporterOutput(rootBuffer);292 for (ISuite suite : suites) {293 writeSuite(suite.getXmlSuite(), suite);294 }295 rootBuffer.pop();296 if (config.getOutputDirectory().contains("surefire-reports"))297 Utils.writeUtf8File("test-output", FILE_NAME, rootBuffer,298 null /* no prefix */);299 Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer,300 null /* no prefix */);301 }302 /**303 * This method is used to spit out the first cummulative reporter-outut304 * It's not being used right now in favor of the individual reporter-output305 * for each suite306 *307 * @param xmlBuffer308 */309 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {310 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);311 List<String> output = Reporter.getOutput();312 for (String line : output) {313 if (line != null) {314 xmlBuffer.push(XMLReporterConfig.TAG_LINE);315 xmlBuffer.addCDATA(XMLSuiteResultWriter.filterInvalidChars(line));316 xmlBuffer.pop();317 }318 }319 xmlBuffer.pop();320 }321 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {322 switch (config.getFileFragmentationLevel()) {323 case XMLReporterConfig.FF_LEVEL_NONE:324 writeSuiteToBuffer(rootBuffer, suite);325 break;326 case XMLReporterConfig.FF_LEVEL_SUITE:327 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:328 File suiteFile = referenceSuite(rootBuffer, suite);329 writeSuiteToFile(suiteFile, suite);330 break;331 default:332 throw new AssertionError("Unexpected value: "333 + config.getFileFragmentationLevel());334 }335 }336 private void writeSuiteToFile(File suiteFile, ISuite suite) {337 XMLStringBuffer xmlBuffer = new XMLStringBuffer();338 writeSuiteToBuffer(xmlBuffer, suite);339 File parentDir = suiteFile.getParentFile();340 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {341 Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME,342 xmlBuffer.toXML());343 }344 }345 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {346 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;347 File suiteFile = new File(config.getOutputDirectory(), relativePath);348 Properties attrs = new Properties();349 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);350 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);351 return suiteFile;352 }353 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {354 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));355 writeSuiteGroups(xmlBuffer, suite);356 Map<String, ISuiteResult> results = suite.getResults();357 XMLSuiteResultWriter suiteResultWriter = getSuiteResultWriter();358 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {359 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());360 }361 xmlBuffer.pop();362 }363 protected XMLSuiteResultWriter getSuiteResultWriter() {364 return new XMLSuiteResultWriter(config);365 }366 private void generateRunConfig() {367 try {368 Properties properties = new Properties();369 for (String key : this.outputConfig.keySet()) {370 properties.setProperty(key, this.outputConfig.get(key));371 }372 File file = new File("runConfiguration.properties");373 FileOutputStream fileOut = new FileOutputStream(file);374 properties.store(fileOut, "Framework Run Configuration");375 fileOut.close();376 } catch (IOException e) {377 e.printStackTrace();378 }...

Full Screen

Full Screen

Source:XMLSuiteResultWriter.java Github

copy

Full Screen

...17 * Utility writing an ISuiteResult to an XMLStringBuffer. Depending on the settings in the <code>config</code> property18 * it might generate an additional XML file with the actual content and only reference the file with an <code>url</code>19 * attribute in the passed XMLStringBuffer.20 */21public class XMLSuiteResultWriter {22 protected XMLReporterConfig config;23 protected final int STACKTRACE_SHORT = 1;24 protected final int STACKTRACE_FULL = 2;25 public XMLSuiteResultWriter(XMLReporterConfig config) {26 this.config = config;27 }28 /**29 * Writes the specified ISuiteResult in the given XMLStringBuffer. Please consider that depending on the settings in30 * the <code>config</code> property it might generate an additional XML file with the actual content and only31 * reference the file with an <code>url</code> attribute in the passed XMLStringBuffer.32 *33 * @param xmlBuffer The XML buffer where to write or reference the suite result34 * @param suiteResult The <code>ISuiteResult</code> to serialize35 */36 public void writeSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {37 if (XMLReporterConfig.FF_LEVEL_SUITE_RESULT != config.getFileFragmentationLevel()) {38 writeAllToBuffer(xmlBuffer, suiteResult);39 } else {...

Full Screen

Full Screen

Source:CustomXMLReporter.java Github

copy

Full Screen

...12import org.testng.Reporter;13import org.testng.internal.Utils;14import org.testng.reporters.XMLReporterConfig;15import org.testng.reporters.XMLStringBuffer;16import org.testng.reporters.XMLSuiteResultWriter;17import org.testng.xml.XmlSuite;18import java.io.File;19import java.io.IOException;20import java.text.SimpleDateFormat;21import java.util.Collection;22import java.util.Date;23import java.util.LinkedHashSet;24import java.util.List;25import java.util.Map;26import java.util.Properties;27import java.util.Set;28import java.util.TimeZone;29/**30 * The main entry for the XML generation operation31 *32 * @author Cosmin Marginean, Mar 16, 200733 */34public class CustomXMLReporter implements IReporter {35 public static final String FILE_NAME = "testng-results.xml";36 private final XMLReporterConfig config = new XMLReporterConfig();37 private XMLStringBuffer rootBuffer;38 @Override39 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,40 String outputDirectory) {41 if (Utils.isStringEmpty(config.getOutputDirectory())) {42 config.setOutputDirectory(outputDirectory);43 }44 // Calculate passed/failed/skipped45 int passed = 0;46 int failed = 0;47 int skipped = 0;48 int ignored = 0;49 for (ISuite s : suites) {50 Map<String, ISuiteResult> suiteResults = s.getResults();51 synchronized(suiteResults) {52 for (ISuiteResult sr : suiteResults.values()) {53 ITestContext testContext = sr.getTestContext();54 passed += testContext.getPassedTests().size();55 failed += testContext.getFailedTests().size();56 skipped += testContext.getSkippedTests().size();57 ignored += testContext.getExcludedMethods().size();58 }59 }60 }61 rootBuffer = new XMLStringBuffer();62 Properties p = new Properties();63 p.put("passed", passed);64 p.put("failed", failed);65 p.put("skipped", skipped);66 p.put("ignored", ignored);67 p.put("buildNo",VBIConfig.buildNo);68 p.put("testMode",VBIConfig.testMode);69 p.put("browserstackEnvironment",VBIConfig.browserstackEnvironment);70 p.put("total", passed + failed + skipped + ignored);71 if(VBIConfig.testMode.equals("report"))72 try {73 AutomatedPropertiesReport.writeToFile();74 } catch (IOException e) {75 e.printStackTrace();76 }77 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);78 writeReporterOutput(rootBuffer);79 for (ISuite suite : suites) {80 writeSuite(suite.getXmlSuite(), suite);81 }82 rootBuffer.pop();83 Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer, null /* no prefix */);84 try {85 TestNgReportBuilderCli.generateReport();86 } catch (Exception e) {87 e.printStackTrace();88 }89 }90 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {91 // TODO: Cosmin - maybe a <line> element isn't indicated for each line92 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);93 List<String> output = Reporter.getOutput();94 for (String line : output) {95 if (line != null) {96 xmlBuffer.push(XMLReporterConfig.TAG_LINE);97 xmlBuffer.addCDATA(line);98 xmlBuffer.pop();99 }100 }101 xmlBuffer.pop();102 }103 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {104 switch (config.getFileFragmentationLevel()) {105 case XMLReporterConfig.FF_LEVEL_NONE:106 writeSuiteToBuffer(rootBuffer, suite);107 break;108 case XMLReporterConfig.FF_LEVEL_SUITE:109 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:110 File suiteFile = referenceSuite(rootBuffer, suite);111 writeSuiteToFile(suiteFile, suite);112 break;113 default:114 throw new AssertionError("Unexpected value: " + config.getFileFragmentationLevel());115 }116 }117 private void writeSuiteToFile(File suiteFile, ISuite suite) {118 XMLStringBuffer xmlBuffer = new XMLStringBuffer();119 writeSuiteToBuffer(xmlBuffer, suite);120 File parentDir = suiteFile.getParentFile();121 suiteFile.getParentFile().mkdirs();122 if (parentDir.exists() || suiteFile.getParentFile().exists()) {123 Utils.writeUtf8File(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());124 }125 try {126 TestNgReportBuilderCli.generateReport();127 } catch (Exception e) {128 e.printStackTrace();129 }130 }131 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {132 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;133 File suiteFile = new File(config.getOutputDirectory(), relativePath);134 Properties attrs = new Properties();135 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);136 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);137 return suiteFile;138 }139 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {140 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));141 writeSuiteGroups(xmlBuffer, suite);142 Map<String, ISuiteResult> results = suite.getResults();143 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);144 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {145 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());146 }147 xmlBuffer.pop();148 }149 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {150 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);151 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();152 for (Map.Entry<String, Collection<ITestNGMethod>> entry : methodsByGroups.entrySet()) {153 Properties groupAttrs = new Properties();154 groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, entry.getKey());155 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);156 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(entry.getValue());157 for (ITestNGMethod groupMethod : groupMethods) {...

Full Screen

Full Screen

Source:CustomTestNgReporter.java Github

copy

Full Screen

...26import org.testng.internal.ResultMap;27import org.testng.internal.Utils;28import org.testng.reporters.XMLReporterConfig;29import org.testng.reporters.XMLStringBuffer;30import org.testng.reporters.XMLSuiteResultWriter;31import org.testng.xml.XmlSuite;32import java.io.File;33import java.text.SimpleDateFormat;34import java.util.Collection;35import java.util.Date;36import java.util.HashMap;37import java.util.LinkedHashSet;38import java.util.List;39import java.util.Map;40import java.util.Properties;41import java.util.Set;42public class CustomTestNgReporter implements IReporter {43 private final XMLReporterConfig config = new XMLReporterConfig();44 private XMLStringBuffer rootBuffer;45 ITestContext testRootContext = null;46 ISuite testRootSuite = null;47 Exception exception = null;48 public CustomTestNgReporter(ITestContext context, Exception e) {49 testRootContext = context;50 exception = e;51 }52 public CustomTestNgReporter(ISuite suite, Exception e) {53 testRootSuite = suite;54 exception = e;55 }56 public CustomTestNgReporter(ITestContext context) {57 testRootContext = context;58 exception = null;59 }60 public CustomTestNgReporter(ISuite suite) {61 testRootSuite = suite;62 exception = null;63 }64 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,65 String outputDirectory) {66 if (Utils.isStringEmpty(config.getOutputDirectory())) {67 config.setOutputDirectory(outputDirectory);68 }69 rootBuffer = new XMLStringBuffer("");70 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS);71 writeReporterOutput(rootBuffer);72 for (int i = 0; i < suites.size(); i++) {73 writeSuite(suites.get(i).getXmlSuite(), suites.get(i));74 }75 rootBuffer.pop();76 Utils.writeUtf8File(config.getOutputDirectory(), "testng-results.xml", rootBuffer.toXML());77 }78 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {79 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);80 List<String> output = Reporter.getOutput();81 for (String line : output) {82 if (line != null) {83 xmlBuffer.push(XMLReporterConfig.TAG_LINE);84 xmlBuffer.addCDATA(line);85 xmlBuffer.pop();86 }87 }88 xmlBuffer.pop();89 }90 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {91 switch (config.getFileFragmentationLevel()) {92 case XMLReporterConfig.FF_LEVEL_NONE:93 writeSuiteToBuffer(rootBuffer, suite);94 break;95 case XMLReporterConfig.FF_LEVEL_SUITE:96 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:97 File suiteFile = referenceSuite(rootBuffer, suite);98 writeSuiteToFile(suiteFile, suite);99 }100 }101 private void writeSuiteToFile(File suiteFile, ISuite suite) {102 XMLStringBuffer xmlBuffer = new XMLStringBuffer("");103 writeSuiteToBuffer(xmlBuffer, suite);104 File parentDir = suiteFile.getParentFile();105 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {106 Utils.writeFile(parentDir.getAbsolutePath(), "testng-results.xml", xmlBuffer.toXML());107 }108 }109 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {110 String relativePath = suite.getName() + File.separatorChar + "testng-results.xml";111 File suiteFile = new File(config.getOutputDirectory(), relativePath);112 Properties attrs = new Properties();113 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);114 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);115 return suiteFile;116 }117 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, final ISuite suite) {118 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));119 writeSuiteGroups(xmlBuffer, suite);120 final ISuite iSuite = suite;121 final ITestContext testContext2 = testRootContext;122 final IResultMap resultMap = new ResultMap();123 CustomTestngResults results2 = new CustomTestngResults();124 ISuiteResult iSuiteResult = new ISuiteResult() {125 public String getPropertyFileName() {126 return iSuite.getXmlSuite().getFileName();127 }128 public ITestContext getTestContext() {129 return testRootContext;130 }131 };132 final Map<String, ISuiteResult> results = new HashMap<String, ISuiteResult>();133 results.put("Test", iSuiteResult);134 final Map<String, ISuiteResult> resultsFinal = results;135 ReportSuiteSetter suiteSetter = new ReportSuiteSetter();136 ISuite newSuite = suite;137 for (ITestNGMethod method : suite.getAllMethods()) {138 resultMap.addResult(results2.setResults(newSuite, method, 2, exception), method);139 }140 final IResultMap reportmap = resultMap;141 final ISuite reportsuite = newSuite;142 // ReportContextSetter contextSetter = new ReportContextSetter();143 // testRootContext = contextSetter.setContext(testContext2, resultMap, newSuite);144 ISuiteResult iSuiteResult2 = new ISuiteResult() {145 public String getPropertyFileName() {146 return reportsuite.getXmlSuite().getFileName();147 }148 public ITestContext getTestContext() {149 return testRootContext;150 }151 };152 final Map<String, ISuiteResult> reportResults1 = new HashMap<String, ISuiteResult>();153 reportResults1.put("Test", iSuiteResult2);154 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);155 if (testContext2 != null) {156 for (Map.Entry<String, ISuiteResult> result : reportResults1.entrySet()) {157 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());158 }159 } else {160 for (Map.Entry<String, ISuiteResult> result : newSuite.getResults().entrySet()) {161 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());162 }163 }164 xmlBuffer.pop();165 }166 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {167 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);168 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();...

Full Screen

Full Screen

Source:GeneratePassedReports.java Github

copy

Full Screen

...7import org.testng.Reporter;8import org.testng.internal.Utils;9import org.testng.reporters.XMLReporterConfig;10import org.testng.reporters.XMLStringBuffer;11import org.testng.reporters.XMLSuiteResultWriter;12import org.testng.xml.XmlSuite;13import java.io.File;14import java.text.SimpleDateFormat;15import java.util.Collection;16import java.util.Date;17import java.util.LinkedHashSet;18import java.util.List;19import java.util.Map;20import java.util.Properties;21import java.util.Set;22import java.util.TimeZone;23/**24 * The main entry for the XML generation operation25 * 26 * @author Cosmin Marginean, Mar 16, 200727 */28public class GeneratePassedReports implements IReporter {29 public static final String FILE_NAME = "testng-results.xml";30 private final XMLReporterConfig config = new XMLReporterConfig();31 private XMLStringBuffer rootBuffer;32 @Override33 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,34 String outputDirectory) {35 if (Utils.isStringEmpty(config.getOutputDirectory())) {36 config.setOutputDirectory(outputDirectory);37 }38 // Calculate passed/failed/skipped39 int passed = 0;40 int failed = 0;41 int skipped = 0;42 for (ISuite s : suites) {43 for (ISuiteResult sr : s.getResults().values()) {44 ITestContext testContext = sr.getTestContext();45 passed += testContext.getPassedTests().size();46 failed += testContext.getFailedTests().size();47 skipped += testContext.getSkippedTests().size();48 }49 }50 rootBuffer = new XMLStringBuffer();51 Properties p = new Properties();52 p.put("passed", passed);53 p.put("failed", failed);54 p.put("skipped", skipped);55 p.put("total", passed + failed + skipped);56 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);57 writeReporterOutput(rootBuffer);58 for (int i = 0; i < suites.size(); i++) {59 writeSuite(suites.get(i).getXmlSuite(), suites.get(i));60 }61 rootBuffer.pop();62 Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer.toXML());63 }64 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {65 // TODO: Cosmin - maybe a <line> element isn't indicated for each line66 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);67 List<String> output = Reporter.getOutput();68 for (String line : output) {69 if (line != null) {70 xmlBuffer.push(XMLReporterConfig.TAG_LINE);71 xmlBuffer.addCDATA(line.replace("&amp;", ""));72 xmlBuffer.pop();73 }74 }75 xmlBuffer.pop();76 }77 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {78 switch (config.getFileFragmentationLevel()) {79 case XMLReporterConfig.FF_LEVEL_NONE:80 writeSuiteToBuffer(rootBuffer, suite);81 break;82 case XMLReporterConfig.FF_LEVEL_SUITE:83 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:84 File suiteFile = referenceSuite(rootBuffer, suite);85 writeSuiteToFile(suiteFile, suite);86 }87 }88 private void writeSuiteToFile(File suiteFile, ISuite suite) {89 XMLStringBuffer xmlBuffer = new XMLStringBuffer();90 writeSuiteToBuffer(xmlBuffer, suite);91 File parentDir = suiteFile.getParentFile();92 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {93 Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());94 }95 }96 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {97 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;98 File suiteFile = new File(config.getOutputDirectory(), relativePath);99 Properties attrs = new Properties();100 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);101 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);102 return suiteFile;103 }104 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {105 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));106 writeSuiteGroups(xmlBuffer, suite);107 Map<String, ISuiteResult> results = suite.getResults();108 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);109 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {110 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());111 }112 xmlBuffer.pop();113 }114 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {115 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);116 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();117 for (Map.Entry<String, Collection<ITestNGMethod>> entry : methodsByGroups.entrySet()) {118 Properties groupAttrs = new Properties();119 groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, entry.getKey());120 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);121 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(entry.getValue());122 for (ITestNGMethod groupMethod : groupMethods) {...

Full Screen

Full Screen

Source:XMLReporter.java Github

copy

Full Screen

...16import org.testng.Reporter;17import org.testng.internal.Utils;18import org.testng.reporters.XMLReporterConfig;19import org.testng.reporters.XMLStringBuffer;20import org.testng.reporters.XMLSuiteResultWriter;21import org.testng.xml.XmlSuite;22import com.wooplr.base.controller.ContextManager;23import com.wooplr.base.controller.Logging;24/**25 * The main entry for the XML generation operation26 */27public class XMLReporter implements IReporter {28 private static Logger logger = Logging.getLogger(XMLReporter.class);29 private XMLReporterConfig config = new XMLReporterConfig();30 private XMLStringBuffer rootBuffer;31 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {32 if (Utils.isStringEmpty(config.getOutputDirectory())) {33 config.setOutputDirectory(outputDirectory);34 }35 rootBuffer = new XMLStringBuffer("");36 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS);37 writeReporterOutput(rootBuffer);38 for (int i = 0; i < suites.size(); i++) {39 writeSuite(xmlSuites.get(i), suites.get(i));40 }41 rootBuffer.pop();42 // Utils.writeUtf8File(config.getOutputDirectory(),43 // "testng-results-spire.xml", rootBuffer.toXML());44 try {45 Utils.writeUtf8File(ContextManager.getGlobalContext().getOutputDirectory(), "testng-results-spire.xml", rootBuffer.toXML());46 } catch (Throwable e) {47 logger.warn("Ex", e);48 }49 }50 // TODO: This is not the smartest way to implement the config51 public int getFileFragmentationLevel() {52 return config.getFileFragmentationLevel();53 }54 public String getOutputDirectory() {55 return config.getOutputDirectory();56 }57 public int getStackTraceOutputMethod() {58 return config.getStackTraceOutputMethod();59 }60 private Properties getSuiteAttributes(ISuite suite) {61 Properties props = new Properties();62 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());63 return props;64 }65 public String getTimestampFormat() {66 return XMLReporterConfig.getTimestampFormat();67 }68 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {69 Set<ITestNGMethod> result = new LinkedHashSet<ITestNGMethod>();70 for (ITestNGMethod method : methods) {71 result.add(method);72 }73 return result;74 }75 public boolean isGenerateDependsOnGroups() {76 return config.isGenerateDependsOnGroups();77 }78 public boolean isGenerateDependsOnMethods() {79 return config.isGenerateDependsOnMethods();80 }81 public boolean isGenerateGroupsAttribute() {82 return config.isGenerateGroupsAttribute();83 }84 public boolean isSplitClassAndPackageNames() {85 return config.isSplitClassAndPackageNames();86 }87 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {88 String relativePath = suite.getName() + File.separatorChar + "testng-results.xml";89 File suiteFile = new File(config.getOutputDirectory(), relativePath);90 Properties attrs = new Properties();91 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);92 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);93 return suiteFile;94 }95 public void setFileFragmentationLevel(int fileFragmentationLevel) {96 config.setFileFragmentationLevel(fileFragmentationLevel);97 }98 public void setGenerateDependsOnGroups(boolean generateDependsOnGroups) {99 config.setGenerateDependsOnGroups(generateDependsOnGroups);100 }101 public void setGenerateDependsOnMethods(boolean generateDependsOnMethods) {102 config.setGenerateDependsOnMethods(generateDependsOnMethods);103 }104 public void setGenerateGroupsAttribute(boolean generateGroupsAttribute) {105 config.setGenerateGroupsAttribute(generateGroupsAttribute);106 }107 public void setOutputDirectory(String outputDirectory) {108 config.setOutputDirectory(outputDirectory);109 }110 public void setSplitClassAndPackageNames(boolean splitClassAndPackageNames) {111 config.setSplitClassAndPackageNames(splitClassAndPackageNames);112 }113 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {114 config.setStackTraceOutputMethod(stackTraceOutputMethod);115 }116 public void setTimestampFormat(String timestampFormat) {117 config.setTimestampFormat(timestampFormat);118 }119 private void writePoolBuildInformation(ISuite suite, XMLStringBuffer xmlBuffer) {120 Properties prop = new Properties();121 prop.put("user", System.getProperty("user.name"));122 try {123 prop.put("host", InetAddress.getLocalHost().getCanonicalHostName());124 } catch (UnknownHostException e) {125 }126 // List<BugfoeTestMethodIgnore> ignoreList =127 // AbstractStep.getIgnoreList();128 //129 // Set<ITestResult> failedSet = ctx.getFailedTests().getAllResults();130 // for (ITestResult testResult : failedSet) {131 // Method method = testResult.getMethod().getMethod();132 // for (BugfoeTestMethodIgnore ignoredMethod : ignoreList) {133 // if(ignoredMethod.getMethodSignature().equals(method.getDeclaringClass().getCanonicalName()134 // + "." + method.getName())){135 //136 // }137 // }138 // }139 // prop.put("title", (String)140 // ContextManager.getGlobalContext().getAttribute(Context.REPORT_TITLE));141 // prop.put("hub",142 // ContextManager.getGlobalContext().getAttribute(Context.SELENIUM_HUB));143 prop.put("pool", ContextManager.getGlobalContext().getPool());144 // prop.put("runid", (String)145 // ContextManager.getGlobalContext().getAttribute(Context.RUN_ID));146 prop.put("runstatus", "");147 // prop.put("buildid", (String)148 // ContextManager.getGlobalContext().getAttribute(Context.BUILD_ID));149 // prop.put("buildtag", (String)150 // ContextManager.getGlobalContext().getAttribute(Context.BUILD_TAG));151 xmlBuffer.push("bugfoe-run-info", prop);152 xmlBuffer.push("config-spec");153 // xmlBuffer.addCDATA((String)154 // ContextManager.getGlobalContext().getAttribute(Context.BUILD_CONFIG_SPEC));155 xmlBuffer.pop();156 xmlBuffer.pop();157 }158 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {159 // TODO: Cosmin - maybe a <line> element isn't indicated for each line.160 // Also escaping might be considered161 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);162 List<String> output = Reporter.getOutput();163 for (String line : output) {164 xmlBuffer.push(XMLReporterConfig.TAG_LINE);165 xmlBuffer.addCDATA(line);166 xmlBuffer.pop();167 }168 xmlBuffer.pop();169 }170 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {171 switch (config.getFileFragmentationLevel()) {172 case XMLReporterConfig.FF_LEVEL_NONE:173 writeSuiteToBuffer(rootBuffer, suite);174 break;175 case XMLReporterConfig.FF_LEVEL_SUITE:176 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:177 File suiteFile = referenceSuite(rootBuffer, suite);178 writeSuiteToFile(suiteFile, suite);179 }180 }181 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {182 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);183 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();184 for (String groupName : methodsByGroups.keySet()) {185 Properties groupAttrs = new Properties();186 groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupName);187 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);188 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(methodsByGroups.get(groupName));189 for (ITestNGMethod groupMethod : groupMethods) {190 Properties methodAttrs = new Properties();191 methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupMethod.getMethodName());192 methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, groupMethod.toString());193 methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, groupMethod.getRealClass().getName());194 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD, methodAttrs);195 }196 xmlBuffer.pop();197 }198 xmlBuffer.pop();199 }200 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {201 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));202 writePoolBuildInformation(suite, rootBuffer);203 writeSuiteGroups(xmlBuffer, suite);204 Map<String, ISuiteResult> results = suite.getResults();205 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);206 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {207 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());208 }209 xmlBuffer.pop();210 }211 private void writeSuiteToFile(File suiteFile, ISuite suite) {212 XMLStringBuffer xmlBuffer = new XMLStringBuffer("");213 writeSuiteToBuffer(xmlBuffer, suite);214 File parentDir = suiteFile.getParentFile();215 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {216 Utils.writeFile(parentDir.getAbsolutePath(), "testng-results.xml", xmlBuffer.toXML());217 }218 }219}...

Full Screen

Full Screen

Source:EMReporter.java Github

copy

Full Screen

...7import org.testng.Reporter;8import org.testng.internal.Utils;9import org.testng.reporters.XMLReporterConfig;10import org.testng.reporters.XMLStringBuffer;11import org.testng.reporters.XMLSuiteResultWriter;12import org.testng.xml.XmlSuite;13import java.io.File;14import java.text.SimpleDateFormat;15import java.util.Collection;16import java.util.Date;17import java.util.LinkedHashSet;18import java.util.List;19import java.util.Map;20import java.util.Properties;21import java.util.Set;22/**23 * The main entry for the XML generation operation24 *25 * @author 26 */27public class EMReporter implements IReporter {28 private final XMLReporterConfig config = new XMLReporterConfig();29 private XMLStringBuffer rootBuffer;30 @Override31 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {32 // if output directory not set, then set it.33 System.out.println("Sundeep the directory s " + config.getOutputDirectory() + outputDirectory);34 if (Utils.isStringEmpty(config.getOutputDirectory())) {35 config.setOutputDirectory(outputDirectory);36 }37 rootBuffer = new XMLStringBuffer("");38 rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS);39 writeReporterOutput(rootBuffer);40 for (int i = 0; i < suites.size(); i++) {41 writeSuite(suites.get(i).getXmlSuite(), suites.get(i));42 }43 44 rootBuffer.pop();45 Utils.writeUtf8File(config.getOutputDirectory(), "abeer-results.xml", rootBuffer.toXML());46 }47 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {48 //TODO: Cosmin - maybe a <line> element isn't indicated for each line49 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);50 List<String> output = Reporter.getOutput();51 for (String line : output) {52 if (line != null) {53 xmlBuffer.push(XMLReporterConfig.TAG_LINE);54 xmlBuffer.addCDATA(line);55 xmlBuffer.pop();56 }57 }58 xmlBuffer.pop();59 }60 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {61 System.out.println("Value of FF" + config.getFileFragmentationLevel());62 switch (config.getFileFragmentationLevel()) {63 case XMLReporterConfig.FF_LEVEL_NONE:64 writeSuiteToBuffer(rootBuffer, suite);65 break;66 case XMLReporterConfig.FF_LEVEL_SUITE:67 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:68 File suiteFile = referenceSuite(rootBuffer, suite);69 writeSuiteToFile(suiteFile, suite);70 }71 }72 private void writeSuiteToFile(File suiteFile, ISuite suite) {73 XMLStringBuffer xmlBuffer = new XMLStringBuffer("");74 writeSuiteToBuffer(xmlBuffer, suite);75 File parentDir = suiteFile.getParentFile();76 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {77 Utils.writeFile(parentDir.getAbsolutePath(), "testng-results.xml", xmlBuffer.toXML());78 }79 }80 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {81 String relativePath = suite.getName() + File.separatorChar + "testng-results.xml";82 File suiteFile = new File(config.getOutputDirectory(), relativePath);83 Properties attrs = new Properties();84 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);85 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);86 return suiteFile;87 }88 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {89 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));90 writeSuiteGroups(xmlBuffer, suite);91 92 Map<String, ISuiteResult> results = suite.getResults();93 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);94 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {95 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());96 }97 xmlBuffer.pop();98 }99 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {100 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);101 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();102 for (String groupName : methodsByGroups.keySet()) {103 Properties groupAttrs = new Properties();104 //groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupName);105 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);106 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(methodsByGroups.get(groupName));107 System.out.println("Group Lengths is " + groupName + groupMethods.size());...

Full Screen

Full Screen

Source:cdf15.java Github

copy

Full Screen

1diff --git a/src/main/org/testng/reporters/XMLSuiteResultWriter.java b/src/main/org/testng/reporters/XMLSuiteResultWriter.java2index 175b783..1d04168 1006443--- a/src/main/org/testng/reporters/XMLSuiteResultWriter.java4+++ b/src/main/org/testng/reporters/XMLSuiteResultWriter.java5@@ -231,7 +231,7 @@6 xmlBuffer.pop();7 }8 9- String[] stackTraces = Utils.stackTrace(exception, true);10+ String[] stackTraces = Utils.stackTrace(exception, false);11 if ((config.getStackTraceOutputMethod() & XMLReporterConfig.STACKTRACE_SHORT) == XMLReporterConfig12 .STACKTRACE_SHORT) {13 xmlBuffer.push(XMLReporterConfig.TAG_SHORT_STACKTRACE);...

Full Screen

Full Screen

XMLSuiteResultWriter

Using AI Code Generation

copy

Full Screen

1public void test() {2 TestNG testNG = new TestNG();3 testNG.setTestClasses(new Class[]{TestNGTest.class});4 testNG.setOutputDirectory("test-output");5 testNG.setXmlSuites(Arrays.asList(getXmlSuite()));6 testNG.run();7}8private XmlSuite getXmlSuite() {9 XmlSuite xmlSuite = new XmlSuite();10 xmlSuite.setName("TestNGTest");11 xmlSuite.setParallel(XmlSuite.ParallelMode.TESTS);12 xmlSuite.setThreadCount(3);13 xmlSuite.setVerbose(2);14 xmlSuite.setListeners(Arrays.asList(TestNGTest.class.getName()));15 xmlSuite.setXmlPackages(Arrays.asList(getXmlPackage()));16 return xmlSuite;17}18private XmlPackage getXmlPackage() {19 XmlPackage xmlPackage = new XmlPackage();20 xmlPackage.setName("org.example.test");21 return xmlPackage;22}23public void test() {24 TestNG testNG = new TestNG();25 testNG.setTestClasses(new Class[]{TestNGTest.class});26 testNG.setOutputDirectory("test-output");27 testNG.setXmlSuites(Arrays.asList(getXmlSuite()));28 testNG.run();29}30private XmlSuite getXmlSuite() {31 XmlSuite xmlSuite = new XmlSuite();32 xmlSuite.setName("TestNGTest");33 xmlSuite.setParallel(XmlSuite.ParallelMode.TESTS);34 xmlSuite.setThreadCount(3);35 xmlSuite.setVerbose(2);36 xmlSuite.setListeners(Arrays.asList(TestNGTest.class.getName()));37 xmlSuite.setXmlPackages(Arrays.asList(getXmlPackage()));38 return xmlSuite;39}40private XmlPackage getXmlPackage() {41 XmlPackage xmlPackage = new XmlPackage();42 xmlPackage.setName("org.example.test");43 return xmlPackage;44}45public void test() {46 TestNG testNG = new TestNG();47 testNG.setTestClasses(new Class[]{TestNGTest.class});48 testNG.setOutputDirectory("test-output");49 testNG.setXmlSuites(Arrays.asList(getXmlSuite()));50 testNG.run();51}52private XmlSuite getXmlSuite() {53 XmlSuite xmlSuite = new XmlSuite();54 xmlSuite.setName("TestNGTest");55 xmlSuite.setParallel(XmlSuite.ParallelMode.TESTS);56 xmlSuite.setThreadCount(3);57 xmlSuite.setVerbose(2);58 xmlSuite.setListeners(Arrays.asList(TestNGTest.class.getName()));59 xmlSuite.setXmlPackages(Arrays.asList(get

Full Screen

Full Screen
copy
1public final <T extends Throwable> T expectException( Class<T> exceptionClass, Runnable runnable )2{3 try4 {5 runnable.run();6 }7 catch( Throwable throwable )8 {9 if( throwable instanceof AssertionError && throwable.getCause() != null )10 throwable = throwable.getCause(); //allows testing for "assert x != null : new IllegalArgumentException();"11 assert exceptionClass.isInstance( throwable ) : throwable; //exception of the wrong kind was thrown.12 assert throwable.getClass() == exceptionClass : throwable; //exception thrown was a subclass, but not the exact class, expected.13 @SuppressWarnings( "unchecked" )14 T result = (T)throwable;15 return result;16 }17 assert false; //expected exception was not thrown.18 return null; //to keep the compiler happy.19}20
Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on XMLSuiteResultWriter

Most used methods in XMLSuiteResultWriter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful