How to use fileName method of org.testng.reporters.XMLReporter class

Best Testng code snippet using org.testng.reporters.XMLReporter.fileName

Source:CustomReportListener.java Github

copy

Full Screen

1import java.io.File;2import java.io.IOException;3import java.util.List;4import java.util.Collection;5import java.util.Map;6import java.util.Properties;7import java.util.SortedMap;8import java.util.SortedSet;9import java.util.TreeMap;10import java.util.TreeSet;11import javax.mail.Session;12import java.util.Comparator;13import java.util.ArrayList;14import java.util.Collections;15import org.apache.velocity.VelocityContext;16import org.testng.ISuite;17import org.testng.ISuiteResult;18import org.testng.ITestNGMethod;19import org.testng.Reporter;20import org.testng.IClass;21import org.testng.IReporter;22import org.testng.ITestResult;23import org.testng.IResultMap;24import org.testng.xml.XmlSuite;25import org.uncommons.reportng.AbstractReporter;26import org.uncommons.reportng.ReportNGException;27import javax.activation.DataHandler;28import javax.activation.DataSource;29import javax.activation.FileDataSource;30import javax.mail.Message;31import javax.mail.MessagingException;32import javax.mail.Multipart;33import javax.mail.PasswordAuthentication;34import javax.mail.Transport;35import javax.mail.internet.InternetAddress;36import javax.mail.internet.MimeBodyPart;37import javax.mail.internet.MimeMessage;38import javax.mail.internet.MimeMultipart;39import java.io.File;40import java.text.SimpleDateFormat;41import java.util.ArrayList;42import java.util.Arrays;43import java.util.Collection;44import java.util.Collections;45import java.util.Comparator;46import java.util.Date;47import java.util.LinkedHashSet;48import java.util.List;49import java.util.Map;50import java.util.Properties;51import java.util.Set;52import java.util.TimeZone;53import org.testng.IReporter;54import org.testng.IResultMap;55import org.testng.ISuite;56import org.testng.ISuiteResult;57import org.testng.ITestContext;58import org.testng.ITestNGMethod;59import org.testng.ITestResult;60import org.testng.collections.Lists;61import org.testng.collections.Maps;62import org.testng.collections.Sets;63import org.testng.internal.Utils;64import org.testng.reporters.XMLReporterConfig;65import org.testng.reporters.XMLStringBuffer;66import org.testng.reporters.XMLSuiteResultWriter;67import org.testng.xml.XmlSuite;68public class CustomReportListener implements IReporter {69 public static final String FILE_NAME = "TestReport_junit.xml";70 private final XMLReporterConfig config = new XMLReporterConfig();71 private XMLStringBuffer rootBuffer;72 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {73 if (Utils.isStringEmpty(config.getOutputDirectory())) {74 config.setOutputDirectory(outputDirectory + "/../");75 }76 // Calculate passed/failed/skipped77 int passed = 0;78 int failed = 0;79 int skipped = 0;80 int ignored = 0;81 for (ISuite s : suites) {82 Map<String, ISuiteResult> suiteResults = s.getResults();83 synchronized (suiteResults) {84 for (ISuiteResult sr : suiteResults.values()) {85 ITestContext testContext = sr.getTestContext();86 passed += testContext.getPassedTests().size();87 failed += testContext.getFailedTests().size();88 skipped += testContext.getSkippedTests().size();89 ignored += testContext.getExcludedMethods().size();90 }91 }92 }93 rootBuffer = new XMLStringBuffer();94 Properties p = new Properties();95 p.put("name", xmlSuites.get(0).getName());96 // p.put("passed", passed);97 // p.put("failed", failed);98 // p.put("skipped", skipped);99 // p.put("ignored", ignored);100 // p.put("total", passed + failed + skipped + ignored);101 rootBuffer.push("testsuites", p);102 // writeReporterOutput(rootBuffer);103 for (ISuite suite : suites) {104 writeSuite(suite.getXmlSuite(), suite);105 }106 rootBuffer.pop();107 Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer, null /* no prefix */);108 109 System.out.println("STARTING CUSTOM LISTENER***********************");110 sendMail(outputDirectory);111 }112 private static void sendMail(String outputDirectoryName){113 final String username = "testUser@gmail.com";114 final String password = "password";115 Properties props = new Properties();116 props.put("mail.smtp.auth", "true");117 props.put("mail.smtp.starttls.enable", "true");118 props.put("mail.smtp.host", "smtp.gmail.com");119 props.put("mail.smtp.port", "587");120 Session session = Session.getInstance(props,121 new javax.mail.Authenticator() {122 protected PasswordAuthentication getPasswordAuthentication() {123 return new PasswordAuthentication(username, password);124 }125 });126 try {127 Message message = new MimeMessage(session);128 message.setFrom(new InternetAddress("rama.rajeswari.ramachandran@oracle.com"));129 message.setRecipients(Message.RecipientType.TO,130 InternetAddress.parse("rama.rajeswari.ramachandran@oracle.com"));131 message.setSubject("Testing Subject");132 message.setText("Dear Mail Crawler,"133 + "\n\n No spam to my email, please!");134 MimeBodyPart messageBodyPart2 = new MimeBodyPart(); 135 String filename = outputDirectoryName+"Suite1\\test.html";136 DataSource source = new FileDataSource(filename); 137 messageBodyPart2.setDataHandler(new DataHandler(source)); 138 messageBodyPart2.setFileName(filename); 139 Multipart multipart = new MimeMultipart(); 140 multipart.addBodyPart(messageBodyPart2); 141 message.setContent(multipart ); 142 Transport.send(message);143 System.out.println("***********completed emailing report*********");144 System.out.println("Done");145 146 } catch (MessagingException e) {147 throw new RuntimeException(e);148 }}149 // private void writeReporterOutput(XMLStringBuffer xmlBuffer) {150 // // TODO: Cosmin - maybe a <line> element isn't indicated for each line151 // xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);152 // List<String> output = Reporter.getOutput();153 // for (String line : output) {154 // if (line != null) {155 // xmlBuffer.push(XMLReporterConfig.TAG_LINE);156 // xmlBuffer.addCDATA(line);157 // xmlBuffer.pop();158 // }159 // }160 // xmlBuffer.pop();161 // }162 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {163 // switch (config.getFileFragmentationLevel()) {164 // case XMLReporterConfig.FF_LEVEL_NONE:165 writeSuiteToBuffer(rootBuffer, suite);166 // break;167 // case XMLReporterConfig.FF_LEVEL_SUITE:168 // case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:169 // File suiteFile = referenceSuite(rootBuffer, suite);170 // writeSuiteToFile(suiteFile, suite);171 // break;172 // default:173 // throw new AssertionError("Unexpected value: " +174 // config.getFileFragmentationLevel());175 // }176 }177 private void writeSuiteToFile(File suiteFile, ISuite suite) {178 XMLStringBuffer xmlBuffer = new XMLStringBuffer();179 writeSuiteToBuffer(xmlBuffer, suite);180 File parentDir = suiteFile.getParentFile();181 suiteFile.getParentFile().mkdirs();182 if (parentDir.exists() || suiteFile.getParentFile().exists()) {183 Utils.writeUtf8File(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());184 }185 }186 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {187 // xmlBuffer.push("testsuite", getSuiteAttributes(suite));188 // writeSuiteGroups(xmlBuffer, suite);189 Map<String, ISuiteResult> results = suite.getResults();190 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config);191 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {192 writeSuiteResult(xmlBuffer, result.getValue());193 }194 // xmlBuffer.pop();195 }196 public void writeSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {197 referenceSuiteResult(xmlBuffer, suiteResult);198 // to write the methods199 writeAllToBuffer(xmlBuffer, suiteResult);200 }201 private void writeAllToBuffer(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {202 xmlBuffer.push("testsuite", getSuiteResultAttributes(suiteResult));203 Set<ITestResult> testResults = Sets.newHashSet();204 ITestContext testContext = suiteResult.getTestContext();205 addAllTestResults(testResults, testContext.getPassedTests());206 addAllTestResults(testResults, testContext.getFailedTests());207 addAllTestResults(testResults, testContext.getSkippedTests());208 addAllTestResults(testResults, testContext.getPassedConfigurations());209 addAllTestResults(testResults, testContext.getSkippedConfigurations());210 addAllTestResults(testResults, testContext.getFailedConfigurations());211 addAllTestResults(testResults, testContext.getFailedButWithinSuccessPercentageTests());212 addTestResults(xmlBuffer, testResults);213 xmlBuffer.pop();214 }215 @SuppressWarnings("unchecked")216 private void addAllTestResults(Set<ITestResult> testResults, IResultMap resultMap) {217 if (resultMap != null) {218 // Sort the results chronologically before adding them219 List<ITestResult> allResults = new ArrayList<>();220 allResults.addAll(resultMap.getAllResults());221 Collections.sort(new ArrayList(allResults), new Comparator<ITestResult>() {222 @Override223 public int compare(ITestResult o1, ITestResult o2) {224 return (int) (o1.getStartMillis() - o2.getStartMillis());225 }226 });227 testResults.addAll(allResults);228 }229 }230 private void addTestResults(XMLStringBuffer xmlBuffer, Set<ITestResult> testResults) {231 Map<String, List<ITestResult>> testsGroupedByClass = buildTestClassGroups(testResults);232 for (Map.Entry<String, List<ITestResult>> result : testsGroupedByClass.entrySet()) {233 Properties attributes = new Properties();234 String className = result.getKey();235 if (config.isSplitClassAndPackageNames()) {236 int dot = className.lastIndexOf('.');237 attributes.setProperty(XMLReporterConfig.ATTR_NAME,238 dot > -1 ? className.substring(dot + 1, className.length()) : className);239 attributes.setProperty(XMLReporterConfig.ATTR_PACKAGE,240 dot > -1 ? className.substring(0, dot) : "[default]");241 } else {242 attributes.setProperty(XMLReporterConfig.ATTR_NAME, className);243 }244 // xmlBuffer.push(XMLReporterConfig.TAG_CLASS, attributes);245 List<ITestResult> sortedResults = result.getValue();246 Collections.sort(sortedResults);247 for (ITestResult testResult : sortedResults) {248 addTestResult(xmlBuffer, testResult);249 }250 // xmlBuffer.pop();251 }252 }253 private Map<String, List<ITestResult>> buildTestClassGroups(Set<ITestResult> testResults) {254 Map<String, List<ITestResult>> map = Maps.newHashMap();255 for (ITestResult result : testResults) {256 String className = result.getTestClass().getName();257 List<ITestResult> list = map.get(className);258 if (list == null) {259 list = Lists.newArrayList();260 map.put(className, list);261 }262 list.add(result);263 }264 return map;265 }266 private void addTestResult(XMLStringBuffer xmlBuffer, ITestResult testResult) {267 Properties attribs = getTestResultAttributes(testResult);268 attribs.setProperty(XMLReporterConfig.ATTR_STATUS, getStatusString(testResult.getStatus()));269 // status, time, name270 xmlBuffer.addEmptyElement("testcase", attribs);271 // addTestMethodParams(xmlBuffer, testResult);272 // addTestResultException(xmlBuffer, testResult);273 // addTestResultOutput(xmlBuffer, testResult);274 // if (config.isGenerateTestResultAttributes()) {275 // addTestResultAttributes(xmlBuffer, testResult);276 // }277 // xmlBuffer.pop();278 }279 private String getStatusString(int testResultStatus) {280 switch (testResultStatus) {281 case ITestResult.SUCCESS:282 return "Passed";283 case ITestResult.FAILURE:284 return "Failed";285 case ITestResult.SKIP:286 return "Skipped";287 case ITestResult.SUCCESS_PERCENTAGE_FAILURE:288 return "SUCCESS_PERCENTAGE_FAILURE";289 default:290 throw new AssertionError("Unexpected value: " + testResultStatus);291 }292 }293 public void addTestMethodParams(XMLStringBuffer xmlBuffer, ITestResult testResult) {294 Object[] parameters = testResult.getParameters();295 if ((parameters != null) && (parameters.length > 0)) {296 xmlBuffer.push(XMLReporterConfig.TAG_PARAMS);297 for (int i = 0; i < parameters.length; i++) {298 addParameter(xmlBuffer, parameters[i], i);299 }300 xmlBuffer.pop();301 }302 }303 private void addParameter(XMLStringBuffer xmlBuffer, Object parameter, int i) {304 Properties attrs = new Properties();305 attrs.setProperty(XMLReporterConfig.ATTR_INDEX, String.valueOf(i));306 xmlBuffer.push(XMLReporterConfig.TAG_PARAM, attrs);307 if (parameter == null) {308 Properties valueAttrs = new Properties();309 valueAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true");310 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_PARAM_VALUE, valueAttrs);311 } else {312 xmlBuffer.push(XMLReporterConfig.TAG_PARAM_VALUE);313 xmlBuffer.addCDATA(parameter.toString());314 xmlBuffer.pop();315 }316 xmlBuffer.pop();317 }318 private void addTestResultAttributes(XMLStringBuffer xmlBuffer, ITestResult testResult) {319 if (testResult.getAttributeNames() != null && testResult.getAttributeNames().size() > 0) {320 xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTES);321 for (String attrName : testResult.getAttributeNames()) {322 if (attrName == null) {323 continue;324 }325 Object attrValue = testResult.getAttribute(attrName);326 Properties attributeAttrs = new Properties();327 attributeAttrs.setProperty(XMLReporterConfig.ATTR_NAME, attrName);328 if (attrValue == null) {329 attributeAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true");330 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs);331 } else {332 xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs);333 xmlBuffer.addCDATA(attrValue.toString());334 xmlBuffer.pop();335 }336 }337 xmlBuffer.pop();338 }339 }340 private Properties getTestResultAttributes(ITestResult testResult) {341 Properties attributes = new Properties();342 // if (!testResult.getMethod().isTest()) {343 // attributes.setProperty(XMLReporterConfig.ATTR_IS_CONFIG, "true");344 // }345 attributes.setProperty(XMLReporterConfig.ATTR_NAME, testResult.getMethod().getMethodName());346 String testInstanceName = testResult.getTestName();347 // if (null != testInstanceName) {348 // attributes.setProperty(XMLReporterConfig.ATTR_TEST_INSTANCE_NAME,349 // testInstanceName);350 // }351 // String description = testResult.getMethod().getDescription();352 // if (!Utils.isStringEmpty(description)) {353 // attributes.setProperty(XMLReporterConfig.ATTR_DESC, description);354 // }355 SimpleDateFormat format = new SimpleDateFormat(config.getTimestampFormat());356 String startTime = format.format(testResult.getStartMillis());357 String endTime = format.format(testResult.getEndMillis());358 // attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);359 // attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);360 long duration = testResult.getEndMillis() - testResult.getStartMillis();361 String strDuration = Long.toString(duration / 1000);362 attributes.setProperty("time", strDuration);363 // if (config.isGenerateGroupsAttribute()) {364 // String groupNamesStr =365 // Utils.arrayToString(testResult.getMethod().getGroups());366 // if (!Utils.isStringEmpty(groupNamesStr)) {367 // attributes.setProperty(XMLReporterConfig.ATTR_GROUPS, groupNamesStr);368 // }369 // }370 //371 // if (config.isGenerateDependsOnMethods()) {372 // String dependsOnStr =373 // Utils.arrayToString(testResult.getMethod().getMethodsDependedUpon());374 // if (!Utils.isStringEmpty(dependsOnStr)) {375 // attributes.setProperty(XMLReporterConfig.ATTR_DEPENDS_ON_METHODS,376 // dependsOnStr);377 // }378 // }379 //380 // if (config.isGenerateDependsOnGroups()) {381 // String dependsOnStr =382 // Utils.arrayToString(testResult.getMethod().getGroupsDependedUpon());383 // if (!Utils.isStringEmpty(dependsOnStr)) {384 // attributes.setProperty(XMLReporterConfig.ATTR_DEPENDS_ON_GROUPS,385 // dependsOnStr);386 // }387 // }388 //389 // ConstructorOrMethod cm =390 // testResult.getMethod().getConstructorOrMethod();391 // Test testAnnotation;392 // if (cm.getMethod() != null) {393 // testAnnotation = cm.getMethod().getAnnotation(Test.class);394 // if (testAnnotation != null) {395 // String dataProvider = testAnnotation.dataProvider();396 // if (!Strings.isNullOrEmpty(dataProvider)) {397 // attributes.setProperty(XMLReporterConfig.ATTR_DATA_PROVIDER,398 // dataProvider);399 // }400 // }401 // }402 return attributes;403 }404 private Properties getSuiteResultAttributes(ISuiteResult suiteResult) {405 Properties attributes = new Properties();406 ITestContext tc = suiteResult.getTestContext();407 attributes.setProperty(XMLReporterConfig.ATTR_NAME, tc.getName());408 // XMLReporter.addDurationAttributes(config, attributes,409 // tc.getStartDate(), tc.getEndDate());410 return attributes;411 }412 private void referenceSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {413 Properties attrs = new Properties();414 String suiteResultName = suiteResult.getTestContext().getName();415 attrs.setProperty(XMLReporterConfig.ATTR_NAME, suiteResultName);416 String status = "";417 // if (suiteResult.getTestContext().getFailedTests().size() == 0)418 // status = "Passed";419 // else420 // status = "Failed";421 // attrs.setProperty("status", status);422 // long duration = suiteResult.getTestContext().getEndDate().getTime()423 // - suiteResult.getTestContext().getStartDate().getTime();424 // attrs.setProperty("time", Long.toString(duration));425 // attrs.setProperty("passed",426 // Integer.toString(suiteResult.getTestContext().getPassedTests().size()));427 // attrs.setProperty("failed",428 // Integer.toString(suiteResult.getTestContext().getFailedTests().size()));429 // attrs.setProperty("skipped",430 // Integer.toString(suiteResult.getTestContext().getSkippedTests().size()));431 // attrs.setProperty("ignored",432 // Integer.toString(suiteResult.getTestContext().getSkippedTests().size()));433 // attrs.setProperty("total",434 // Integer.toString(suiteResult.getTestContext().getPassedTests().size()435 // + suiteResult.getTestContext().getFailedTests().size()436 // + suiteResult.getTestContext().getSkippedTests().size()));437 // xmlBuffer.addEmptyElement("testcase", attrs);438 // xmlBuffer.push("testsuite", getSuiteResultAttributes(suiteResult));439 ArrayList<ITestNGMethod> testcase = new ArrayList<ITestNGMethod>(440 Arrays.asList(suiteResult.getTestContext().getAllTestMethods()));441 //442 // for (ITestNGMethod method : testcase) {443 // //444 //445 // writeMethodToBuffer(xmlBuffer, method, suiteResult.getTestContext());446 //447 // }448 //449 // for (ITestResult testResult : sortedResults) {450 // addTestResult(xmlBuffer, testResult);451 // }452 // xmlBuffer.pop();453 }454 // private void writeMethodToBuffer(XMLStringBuffer xmlBuffer, ITestNGMethod455 // methodResult, ITestContext test) {456 //457 // Properties attrs = new Properties();458 // String methName = methodResult.getMethodName();459 // attrs.setProperty("name", methodResult.getMethodName());460 //461 // String strDuration = Long.toString(duration);462 //463 // IResultMap results = test.getFailedTests();464 // Set<ITestResult> newset = new HashSet<ITestResult>();465 // if (results.size() > 0) {466 //467 // newset = results.getResults(methodResult);468 // if (newset.size() == 0)469 // attrs.setProperty("Status", "Passed");470 // else {471 // for (ITestResult t : newset) {472 // if (t.getName().contains(methName))473 // attrs.setProperty("Status", "Failed");474 //475 // }476 // }477 // } else {478 // attrs.setProperty("Status", "Passed");479 // }480 // SimpleDateFormat format = new481 // SimpleDateFormat(config.getTimestampFormat());482 // String startTime = format.format(newset.getStartMillis());483 // String endTime = format.format(newset.getEndMillis());484 //485 // attrs.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);486 // attrs.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);487 // long duration = newset.getEndMillis() - newset.getStartMillis();488 //489 // xmlBuffer.addEmptyElement("testcase", attrs);490 // // xmlBuffer.pop();491 // }492 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {493 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;494 File suiteFile = new File(config.getOutputDirectory(), relativePath);495 Properties attrs = new Properties();496 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);497 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);498 return suiteFile;499 }500 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {501 Set<ITestNGMethod> result = new LinkedHashSet<>();502 for (ITestNGMethod method : methods) {503 result.add(method);504 }505 return result;506 }507 private Properties getSuiteAttributes(ISuite suite) {508 Properties props = new Properties();509 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());510 // // Calculate the duration511 // Map<String, ISuiteResult> results = suite.getResults();512 // Date minStartDate = new Date();513 // Date maxEndDate = null;514 // // TODO: We could probably optimize this in order not to traverse515 // this twice516 // synchronized(results) {517 // for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {518 // ITestContext testContext = result.getValue().getTestContext();519 // Date startDate = testContext.getStartDate();520 // Date endDate = testContext.getEndDate();521 // if (minStartDate.after(startDate)) {522 // minStartDate = startDate;523 // }524 // if (maxEndDate == null || maxEndDate.before(endDate)) {525 // maxEndDate = endDate != null ? endDate : startDate;526 // }527 // }528 // }529 // // The suite could be completely empty530 // if (maxEndDate == null) {531 // maxEndDate = minStartDate;532 // }533 // addDurationAttributes(config, props, minStartDate, maxEndDate);534 return props;535 }536 /**537 * Add started-at, finished-at and duration-ms attributes to the <suite> tag538 */539 public static void addDurationAttributes(XMLReporterConfig config, Properties attributes, Date minStartDate,540 Date maxEndDate) {541 SimpleDateFormat format = new SimpleDateFormat(config.getTimestampFormat());542 TimeZone utc = TimeZone.getTimeZone("UTC");543 format.setTimeZone(utc);544 String startTime = format.format(minStartDate);545 String endTime = format.format(maxEndDate);546 long duration = maxEndDate.getTime() - minStartDate.getTime();547 // attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);548 // attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);549 attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, Long.toString(duration));550 }551 // TODO: This is not the smartest way to implement the config552 public int getFileFragmentationLevel() {553 return config.getFileFragmentationLevel();554 }555 public void setFileFragmentationLevel(int fileFragmentationLevel) {556 config.setFileFragmentationLevel(fileFragmentationLevel);557 }558 public int getStackTraceOutputMethod() {559 return config.getStackTraceOutputMethod();560 }561 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {562 config.setStackTraceOutputMethod(stackTraceOutputMethod);563 }564 public String getOutputDirectory() {565 return config.getOutputDirectory();566 }567 public void setOutputDirectory(String outputDirectory) {568 config.setOutputDirectory(outputDirectory);569 }570 public boolean isGenerateGroupsAttribute() {571 return config.isGenerateGroupsAttribute();572 }573 public void setGenerateGroupsAttribute(boolean generateGroupsAttribute) {574 config.setGenerateGroupsAttribute(generateGroupsAttribute);575 }576 public boolean isSplitClassAndPackageNames() {577 return config.isSplitClassAndPackageNames();578 }579 public void setSplitClassAndPackageNames(boolean splitClassAndPackageNames) {580 config.setSplitClassAndPackageNames(splitClassAndPackageNames);581 }582 public String getTimestampFormat() {583 return config.getTimestampFormat();584 }585 public void setTimestampFormat(String timestampFormat) {586 config.setTimestampFormat(timestampFormat);587 }588 public boolean isGenerateDependsOnMethods() {589 return config.isGenerateDependsOnMethods();590 }591 public void setGenerateDependsOnMethods(boolean generateDependsOnMethods) {592 config.setGenerateDependsOnMethods(generateDependsOnMethods);593 }594 public void setGenerateDependsOnGroups(boolean generateDependsOnGroups) {595 config.setGenerateDependsOnGroups(generateDependsOnGroups);596 }597 public boolean isGenerateDependsOnGroups() {598 return config.isGenerateDependsOnGroups();599 }600 public void setGenerateTestResultAttributes(boolean generateTestResultAttributes) {601 config.setGenerateTestResultAttributes(generateTestResultAttributes);602 }603 public boolean isGenerateTestResultAttributes() {604 return config.isGenerateTestResultAttributes();605 }606 //// suiteRunners607 // public static void main (String args[]){608 // mTempDirectory = new File(slashTmpDir, "testng-tmp-" +609 //// System.currentTimeMillis() % 1000);610 // mTempDirectory.mkdirs();611 //612 // List<String> suiteFiles = new ArrayList<>(withSuiteFiles.length);613 // for (String suiteFile : withSuiteFiles) {614 // suiteFiles.add(new File(PARENT, suiteFile).getAbsolutePath());615 // }616 //617 // ReportGenerator reportGenerator = new ReportGenerator();618 // reportGenerator.generateReport(xmlSuites, suiteRunners,619 //// "D:\\myNewCloudProject\\test-report");620 // for (int i=0; i < suites.size(); i++) {621 // writeSuite(suites.get(i).getXmlSuite(),suites.get(i));622 // }623 //// TestNG tng = new TestNG();624 // * List<String> suites = Lists.newArrayList();625 // * suites.add("c:/tests/testng1.xml");626 // * suites.add("c:/tests/testng2.xml");627 // * tng.setTestSuites(suites);628}...

Full Screen

Full Screen

Source:CustomReport.java Github

copy

Full Screen

...102 }103 104105 public String generateFileName() {106 String fileName = "";107 try {108109 DateFormat dateFormat = new SimpleDateFormat("MM-dd_HH-mm-ss");110 Date date = new Date();111 fileName = "CustomReport_"+ application + "_" + environment +"_"+getPackageName()112 +"_"+ browserName +"_"+dateFormat.format(date)+".xml";113 } catch (Exception e) {114 e.printStackTrace();115 }116 return fileName;117 }118 119 private String getPackageName() {120 String packageName = "";121 packageName = System.getProperty("packageName", "NA");122 if(packageName != null && !packageName.equalsIgnoreCase("")) {123 if(packageName.equalsIgnoreCase("${packageName}")) {124 packageName = "NA";125 }126 }127 return packageName;128 }129130 public void cleanSuite() { ...

Full Screen

Full Screen

Source:JUnitXMLReporter.java Github

copy

Full Screen

...37 }38 private int m_numFailed = 0;39 private Queue<ITestResult> m_allTests = new ConcurrentLinkedDeque<>();40 private Queue<ITestResult> m_configIssues = new ConcurrentLinkedDeque<>();41 private Map<String, String> m_fileNameMap = Maps.newHashMap();42 private int m_fileNameIncrementer = 0;43 @Override44 public void onTestStart(ITestResult result) {}45 @Override46 public void beforeConfiguration(ITestResult tr) {}47 /** Invoked each time a test succeeds. */48 @Override49 public void onTestSuccess(ITestResult tr) {50 m_allTests.add(tr);51 }52 @Override53 public void onTestFailedButWithinSuccessPercentage(ITestResult tr) {54 m_allTests.add(tr);55 }56 /** Invoked each time a test fails. */57 @Override58 public void onTestFailure(ITestResult tr) {59 m_allTests.add(tr);60 m_numFailed++;61 }62 /** Invoked each time a test is skipped. */63 @Override64 public void onTestSkipped(ITestResult tr) {65 m_allTests.add(tr);66 }67 /** Invoked after the test class is instantiated and before any configuration method is called. */68 @Override69 public void onStart(ITestContext context) {}70 /** Invoked after all the tests have run and all their Configuration methods have been called. */71 @Override72 public void onFinish(ITestContext context) {73 generateReport(context);74 resetAll();75 }76 /** @see org.testng.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult) */77 @Override78 public void onConfigurationFailure(ITestResult itr) {79 m_configIssues.add(itr);80 }81 /** @see org.testng.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult) */82 @Override83 public void onConfigurationSkip(ITestResult itr) {84 m_configIssues.add(itr);85 }86 /** @see org.testng.IConfigurationListener#onConfigurationSuccess(org.testng.ITestResult) */87 @Override88 public void onConfigurationSuccess(ITestResult itr) {}89 /**90 * generate the XML report given what we know from all the test results91 *92 * @param context The test context93 */94 protected void generateReport(ITestContext context) {95 XMLStringBuffer document = new XMLStringBuffer();96 document.addComment("Generated by " + getClass().getName());97 Properties attrs = new Properties();98 attrs.setProperty(XMLConstants.ATTR_ERRORS, "0");99 attrs.setProperty(XMLConstants.ATTR_FAILURES, Integer.toString(m_numFailed));100 attrs.setProperty(101 XMLConstants.ATTR_IGNORED, Integer.toString(context.getExcludedMethods().size()));102 try {103 attrs.setProperty(XMLConstants.ATTR_HOSTNAME, InetAddress.getLocalHost().getHostName());104 } catch (UnknownHostException e) {105 // ignore106 }107 Set<String> packages = getPackages(context);108 if (packages.size() > 0) {109 attrs.setProperty(XMLConstants.ATTR_NAME, context.getCurrentXmlTest().getName());110 // attrs.setProperty(XMLConstants.ATTR_PACKAGE, packages.iterator().next());111 }112 attrs.setProperty(XMLConstants.ATTR_TESTS, Integer.toString(m_allTests.size()));113 attrs.setProperty(114 XMLConstants.ATTR_TIME,115 Double.toString(116 (context.getEndDate().getTime() - context.getStartDate().getTime()) / 1000.0));117 attrs.setProperty(XMLConstants.ATTR_TIMESTAMP, formattedTime());118 document.push(XMLConstants.TESTSUITE, attrs);119 createElementFromTestResults(document, m_configIssues);120 createElementFromTestResults(document, m_allTests);121 createElementFromIgnoredTests(document, context);122 document.pop();123 Utils.writeUtf8File(124 context.getOutputDirectory(), generateFileName(context) + ".xml", document.toXML());125 }126 static String formattedTime() {127 return TimeUtils.formatTimeInLocalOrSpecifiedTimeZone(128 System.currentTimeMillis(), XMLReporterConfig.FMT_DEFAULT);129 }130 private synchronized void createElementFromTestResults(131 XMLStringBuffer document, Collection<ITestResult> results) {132 for (ITestResult tr : results) {133 createElement(document, tr);134 }135 }136 private synchronized void createElementFromIgnoredTests(137 XMLStringBuffer doc, ITestContext context) {138 Collection<ITestNGMethod> methods = context.getExcludedMethods();139 for (ITestNGMethod method : methods) {140 Properties properties = getPropertiesFor(method, 0);141 doc.push(XMLConstants.TESTCASE, properties);142 doc.addEmptyElement(XMLConstants.ATTR_IGNORED);143 doc.pop();144 }145 }146 private Properties getPropertiesFor(ITestNGMethod method, long elapsedTimeMillis) {147 Properties attrs = new Properties();148 String name = Utils.detailedMethodName(method, false);149 attrs.setProperty(XMLConstants.ATTR_NAME, name);150 attrs.setProperty(XMLConstants.ATTR_CLASSNAME, method.getRealClass().getName());151 attrs.setProperty(XMLConstants.ATTR_TIME, Double.toString(((double) elapsedTimeMillis) / 1000));152 return attrs;153 }154 private Set<String> getPackages(ITestContext context) {155 Set<String> result = Sets.newHashSet();156 for (ITestNGMethod m : context.getAllTestMethods()) {157 Package pkg = m.getRealClass().getPackage();158 if (pkg != null) {159 result.add(pkg.getName());160 }161 }162 return result;163 }164 private void createElement(XMLStringBuffer doc, ITestResult tr) {165 long elapsedTimeMillis = tr.getEndMillis() - tr.getStartMillis();166 Properties attrs = getPropertiesFor(tr.getMethod(), elapsedTimeMillis);167 if (tr.getMethod().isTest()) {168 attrs.setProperty(XMLConstants.ATTR_NAME, tr.getName());169 }170 if ((ITestResult.FAILURE == tr.getStatus()) || (ITestResult.SKIP == tr.getStatus())) {171 doc.push(XMLConstants.TESTCASE, attrs);172 if (ITestResult.FAILURE == tr.getStatus()) {173 createFailureElement(doc, tr);174 } else if (ITestResult.SKIP == tr.getStatus()) {175 createSkipElement(doc);176 }177 doc.pop();178 } else {179 doc.addEmptyElement(XMLConstants.TESTCASE, attrs);180 }181 }182 private void createFailureElement(XMLStringBuffer doc, ITestResult tr) {183 Properties attrs = new Properties();184 Throwable t = tr.getThrowable();185 if (t != null) {186 attrs.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());187 String message = t.getMessage();188 if ((message != null) && (message.length() > 0)) {189 attrs.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE190 }191 doc.push(XMLConstants.FAILURE, attrs);192 doc.addCDATA(Utils.shortStackTrace(t, false));193 doc.pop();194 } else {195 doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR196 }197 }198 private void createSkipElement(XMLStringBuffer doc) {199 doc.addEmptyElement(XMLConstants.SKIPPED);200 }201 private String encodeAttr(String attr) {202 String result = replaceAmpersand(attr, ENTITY);203 for (Map.Entry<String, Pattern> e : ATTR_ESCAPES.entrySet()) {204 result = e.getValue().matcher(result).replaceAll(e.getKey());205 }206 return result;207 }208 private String replaceAmpersand(String str, Pattern pattern) {209 int start = 0;210 int idx = str.indexOf('&', start);211 if (idx == -1) {212 return str;213 }214 StringBuilder result = new StringBuilder();215 while (idx != -1) {216 result.append(str.substring(start, idx));217 if (pattern.matcher(str.substring(idx)).matches()) {218 // do nothing it is an entity;219 result.append("&");220 } else {221 result.append("&amp;");222 }223 start = idx + 1;224 idx = str.indexOf('&', start);225 }226 result.append(str.substring(start));227 return result.toString();228 }229 /** Reset all member variables for next test. */230 private void resetAll() {231 m_allTests = new ConcurrentLinkedDeque<>();232 m_configIssues = new ConcurrentLinkedDeque<>();233 m_numFailed = 0;234 }235 /**236 * This method guarantees unique file names for reports.<br>237 * Also, this will guarantee that the old reports are overwritten when tests are run again.238 *239 * @param context test context240 * @return unique name for the file associated with this test context.241 */242 private String generateFileName(ITestContext context) {243 String fileName;244 String keyToSearch = context.getSuite().getName() + context.getName();245 if (m_fileNameMap.get(keyToSearch) == null) {246 fileName = context.getName();247 } else {248 fileName = context.getName() + m_fileNameIncrementer++;249 }250 m_fileNameMap.put(keyToSearch, fileName);251 return fileName;252 }253}...

Full Screen

Full Screen

Source:XMLReporter.java Github

copy

Full Screen

...68 for (ISuite suite : suites) {69 writeSuite(suite);70 }71 rootBuffer.pop();72 Utils.writeUtf8File(config.getOutputDirectory(), fileName(), rootBuffer, null /* no prefix */);73 }74 public void addCustomTagsFor(XMLStringBuffer xmlBuffer, ITestResult testResult) {75 }76 public String fileName() {77 return RuntimeBehavior.getDefaultFileNameForXmlReports();78 }79 private void writeReporterOutput(XMLStringBuffer xmlBuffer) {80 // TODO: Cosmin - maybe a <line> element isn't indicated for each line81 xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);82 List<String> output = Reporter.getOutput();83 for (String line : output) {84 if (line != null) {85 xmlBuffer.push(XMLReporterConfig.TAG_LINE);86 xmlBuffer.addCDATA(line);87 xmlBuffer.pop();88 }89 }90 xmlBuffer.pop();91 }92 private void writeSuite(ISuite suite) {93 switch (config.getFileFragmentationLevel()) {94 case XMLReporterConfig.FF_LEVEL_NONE:95 writeSuiteToBuffer(rootBuffer, suite);96 break;97 case XMLReporterConfig.FF_LEVEL_SUITE:98 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:99 File suiteFile = referenceSuite(rootBuffer, suite);100 writeSuiteToFile(suiteFile, suite);101 break;102 default:103 throw new AssertionError("Unexpected value: " + config.getFileFragmentationLevel());104 }105 }106 private void writeSuiteToFile(File suiteFile, ISuite suite) {107 XMLStringBuffer xmlBuffer = new XMLStringBuffer();108 writeSuiteToBuffer(xmlBuffer, suite);109 File parentDir = suiteFile.getParentFile();110 suiteFile.getParentFile().mkdirs();111 if (parentDir.exists() || suiteFile.getParentFile().exists()) {112 Utils.writeUtf8File(parentDir.getAbsolutePath(), fileName(), xmlBuffer.toXML());113 }114 }115 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {116 String relativePath = suite.getName() + File.separatorChar + fileName();117 File suiteFile = new File(config.getOutputDirectory(), relativePath);118 Properties attrs = new Properties();119 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);120 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);121 return suiteFile;122 }123 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {124 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));125 writeSuiteGroups(xmlBuffer, suite);126 Map<String, ISuiteResult> results = suite.getResults();127 XMLSuiteResultWriter suiteResultWriter = new XMLSuiteResultWriter(config, this);128 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {129 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());130 }...

Full Screen

Full Screen

Source:XrayReportListener.java Github

copy

Full Screen

1package com.xpandit.testng.reports;2import java.util.Properties;3import org.testng.ITestResult;4import org.testng.reporters.XMLReporter;5import org.testng.reporters.XMLStringBuffer;6import java.io.File;7import java.nio.file.Files;8import java.util.Base64;9import java.util.Base64.Encoder;10public class XrayReportListener extends XMLReporter {11 public static final String TAG_ATTACHMENTS = "attachments";12 public static final String TAG_ATTACHMENT = "attachment";13 public static final String TAG_ATTACHMENT_RAWCONTENT = "rawcontent";14 public static final String ATTR_NAME = "name";15 public static final String ATTR_FILENAME = "filename";16 public static final String ATTR_SRC = "src";17 @Override18 public void addCustomTagsFor(XMLStringBuffer xmlBuffer, ITestResult testResult) {19 xmlBuffer.push(XrayReportListener.TAG_ATTACHMENTS);20 Base64.Encoder enc= Base64.getEncoder();21 File[] attachments = (File[])testResult.getAttribute("attachments");22 if (attachments != null){23 for (File file : attachments) {24 Properties valueAttrs = new Properties();25 valueAttrs.setProperty(XrayReportListener.ATTR_FILENAME, file.getName());26 valueAttrs.setProperty(XrayReportListener.ATTR_SRC, file.getAbsolutePath());27 xmlBuffer.push(XrayReportListener.TAG_ATTACHMENT, valueAttrs);28 try {29 byte[] fileContent = Files.readAllBytes(file.toPath());30 byte[] encoded = enc.encode(fileContent);31 String encodedStr = new String(encoded,"UTF-8");32 xmlBuffer.push(XrayReportListener.TAG_ATTACHMENT_RAWCONTENT);33 xmlBuffer.addCDATA(encodedStr);34 xmlBuffer.pop();35 } catch (Exception ex) {36 }37 xmlBuffer.pop();38 }39 }40 xmlBuffer.pop();41 }42}...

Full Screen

Full Screen

Source:LocalJUnitXMLReporter.java Github

copy

Full Screen

1package test.junitreports;2import org.testng.ITestContext;3import org.testng.reporters.JUnitXMLReporter;4import java.io.File;5import java.io.FileInputStream;6import java.io.FileNotFoundException;7import java.io.FilenameFilter;8import java.util.ArrayList;9import java.util.List;10public class LocalJUnitXMLReporter extends JUnitXMLReporter implements TestsuiteRetriever {11 private List<Testsuite> testsuites = new ArrayList<>();12 protected void generateReport(ITestContext context) {13 super.generateReport(context);14 String dir = context.getOutputDirectory();15 File directory = new File(dir);16 File[] files = directory.listFiles(new FilenameFilter() {17 @Override18 public boolean accept(File dir, String name) {19 return name.endsWith(".xml");20 }21 });22 testsuites.addAll(getSuites(files));23 }24 public Testsuite getTestsuite(String name) {25 for (Testsuite suite : testsuites) {26 if (suite.getName().equals(name)) {27 return suite;28 }29 }30 return null;31 }32 static List<Testsuite> getSuites(File[] files) {33 List<Testsuite> testsuites = new ArrayList<>();34 if (files != null) {35 for (File file : files) {36 TestsuiteXmlParser parser = new TestsuiteXmlParser();37 try {38 testsuites.add(parser.parse("", new FileInputStream(file), false));39 } catch (FileNotFoundException e) {40 e.printStackTrace();41 }42 }43 }44 return testsuites;45 }46}...

Full Screen

Full Screen

Source:LocalJUnitReportReporter.java Github

copy

Full Screen

1package test.junitreports;2import org.testng.ISuite;3import org.testng.reporters.JUnitReportReporter;4import org.testng.xml.XmlSuite;5import java.io.File;6import java.io.FilenameFilter;7import java.util.ArrayList;8import java.util.List;9public class LocalJUnitReportReporter extends JUnitReportReporter implements TestsuiteRetriever {10 private List<Testsuite> testsuites = new ArrayList<>();11 @Override12 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String defaultOutputDirectory) {13 super.generateReport(xmlSuites, suites, defaultOutputDirectory);14 String dir = defaultOutputDirectory + File.separator + "junitreports";15 File directory = new File(dir);16 File[] files = directory.listFiles(new FilenameFilter() {17 @Override18 public boolean accept(File dir, String name) {19 return name.endsWith(".xml");20 }21 });22 testsuites.addAll(LocalJUnitXMLReporter.getSuites(files));23 }24 public Testsuite getTestsuite(String name) {25 for (Testsuite suite : testsuites) {26 if (suite.getName().equals(name)) {27 return suite;28 }29 }30 return null;31 }32}...

Full Screen

Full Screen

Source:MyExampleListener.java Github

copy

Full Screen

...4import org.testng.reporters.XMLReporter;5import org.testng.reporters.XMLStringBuffer;6public class MyExampleListener extends XMLReporter {7 @Override8 public String fileName() {9 return "issue_2171.xml";10 }11 @Override12 public void addCustomTagsFor(XMLStringBuffer xmlBuffer, ITestResult testResult) {13 Properties props = new Properties();14 for (String attributeName : testResult.getAttributeNames()) {15 props.setProperty("path", testResult.getAttribute(attributeName).toString());16 xmlBuffer.push(attributeName, props);17 xmlBuffer.pop(attributeName);18 }19 }20}...

Full Screen

Full Screen

fileName

Using AI Code Generation

copy

Full Screen

1import org.testng.TestNG;2import org.testng.xml.XmlSuite;3import java.util.ArrayList;4import java.util.List;5public class TestNGRunner {6 public static void main(String[] args) {7 TestNG testNG = new TestNG();8 List<XmlSuite> xmlSuites = new ArrayList<XmlSuite>();9 XmlSuite xmlSuite = new XmlSuite();10 xmlSuite.setName("TestNG Suite");11 xmlSuite.setFileName("testng.xml");12 xmlSuites.add(xmlSuite);13 testNG.setXmlSuites(xmlSuites);14 testNG.run();15 }16}17import org.testng.annotations.Test;18public class TestNGTest {19 public void test() {20 System.out.println("TestNGTest.test");21 }22}

Full Screen

Full Screen

fileName

Using AI Code Generation

copy

Full Screen

1package com.automation;2import org.testng.annotations.Test;3import org.testng.annotations.DataProvider;4import org.testng.annotations.BeforeTest;5import org.testng.annotations.AfterTest;6public class NewTest {7 @Test(dataProvider = "dp")8 public void f(Integer n, String s) {9 }10 public Object[][] dp() {11 return new Object[][] {12 new Object[] { 1, "a" },13 new Object[] { 2, "b" },14 };15 }16 public void beforeTest() {17 }18 public void afterTest() {19 }20}21package com.automation;22import org.testng.ITestContext;23import org.testng.ITestListener;24import org.testng.ITestResult;25import org.testng.TestListenerAdapter;26public class MyListener extends TestListenerAdapter implements ITestListener {27 public void onTestStart(ITestResult result) {28 System.out.println("Test Started");29 }30 public void onTestSuccess(ITestResult result) {31 System.out.println("Test Success");32 }33 public void onTestFailure(ITestResult result) {34 System.out.println("Test Failed");35 }36 public void onTestSkipped(ITestResult result) {37 System.out.println("Test Skipped");38 }39 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {40 System.out.println("Test Failed but within Success Percentage");41 }42 public void onStart(ITestContext context) {43 System.out.println("Test Started");44 }45 public void onFinish(ITestContext context) {46 System.out.println("Test Finished");47 }48}

Full Screen

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful