How to use getFileFragmentationLevel method of org.testng.reporters.XMLReporterConfig class

Best Testng code snippet using org.testng.reporters.XMLReporterConfig.getFileFragmentationLevel

Source:CustomReportListener.java Github

copy

Full Screen

...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) {...

Full Screen

Full Screen

Source:CustomXMLReporter.java Github

copy

Full Screen

...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) {158 Properties methodAttrs = new Properties();159 methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupMethod.getMethodName());160 methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, groupMethod.toString());161 methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, groupMethod.getRealClass().getName());162 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD, methodAttrs);163 }164 xmlBuffer.pop();165 }166 xmlBuffer.pop();167 }168 private Properties getSuiteAttributes(ISuite suite) {169 Properties props = new Properties();170 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());171 // Calculate the duration172 Map<String, ISuiteResult> results = suite.getResults();173 Date minStartDate = new Date();174 Date maxEndDate = null;175 // TODO: We could probably optimize this in order not to traverse this twice176 synchronized(results) {177 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {178 ITestContext testContext = result.getValue().getTestContext();179 Date startDate = testContext.getStartDate();180 Date endDate = testContext.getEndDate();181 if (minStartDate.after(startDate)) {182 minStartDate = startDate;183 }184 if (maxEndDate == null || maxEndDate.before(endDate)) {185 maxEndDate = endDate != null ? endDate : startDate;186 }187 }188 }189 // The suite could be completely empty190 if (maxEndDate == null) {191 maxEndDate = minStartDate;192 }193 addDurationAttributes(config, props, minStartDate, maxEndDate);194 return props;195 }196 /**197 * Add started-at, finished-at and duration-ms attributes to the <suite> tag198 */199 public static void addDurationAttributes(XMLReporterConfig config, Properties attributes,200 Date minStartDate, Date maxEndDate) {201 SimpleDateFormat format = new SimpleDateFormat(config.getTimestampFormat());202 TimeZone utc = TimeZone.getTimeZone("UTC");203 format.setTimeZone(utc);204 String startTime = format.format(minStartDate);205 String endTime = format.format(maxEndDate);206 long duration = maxEndDate.getTime() - minStartDate.getTime();207 attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);208 attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);209 attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, Long.toString(duration));210 }211 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {212 Set<ITestNGMethod> result = new LinkedHashSet<>();213 for (ITestNGMethod method : methods) {214 result.add(method);215 }216 return result;217 }218 // TODO: This is not the smartest way to implement the config219 public int getFileFragmentationLevel() {220 return config.getFileFragmentationLevel();221 }222 public void setFileFragmentationLevel(int fileFragmentationLevel) {223 config.setFileFragmentationLevel(fileFragmentationLevel);224 }225 public int getStackTraceOutputMethod() {226 return config.getStackTraceOutputMethod();227 }228 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {229 config.setStackTraceOutputMethod(stackTraceOutputMethod);230 }231 public String getOutputDirectory() {232 return config.getOutputDirectory();233 }234 public void setOutputDirectory(String outputDirectory) {...

Full Screen

Full Screen

Source:CustomTestNgReporter.java Github

copy

Full Screen

...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()) {...

Full Screen

Full Screen

Source:PowerXMLReport.java Github

copy

Full Screen

...78 xmlBuffer.pop();79 }8081 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {82 switch (config.getFileFragmentationLevel()) {83 case XMLReporterConfig.FF_LEVEL_NONE:84 writeSuiteToBuffer(rootBuffer, suite);85 break;86 case XMLReporterConfig.FF_LEVEL_SUITE:87 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:88 File suiteFile = referenceSuite(rootBuffer, suite);89 writeSuiteToFile(suiteFile, suite);90 }91 }9293 private void writeSuiteToFile(File suiteFile, ISuite suite) {94 XMLStringBuffer xmlBuffer = new XMLStringBuffer();95 writeSuiteToBuffer(xmlBuffer, suite);96 File parentDir = suiteFile.getParentFile();97 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {98 Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());99 }100 }101102 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {103 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;104 File suiteFile = new File(config.getOutputDirectory(), relativePath);105 Properties attrs = new Properties();106 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);107 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);108 return suiteFile;109 }110111 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {112 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));113 writeSuiteGroups(xmlBuffer, suite);114115 Map<String, ISuiteResult> results = suite.getResults();116 NeXMLSuiteResultWriter suiteResultWriter = new NeXMLSuiteResultWriter(config);117 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {118 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());119 }120121 xmlBuffer.pop();122 }123124 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {125 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);126 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();127 for (Map.Entry<String, Collection<ITestNGMethod>> entry : methodsByGroups.entrySet()) {128 Properties groupAttrs = new Properties();129 groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, entry.getKey());130 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);131 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(entry.getValue());132 for (ITestNGMethod groupMethod : groupMethods) {133 Properties methodAttrs = new Properties();134 methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupMethod.getMethodName());135 methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, groupMethod.toString());136 methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, groupMethod.getRealClass().getName());137 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD, methodAttrs);138 }139 xmlBuffer.pop();140 }141 xmlBuffer.pop();142 }143144 private Properties getSuiteAttributes(ISuite suite) {145 Properties props = new Properties();146 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());147148 // Calculate the duration149 Map<String, ISuiteResult> results = suite.getResults();150 Date minStartDate = new Date();151 Date maxEndDate = null;152 // TODO: We could probably optimize this in order not to traverse this twice153 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {154 ITestContext testContext = result.getValue().getTestContext();155 Date startDate = testContext.getStartDate();156 Date endDate = testContext.getEndDate();157 if (minStartDate.after(startDate)) {158 minStartDate = startDate;159 }160 if (maxEndDate == null || maxEndDate.before(endDate)) {161 maxEndDate = endDate != null ? endDate : startDate;162 }163 }164165 // The suite could be completely empty166 if (maxEndDate == null) {167 maxEndDate = minStartDate;168 }169 addDurationAttributes(config, props, minStartDate, maxEndDate);170 return props;171 }172173 /**174 * Add started-at, finished-at and duration-ms attributes to the <suite> tag175 */176 public static void addDurationAttributes(XMLReporterConfig config, Properties attributes,177 Date minStartDate, Date maxEndDate) {178 SimpleDateFormat format = new SimpleDateFormat(XMLReporterConfig.getTimestampFormat());179 TimeZone utc = TimeZone.getTimeZone("UTC");180 format.setTimeZone(utc);181 String startTime = format.format(minStartDate);182 String endTime = format.format(maxEndDate);183 long duration = maxEndDate.getTime() - minStartDate.getTime();184185 attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);186 attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);187 attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, Long.toString(duration));188 }189190 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {191 Set<ITestNGMethod> result = new LinkedHashSet<>();192 for (ITestNGMethod method : methods) {193 result.add(method);194 }195 return result;196 }197198 // TODO: This is not the smartest way to implement the config199 public int getFileFragmentationLevel() {200 return config.getFileFragmentationLevel();201 }202203 public void setFileFragmentationLevel(int fileFragmentationLevel) {204 config.setFileFragmentationLevel(fileFragmentationLevel);205 }206207 public int getStackTraceOutputMethod() {208 return config.getStackTraceOutputMethod();209 }210211 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {212 config.setStackTraceOutputMethod(stackTraceOutputMethod);213 }214 ...

Full Screen

Full Screen

Source:XMLPassedTestReporter.java Github

copy

Full Screen

...73 }74 xmlBuffer.pop();75 }76 private void writeSuite(XmlSuite xmlSuite, ISuite suite) {77 switch (config.getFileFragmentationLevel()) {78 case XMLReporterConfig.FF_LEVEL_NONE:79 writeSuiteToBuffer(rootBuffer, suite);80 break;81 case XMLReporterConfig.FF_LEVEL_SUITE:82 case XMLReporterConfig.FF_LEVEL_SUITE_RESULT:83 File suiteFile = referenceSuite(rootBuffer, suite);84 writeSuiteToFile(suiteFile, suite);85 }86 }87 private void writeSuiteToFile(File suiteFile, ISuite suite) {88 XMLStringBuffer xmlBuffer = new XMLStringBuffer();89 writeSuiteToBuffer(xmlBuffer, suite);90 File parentDir = suiteFile.getParentFile();91 if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {92 Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());93 }94 }95 private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {96 String relativePath = suite.getName() + File.separatorChar + FILE_NAME;97 File suiteFile = new File(config.getOutputDirectory(), relativePath);98 Properties attrs = new Properties();99 attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);100 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);101 return suiteFile;102 }103 private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {104 xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));105 writeSuiteGroups(xmlBuffer, suite);106 Map<String, ISuiteResult> results = suite.getResults();107 XMLSuiteResultWriterDRC suiteResultWriter = new XMLSuiteResultWriterDRC(config, true, false, true);108 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {109 110 result.getValue();111 //Added exclude logic for failed testCase112 //result.getValue().113 114 suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());115 }116 xmlBuffer.pop();117 }118 private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {119 xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);120 Map<String, Collection<ITestNGMethod>> methodsByGroups = suite.getMethodsByGroups();121 for (Map.Entry<String, Collection<ITestNGMethod>> entry : methodsByGroups.entrySet()) {122 Properties groupAttrs = new Properties();123 groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, entry.getKey());124 xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);125 Set<ITestNGMethod> groupMethods = getUniqueMethodSet(entry.getValue());126 for (ITestNGMethod groupMethod : groupMethods) {127 Properties methodAttrs = new Properties();128 methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupMethod.getMethodName());129 methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, groupMethod.toString());130 methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, groupMethod.getRealClass().getName());131 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD, methodAttrs);132 }133 xmlBuffer.pop();134 }135 xmlBuffer.pop();136 }137 private Properties getSuiteAttributes(ISuite suite) {138 Properties props = new Properties();139 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());140 // Calculate the duration141 Map<String, ISuiteResult> results = suite.getResults();142 Date minStartDate = new Date();143 Date maxEndDate = null;144 // TODO: We could probably optimize this in order not to traverse this twice145 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {146 ITestContext testContext = result.getValue().getTestContext();147 Date startDate = testContext.getStartDate();148 Date endDate = testContext.getEndDate();149 if (minStartDate.after(startDate)) {150 minStartDate = startDate;151 }152 if (maxEndDate == null || maxEndDate.before(endDate)) {153 maxEndDate = endDate != null ? endDate : startDate;154 }155 }156 // The suite could be completely empty157 if (maxEndDate == null) {158 maxEndDate = minStartDate;159 }160 addDurationAttributes(config, props, minStartDate, maxEndDate);161 return props;162 }163 /**164 * Add started-at, finished-at and duration-ms attributes to the <suite> tag165 */166 public static void addDurationAttributes(XMLReporterConfig config, Properties attributes,167 Date minStartDate, Date maxEndDate) {168 SimpleDateFormat format = new SimpleDateFormat(XMLReporterConfig.getTimestampFormat());169 TimeZone utc = TimeZone.getTimeZone("UTC");170 format.setTimeZone(utc);171 String startTime = format.format(minStartDate);172 String endTime = format.format(maxEndDate);173 long duration = maxEndDate.getTime() - minStartDate.getTime();174 attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);175 attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);176 attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, Long.toString(duration));177 }178 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {179 Set<ITestNGMethod> result = new LinkedHashSet<ITestNGMethod>();180 for (ITestNGMethod method : methods) {181 result.add(method);182 }183 return result;184 }185 // TODO: This is not the smartest way to implement the config186 public int getFileFragmentationLevel() {187 return config.getFileFragmentationLevel();188 }189 public void setFileFragmentationLevel(int fileFragmentationLevel) {190 config.setFileFragmentationLevel(fileFragmentationLevel);191 }192 public int getStackTraceOutputMethod() {193 return config.getStackTraceOutputMethod();194 }195 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {196 config.setStackTraceOutputMethod(stackTraceOutputMethod);197 }198 public String getOutputDirectory() {199 return config.getOutputDirectory();200 }201 public void setOutputDirectory(String outputDirectory) {...

Full Screen

Full Screen

Source:GeneratePassedReports.java Github

copy

Full Screen

...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) {123 Properties methodAttrs = new Properties();124 methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME, groupMethod.getMethodName());125 methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, groupMethod.toString());126 methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, groupMethod.getRealClass().getName());127 xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD, methodAttrs);128 }129 xmlBuffer.pop();130 }131 xmlBuffer.pop();132 }133 private Properties getSuiteAttributes(ISuite suite) {134 Properties props = new Properties();135 props.setProperty(XMLReporterConfig.ATTR_NAME, suite.getName());136 // Calculate the duration137 Map<String, ISuiteResult> results = suite.getResults();138 Date minStartDate = new Date();139 Date maxEndDate = null;140 // TODO: We could probably optimize this in order not to traverse this twice141 for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {142 ITestContext testContext = result.getValue().getTestContext();143 Date startDate = testContext.getStartDate();144 Date endDate = testContext.getEndDate();145 if (minStartDate.after(startDate)) {146 minStartDate = startDate;147 }148 if (maxEndDate == null || maxEndDate.before(endDate)) {149 maxEndDate = endDate != null ? endDate : startDate;150 }151 }152 // The suite could be completely empty153 if (maxEndDate == null) {154 maxEndDate = minStartDate;155 }156 addDurationAttributes(config, props, minStartDate, maxEndDate);157 return props;158 }159 /**160 * Add started-at, finished-at and duration-ms attributes to the <suite> tag161 */162 public static void addDurationAttributes(XMLReporterConfig config, Properties attributes,163 Date minStartDate, Date maxEndDate) {164 SimpleDateFormat format = new SimpleDateFormat(XMLReporterConfig.getTimestampFormat());165 TimeZone utc = TimeZone.getTimeZone("UTC");166 format.setTimeZone(utc);167 String startTime = format.format(minStartDate);168 String endTime = format.format(maxEndDate);169 long duration = maxEndDate.getTime() - minStartDate.getTime();170 attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime);171 attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime);172 attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, Long.toString(duration));173 }174 private Set<ITestNGMethod> getUniqueMethodSet(Collection<ITestNGMethod> methods) {175 Set<ITestNGMethod> result = new LinkedHashSet<ITestNGMethod>();176 for (ITestNGMethod method : methods) {177 result.add(method);178 }179 return result;180 }181 // TODO: This is not the smartest way to implement the config182 public int getFileFragmentationLevel() {183 return config.getFileFragmentationLevel();184 }185 public void setFileFragmentationLevel(int fileFragmentationLevel) {186 config.setFileFragmentationLevel(fileFragmentationLevel);187 }188 public int getStackTraceOutputMethod() {189 return config.getStackTraceOutputMethod();190 }191 public void setStackTraceOutputMethod(int stackTraceOutputMethod) {192 config.setStackTraceOutputMethod(stackTraceOutputMethod);193 }194 public String getOutputDirectory() {195 return config.getOutputDirectory();196 }197 public void setOutputDirectory(String outputDirectory) {...

Full Screen

Full Screen

Source:XMLReporter.java Github

copy

Full Screen

...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();...

Full Screen

Full Screen

Source:EMReporter.java Github

copy

Full Screen

...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()) {...

Full Screen

Full Screen

getFileFragmentationLevel

Using AI Code Generation

copy

Full Screen

1public void testGetFileFragmentationLevel() {2 XMLReporterConfig config = new XMLReporterConfig();3 int level = config.getFileFragmentationLevel();4 System.out.println("The fragmentation level is " + level);5}6What is the difference between the map() and forEach() methods?

Full Screen

Full Screen

getFileFragmentationLevel

Using AI Code Generation

copy

Full Screen

1int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel();2System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);3int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel(2);4System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);5int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel(2, "testng.xml");6System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);7int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel(2, "testng.xml", "testng-results.xml");8System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);9int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel(2, "testng.xml", "testng-results.xml", "testng-results.xml");10System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);11int fragmentationLevel = XMLReporterConfig.getFileFragmentationLevel(2, "testng.xml", "testng-results.xml", "testng-results.xml", "testng-results.xml");12System.out.println("The fragmentation level of a test suite is: " + fragmentationLevel);

Full Screen

Full Screen

getFileFragmentationLevel

Using AI Code Generation

copy

Full Screen

1import org.testng.reporters.XMLReporterConfig;2public class Test {3 public static void main(String[] args) {4 XMLReporterConfig xmlReporterConfig = new XMLReporterConfig();5 int fragmentationLevel = xmlReporterConfig.getFileFragmentationLevel();6 System.out.println("Fragmentation level of the testng-results.xml file: " + fragmentationLevel);7 }8}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful