Best Testng code snippet using org.testng.reporters.EmailableReporter2.writeTableData
Source:CustomEmailableReporter.java
...149 writer.print(" class=\"stripe\"");150 }151 writer.print(">");152 buffer.setLength(0);153 writeTableData(buffer.append("<a href=\"#t").append(testIndex)154 .append("\">")155 .append(Utils.escapeHtml(testResult.getTestName()))156 .append("</a>").toString());157 writeTableData(integerFormat.format(passedTests), "num");158 writeTableData(integerFormat.format(skippedTests),159 (skippedTests > 0 ? "num attn" : "num"));160 writeTableData(integerFormat.format(failedTests),161 (failedTests > 0 ? "num attn" : "num"));162 writeTableData(decimalFormat.format(duration), "num");163 writeTableData(testResult.getIncludedGroups());164 writeTableData(testResult.getExcludedGroups());165 writer.print("</tr>");166 totalPassedTests += passedTests;167 totalSkippedTests += skippedTests;168 totalFailedTests += failedTests;169 totalDuration += duration;170 testIndex++;171 }172 }173 // Print totals if there was more than one test174 if (testIndex > 1) {175 writer.print("<tr>");176 writer.print("<th>Total</th>");177 writeTableHeader(integerFormat.format(totalPassedTests), "num");178 writeTableHeader(integerFormat.format(totalSkippedTests),179 (totalSkippedTests > 0 ? "num attn" : "num"));180 writeTableHeader(integerFormat.format(totalFailedTests),181 (totalFailedTests > 0 ? "num attn" : "num"));182 writeTableHeader(decimalFormat.format(totalDuration), "num");183 writer.print("<th colspan=\"2\"></th>");184 writer.print("</tr>");185 }186 writer.print("</table>");187 }188 /**189 * Writes a summary of all the test scenarios.190 */191 @Override192 protected void writeScenarioSummary() {193 writer.print("</br>");194 writer.print("<h1>Detailed Test Report</h1>");195 writer.print("<table>");196 writer.print("<thead>");197 writer.print("<tr>");198 /* writer.print("<th>Class</th>");*/199 writer.print("<th>Method</th>");200 writer.print("<th>Description</th>");201 writer.print("<th>Start</th>");202 writer.print("<th>Time (ms)</th>");203 writer.print("</tr>");204 writer.print("</thead>");205 int testIndex = 0;206 int scenarioIndex = 0;207 for (SuiteResult suiteResult : suiteResults) {208 writer.print("<tbody><tr><th colspan=\"4\">");209 writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));210 writer.print("</th></tr></tbody>");211 for (TestResult testResult : suiteResult.getTestResults()) {212 writer.print("<tbody id=\"t");213 writer.print(testIndex);214 writer.print("\">");215 String testName = Utils.escapeHtml(testResult.getTestName());216 scenarioIndex += writeScenarioSummary(testName217 + " — failed (configuration methods)",218 testResult.getFailedConfigurationResults(), "failed",219 scenarioIndex);220 scenarioIndex += writeScenarioSummary(testName221 + " — failed", testResult.getFailedTestResults(),222 "failed", scenarioIndex);223 scenarioIndex += writeScenarioSummary(testName224 + " — skipped (configuration methods)",225 testResult.getSkippedConfigurationResults(), "skipped",226 scenarioIndex);227 scenarioIndex += writeScenarioSummary(testName228 + " — skipped",229 testResult.getSkippedTestResults(), "skipped",230 scenarioIndex);231 scenarioIndex += writeScenarioSummary(testName232 + " — passed", testResult.getPassedTestResults(),233 "passed", scenarioIndex);234 writer.print("</tbody>");235 testIndex++;236 }237 }238 writer.print("</table>");239 }240 /**241 * Writes the scenario summary for the results of a given state for a single242 * test.243 */244 private int writeScenarioSummary(String description,245 List<ClassResult> classResults, String cssClassPrefix,246 int startingScenarioIndex) {247 int scenarioCount = 0;248 if (!classResults.isEmpty()) {249 writer.print("<tr><th colspan=\"4\">");250 writer.print(description);251 writer.print("</th></tr>");252 int scenarioIndex = startingScenarioIndex;253 int classIndex = 0;254 for (ClassResult classResult : classResults) {255 String cssClass = cssClassPrefix256 + ((classIndex % 2) == 0 ? "even" : "odd");257 buffer.setLength(0);258 int scenariosPerClass = 0;259 int methodIndex = 0;260 for (MethodResult methodResult : classResult.getMethodResults()) {261 List<ITestResult> results = methodResult.getResults();262 int resultsCount = results.size();263 assert resultsCount > 0;264 ITestResult firstResult = results.iterator().next();265 String methodName = Utils.escapeHtml(firstResult266 .getMethod().getMethodName());267 String descMethod = " ";268 if(firstResult.getMethod().getDescription()!=null)269 descMethod = Utils.escapeHtml(firstResult270 .getMethod().getDescription());271 long start = firstResult.getStartMillis();272 long duration = firstResult.getEndMillis() - start;273 // The first method per class shares a row with the class274 // header275 if (methodIndex > 0) {276 buffer.append("<tr class=\"").append(cssClass)277 .append("\">");278 }279 // Write the timing information with the first scenario per280 // method281 buffer.append("<td><a href=\"#m").append(scenarioIndex)282 .append("\">").append(methodName)283 .append("</a></td>").append("<td rowspan=\"")284 .append(resultsCount).append("\">").append(descMethod)285 .append("</td>").append("<td rowspan=\"")286 .append(resultsCount).append("\">").append(start)287 .append("</td>").append("<td rowspan=\"")288 .append(resultsCount).append("\">")289 .append(duration).append("</td></tr>");290 scenarioIndex++;291 // Write the remaining scenarios for the method292 for (int i = 1; i < resultsCount; i++) {293 buffer.append("<tr class=\"").append(cssClass)294 .append("\">").append("<td><a href=\"#m")295 .append(scenarioIndex).append("\">")296 .append(methodName).append("</a></td></tr>");297 scenarioIndex++;298 }299 scenariosPerClass += resultsCount;300 methodIndex++;301 }302 // Write the test results for the class303 writer.print("<tr class=\"");304 writer.print(cssClass);305 writer.print("\">");306/* writer.print("<td rowspan=\"");307 writer.print(scenariosPerClass);308 writer.print("\">");309 writer.print(Utils.escapeHtml(classResult.getClassName()));310 writer.print("</td>");*/311 writer.print(buffer);312 classIndex++;313 }314 scenarioCount = scenarioIndex - startingScenarioIndex;315 }316 return scenarioCount;317 }318 /**319 * Writes the details for all test scenarios.320 */321 @Override322 protected void writeScenarioDetails() {323 int scenarioIndex = 0;324 for (SuiteResult suiteResult : suiteResults) {325 for (TestResult testResult : suiteResult.getTestResults()) {326 writer.print("<h2>");327 writer.print(Utils.escapeHtml(testResult.getTestName()));328 writer.print("</h2>");329 scenarioIndex += writeScenarioDetails(330 testResult.getFailedConfigurationResults(),331 scenarioIndex);332 scenarioIndex += writeScenarioDetails(333 testResult.getFailedTestResults(), scenarioIndex);334 scenarioIndex += writeScenarioDetails(335 testResult.getSkippedConfigurationResults(),336 scenarioIndex);337 scenarioIndex += writeScenarioDetails(338 testResult.getSkippedTestResults(), scenarioIndex);339 scenarioIndex += writeScenarioDetails(340 testResult.getPassedTestResults(), scenarioIndex);341 }342 }343 }344 /**345 * Writes the scenario details for the results of a given state for a single346 * test.347 */348 private int writeScenarioDetails(List<ClassResult> classResults,349 int startingScenarioIndex) {350 int scenarioIndex = startingScenarioIndex;351 for (ClassResult classResult : classResults) {352 String className = classResult.getClassName();353 for (MethodResult methodResult : classResult.getMethodResults()) {354 List<ITestResult> results = methodResult.getResults();355 assert !results.isEmpty();356 String label = Utils357 .escapeHtml(className358 + "#"359 + results.iterator().next().getMethod()360 .getMethodName());361 for (ITestResult result : results) {362 if(!result.isSuccess())363 {364 writeScenario(scenarioIndex, label, result);365 scenarioIndex++;366 }367 }368 }369 }370 return scenarioIndex - startingScenarioIndex;371 }372 /**373 * Writes the details for an individual test scenario.374 */375 private void writeScenario(int scenarioIndex, String label,376 ITestResult result) {377 writer.print("<h3 id=\"m");378 writer.print(scenarioIndex);379 writer.print("\">");380 writer.print(label);381 writer.print("</h3>");382 writer.print("<table class=\"result\">");383 // Write test parameters (if any)384 Object[] parameters = result.getParameters();385 int parameterCount = (parameters == null ? 0 : parameters.length);386 if (parameterCount > 0) {387 writer.print("<tr class=\"param\">");388 for (int i = 1; i <= parameterCount; i++) {389 writer.print("<th>Parameter #");390 writer.print(i);391 writer.print("</th>");392 }393 writer.print("</tr><tr class=\"param stripe\">");394 for (Object parameter : parameters) {395 writer.print("<td>");396 writer.print(Utils.escapeHtml(Utils.toString(parameter)));397 writer.print("</td>");398 }399 writer.print("</tr>");400 }401 // Write reporter messages (if any)402 List<String> reporterMessages = Reporter.getOutput(result);403 if (!reporterMessages.isEmpty()) {404 writer.print("<tr><th");405 if (parameterCount > 1) {406 writer.print(" colspan=\"");407 writer.print(parameterCount);408 writer.print("\"");409 }410 writer.print(">Messages</th></tr>");411 writer.print("<tr><td");412 if (parameterCount > 1) {413 writer.print(" colspan=\"");414 writer.print(parameterCount);415 writer.print("\"");416 }417 writer.print(">");418 writeReporterMessages(reporterMessages);419 writer.print("</td></tr>");420 }421 // Write exception (if any)422 Throwable throwable = result.getThrowable();423 if (throwable != null) {424 writer.print("<tr><th");425 if (parameterCount > 1) {426 writer.print(" colspan=\"");427 writer.print(parameterCount);428 writer.print("\"");429 }430 writer.print(">");431 writer.print((result.getStatus() == ITestResult.SUCCESS ? "Expected Exception"432 : "Exception"));433 writer.print("</th></tr>");434 writer.print("<tr><td");435 if (parameterCount > 1) {436 writer.print(" colspan=\"");437 writer.print(parameterCount);438 writer.print("\"");439 }440 writer.print(">");441 writeStackTrace(throwable);442 writer.print("</td></tr>");443 }444 writer.print("</table>");445 writer.print("<p class=\"totop\"><a href=\"#summary\">back to summary</a></p>");446 }447 @Override448 protected void writeReporterMessages(List<String> reporterMessages) {449 writer.print("<div class=\"messages\">");450 Iterator<String> iterator = reporterMessages.iterator();451 assert iterator.hasNext();452 writer.print(Utils.escapeHtml(iterator.next()));453 while (iterator.hasNext()) {454 writer.print("<br/>");455 writer.print(Utils.escapeHtml(iterator.next()));456 }457 writer.print("</div>");458 }459 @Override460 protected void writeStackTrace(Throwable throwable) {461 writer.print("<div class=\"stacktrace\">");462 writer.print(Utils.stackTrace(throwable, true)[0]);463 writer.print("</div>");464 }465 /**466 * Writes a TH element with the specified contents and CSS class names.467 * 468 * @param html469 * the HTML contents470 * @param cssClasses471 * the space-delimited CSS classes or null if there are no472 * classes to apply473 */474 @Override475 protected void writeTableHeader(String html, String cssClasses) {476 writeTag("th", html, cssClasses);477 }478 /**479 * Writes a TD element with the specified contents.480 * 481 * @param html482 * the HTML contents483 */484 @Override485 protected void writeTableData(String html) {486 writeTableData(html, null);487 }488 /**489 * Writes a TD element with the specified contents and CSS class names.490 * 491 * @param html492 * the HTML contents493 * @param cssClasses494 * the space-delimited CSS classes or null if there are no495 * classes to apply496 */497 @Override498 protected void writeTableData(String html, String cssClasses) {499 writeTag("td", html, cssClasses);500 }501 /**502 * Writes an arbitrary HTML element with the specified contents and CSS503 * class names.504 * 505 * @param tag506 * the tag name507 * @param html508 * the HTML contents509 * @param cssClasses510 * the space-delimited CSS classes or null if there are no511 * classes to apply512 */...
Source:EmailableReporter2.java
...137 writer.print(" class=\"stripe\"");138 }139 writer.print(">");140 buffer.setLength(0);141 writeTableData(buffer.append("<a href=\"#t").append(testIndex)142 .append("\">")143 .append(Utils.escapeHtml(testResult.getTestName()))144 .append("</a>").toString());145 writeTableData(integerFormat.format(passedTests), "num");146 writeTableData(integerFormat.format(skippedTests),147 (skippedTests > 0 ? "num attn" : "num"));148 writeTableData(integerFormat.format(failedTests),149 (failedTests > 0 ? "num attn" : "num"));150 writeTableData(decimalFormat.format(duration), "num");151 writeTableData(testResult.getIncludedGroups());152 writeTableData(testResult.getExcludedGroups());153 writer.println("</tr>");154 totalPassedTests += passedTests;155 totalSkippedTests += skippedTests;156 totalFailedTests += failedTests;157 totalDuration += duration;158 testIndex++;159 }160 }161 // Print totals if there was more than one test162 if (testIndex > 1) {163 writer.print("<tr>");164 writer.print("<th>Total</th>");165 writeTableHeader(integerFormat.format(totalPassedTests), "num");166 writeTableHeader(integerFormat.format(totalSkippedTests),167 (totalSkippedTests > 0 ? "num attn" : "num"));168 writeTableHeader(integerFormat.format(totalFailedTests),169 (totalFailedTests > 0 ? "num attn" : "num"));170 writeTableHeader(decimalFormat.format(totalDuration), "num");171 writer.print("<th colspan=\"2\"></th>");172 writer.println("</tr>");173 }174 writer.println("</table>");175 }176 /**177 * Writes a summary of all the test scenarios.178 */179 protected void writeScenarioSummary() {180 writer.print("<table id='summary'>");181 writer.print("<thead>");182 writer.print("<tr>");183 writer.print("<th>Class</th>");184 writer.print("<th>Method</th>");185 writer.print("<th>Start</th>");186 writer.print("<th>Time (ms)</th>");187 writer.print("</tr>");188 writer.print("</thead>");189 int testIndex = 0;190 int scenarioIndex = 0;191 for (SuiteResult suiteResult : suiteResults) {192 writer.print("<tbody><tr><th colspan=\"4\">");193 writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));194 writer.print("</th></tr></tbody>");195 for (TestResult testResult : suiteResult.getTestResults()) {196 writer.printf("<tbody id=\"t%d\">", testIndex);197 String testName = Utils.escapeHtml(testResult.getTestName());198 int startIndex = scenarioIndex;199 scenarioIndex += writeScenarioSummary(testName200 + " — failed (configuration methods)",201 testResult.getFailedConfigurationResults(), "failed",202 scenarioIndex);203 scenarioIndex += writeScenarioSummary(testName204 + " — failed", testResult.getFailedTestResults(),205 "failed", scenarioIndex);206 scenarioIndex += writeScenarioSummary(testName207 + " — skipped (configuration methods)",208 testResult.getSkippedConfigurationResults(), "skipped",209 scenarioIndex);210 scenarioIndex += writeScenarioSummary(testName211 + " — skipped",212 testResult.getSkippedTestResults(), "skipped",213 scenarioIndex);214 scenarioIndex += writeScenarioSummary(testName215 + " — passed", testResult.getPassedTestResults(),216 "passed", scenarioIndex);217 if (scenarioIndex == startIndex) {218 writer.print("<tr><th colspan=\"4\" class=\"invisible\"/></tr>");219 }220 writer.println("</tbody>");221 testIndex++;222 }223 }224 writer.println("</table>");225 }226 /**227 * Writes the scenario summary for the results of a given state for a single228 * test.229 */230 private int writeScenarioSummary(String description,231 List<ClassResult> classResults, String cssClassPrefix,232 int startingScenarioIndex) {233 int scenarioCount = 0;234 if (!classResults.isEmpty()) {235 writer.print("<tr><th colspan=\"4\">");236 writer.print(description);237 writer.print("</th></tr>");238 int scenarioIndex = startingScenarioIndex;239 int classIndex = 0;240 for (ClassResult classResult : classResults) {241 String cssClass = cssClassPrefix242 + ((classIndex % 2) == 0 ? "even" : "odd");243 buffer.setLength(0);244 int scenariosPerClass = 0;245 int methodIndex = 0;246 for (MethodResult methodResult : classResult.getMethodResults()) {247 List<ITestResult> results = methodResult.getResults();248 int resultsCount = results.size();249 assert resultsCount > 0;250 ITestResult firstResult = results.iterator().next();251 String methodName = Utils.escapeHtml(firstResult252 .getMethod().getMethodName());253 long start = firstResult.getStartMillis();254 long duration = firstResult.getEndMillis() - start;255 // The first method per class shares a row with the class256 // header257 if (methodIndex > 0) {258 buffer.append("<tr class=\"").append(cssClass)259 .append("\">");260 }261 // Write the timing information with the first scenario per262 // method263 buffer.append("<td><a href=\"#m").append(scenarioIndex)264 .append("\">").append(methodName)265 .append("</a></td>").append("<td rowspan=\"")266 .append(resultsCount).append("\">").append(start)267 .append("</td>").append("<td rowspan=\"")268 .append(resultsCount).append("\">")269 .append(duration).append("</td></tr>");270 scenarioIndex++;271 // Write the remaining scenarios for the method272 for (int i = 1; i < resultsCount; i++) {273 buffer.append("<tr class=\"").append(cssClass)274 .append("\">").append("<td><a href=\"#m")275 .append(scenarioIndex).append("\">")276 .append(methodName).append("</a></td></tr>");277 scenarioIndex++;278 }279 scenariosPerClass += resultsCount;280 methodIndex++;281 }282 // Write the test results for the class283 writer.print("<tr class=\"");284 writer.print(cssClass);285 writer.print("\">");286 writer.print("<td rowspan=\"");287 writer.print(scenariosPerClass);288 writer.print("\">");289 writer.print(Utils.escapeHtml(classResult.getClassName()));290 writer.print("</td>");291 writer.print(buffer);292 classIndex++;293 }294 scenarioCount = scenarioIndex - startingScenarioIndex;295 }296 return scenarioCount;297 }298 /**299 * Writes the details for all test scenarios.300 */301 protected void writeScenarioDetails() {302 int scenarioIndex = 0;303 for (SuiteResult suiteResult : suiteResults) {304 for (TestResult testResult : suiteResult.getTestResults()) {305 writer.print("<h2>");306 writer.print(Utils.escapeHtml(testResult.getTestName()));307 writer.print("</h2>");308 scenarioIndex += writeScenarioDetails(309 testResult.getFailedConfigurationResults(),310 scenarioIndex);311 scenarioIndex += writeScenarioDetails(312 testResult.getFailedTestResults(), scenarioIndex);313 scenarioIndex += writeScenarioDetails(314 testResult.getSkippedConfigurationResults(),315 scenarioIndex);316 scenarioIndex += writeScenarioDetails(317 testResult.getSkippedTestResults(), scenarioIndex);318 scenarioIndex += writeScenarioDetails(319 testResult.getPassedTestResults(), scenarioIndex);320 }321 }322 }323 /**324 * Writes the scenario details for the results of a given state for a single325 * test.326 */327 private int writeScenarioDetails(List<ClassResult> classResults,328 int startingScenarioIndex) {329 int scenarioIndex = startingScenarioIndex;330 for (ClassResult classResult : classResults) {331 String className = classResult.getClassName();332 for (MethodResult methodResult : classResult.getMethodResults()) {333 List<ITestResult> results = methodResult.getResults();334 assert !results.isEmpty();335 String label = Utils336 .escapeHtml(className337 + "#"338 + results.iterator().next().getMethod()339 .getMethodName());340 for (ITestResult result : results) {341 writeScenario(scenarioIndex, label, result);342 scenarioIndex++;343 }344 }345 }346 return scenarioIndex - startingScenarioIndex;347 }348 /**349 * Writes the details for an individual test scenario.350 */351 private void writeScenario(int scenarioIndex, String label,352 ITestResult result) {353 writer.print("<h3 id=\"m");354 writer.print(scenarioIndex);355 writer.print("\">");356 writer.print(label);357 writer.print("</h3>");358 writer.print("<table class=\"result\">");359 boolean hasRows = false;360 // Write test parameters (if any)361 Object[] parameters = result.getParameters();362 int parameterCount = (parameters == null ? 0 : parameters.length);363 if (parameterCount > 0) {364 writer.print("<tr class=\"param\">");365 for (int i = 1; i <= parameterCount; i++) {366 writer.print("<th>Parameter #");367 writer.print(i);368 writer.print("</th>");369 }370 writer.print("</tr><tr class=\"param stripe\">");371 for (Object parameter : parameters) {372 writer.print("<td>");373 writer.print(Utils.escapeHtml(Utils.toString(parameter)));374 writer.print("</td>");375 }376 writer.print("</tr>");377 hasRows = true;378 }379 // Write reporter messages (if any)380 List<String> reporterMessages = Reporter.getOutput(result);381 if (!reporterMessages.isEmpty()) {382 writer.print("<tr><th");383 if (parameterCount > 1) {384 writer.printf(" colspan=\"%d\"", parameterCount);385 }386 writer.print(">Messages</th></tr>");387 writer.print("<tr><td");388 if (parameterCount > 1) {389 writer.printf(" colspan=\"%d\"", parameterCount);390 }391 writer.print(">");392 writeReporterMessages(reporterMessages);393 writer.print("</td></tr>");394 hasRows = true;395 }396 // Write exception (if any)397 Throwable throwable = result.getThrowable();398 if (throwable != null) {399 writer.print("<tr><th");400 if (parameterCount > 1) {401 writer.printf(" colspan=\"%d\"", parameterCount);402 }403 writer.print(">");404 writer.print((result.getStatus() == ITestResult.SUCCESS ? "Expected Exception"405 : "Exception"));406 writer.print("</th></tr>");407 writer.print("<tr><td");408 if (parameterCount > 1) {409 writer.printf(" colspan=\"%d\"", parameterCount);410 }411 writer.print(">");412 writeStackTrace(throwable);413 writer.print("</td></tr>");414 hasRows = true;415 }416 if (!hasRows) {417 writer.print("<tr><th");418 if (parameterCount > 1) {419 writer.printf(" colspan=\"%d\"", parameterCount);420 }421 writer.print(" class=\"invisible\"/></tr>");422 }423 writer.print("</table>");424 writer.println("<p class=\"totop\"><a href=\"#summary\">back to summary</a></p>");425 }426 protected void writeReporterMessages(List<String> reporterMessages) {427 writer.print("<div class=\"messages\">");428 Iterator<String> iterator = reporterMessages.iterator();429 assert iterator.hasNext();430 if (Reporter.getEscapeHtml()) {431 writer.print(Utils.escapeHtml(iterator.next()));432 } else {433 writer.print(iterator.next());434 }435 while (iterator.hasNext()) {436 writer.print("<br/>");437 if (Reporter.getEscapeHtml()) {438 writer.print(Utils.escapeHtml(iterator.next()));439 } else {440 writer.print(iterator.next());441 }442 }443 writer.print("</div>");444 }445 protected void writeStackTrace(Throwable throwable) {446 writer.print("<div class=\"stacktrace\">");447 writer.print(Utils.shortStackTrace(throwable, true));448 writer.print("</div>");449 }450 /**451 * Writes a TH element with the specified contents and CSS class names.452 * 453 * @param html454 * the HTML contents455 * @param cssClasses456 * the space-delimited CSS classes or null if there are no457 * classes to apply458 */459 protected void writeTableHeader(String html, String cssClasses) {460 writeTag("th", html, cssClasses);461 }462 /**463 * Writes a TD element with the specified contents.464 * 465 * @param html466 * the HTML contents467 */468 protected void writeTableData(String html) {469 writeTableData(html, null);470 }471 /**472 * Writes a TD element with the specified contents and CSS class names.473 * 474 * @param html475 * the HTML contents476 * @param cssClasses477 * the space-delimited CSS classes or null if there are no478 * classes to apply479 */480 protected void writeTableData(String html, String cssClasses) {481 writeTag("td", html, cssClasses);482 }483 /**484 * Writes an arbitrary HTML element with the specified contents and CSS485 * class names.486 * 487 * @param tag488 * the tag name489 * @param html490 * the HTML contents491 * @param cssClasses492 * the space-delimited CSS classes or null if there are no493 * classes to apply494 */...
Source:CustomReport.java
...184 }185 writer.print(">");186187 buffer.setLength(0);188 writeTableData(buffer.append("<a href=\"#t").append(testIndex).append("\">")189 .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());190 writeTableData(integerFormat.format(passedTests), "num");191 writeTableData(integerFormat.format(skippedTests), (skippedTests > 0 ? "num attn" : "num"));192 writeTableData(integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num"));193 writeTableData(decimalFormat.format(millisecondsToSeconds(duration)), "num");194 writeTableData(testResult.getIncludedGroups());195 writeTableData(testResult.getExcludedGroups());196197 writer.print("</tr>");198199 totalPassedTests += passedTests;200 totalSkippedTests += skippedTests;201 totalFailedTests += failedTests;202 totalDuration += duration;203204 testIndex++;205 }206 }207208 // Print totals if there was more than one test209 if (testIndex >= 1) {210 writer.print("<tr>");211 writer.print("<th>Total</th>");212 writeTableHeader(integerFormat.format(totalPassedTests), "num");213 writeTableHeader(integerFormat.format(totalSkippedTests), (totalSkippedTests > 0 ? "num attn" : "num"));214 writeTableHeader(integerFormat.format(totalFailedTests), (totalFailedTests > 0 ? "num attn" : "num"));215 writeTableHeader(decimalFormat.format(millisecondsToSeconds(totalDuration)), "num");216 writer.print("<th colspan=\"2\"></th>");217 writer.print("</tr>");218 }219220 writer.print("</table>");221 }222223 /**224 * Writes a summary of all the test scenarios.225 */226 protected void writeScenarioSummary() {227 writer.print("<table>");228 writer.print("<thead>");229 writer.print("<tr>");230 writer.print("<th>Class</th>");231 writer.print("<th>Method</th>");232 writer.print("<th>Name</th>");233 writer.print("<th>Start</th>");234 writer.print("<th>Seconds</th>");235 writer.print("</tr>");236 writer.print("</thead>");237238 int testIndex = 0;239 int scenarioIndex = 0;240 for (SuiteResult suiteResult : suiteResults) {241 writer.print("<tbody><tr><th colspan=\"5\">");242 writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));243 writer.print("</th></tr></tbody>");244245 for (TestResult testResult : suiteResult.getTestResults()) {246 writer.print("<tbody id=\"t");247 writer.print(testIndex);248 writer.print("\">");249250 String testName = Utils.escapeHtml(testResult.getTestName());251252 scenarioIndex += writeScenarioSummary(testName + " — failed (configuration methods)",253 testResult.getFailedConfigurationResults(), "failed", scenarioIndex);254 scenarioIndex += writeScenarioSummary(testName + " — failed", testResult.getFailedTestResults(),255 "failed", scenarioIndex);256 scenarioIndex += writeScenarioSummary(testName + " — skipped (configuration methods)",257 testResult.getSkippedConfigurationResults(), "skipped", scenarioIndex);258 scenarioIndex += writeScenarioSummary(testName + " — skipped", testResult.getSkippedTestResults(),259 "skipped", scenarioIndex);260 scenarioIndex += writeScenarioSummary(testName + " — passed", testResult.getPassedTestResults(),261 "passed", scenarioIndex);262263 writer.print("</tbody>");264265 testIndex++;266 }267 }268269 writer.print("</table>");270 }271272 /**273 * Writes the scenario summary for the results of a given state for a single274 * test.275 */276 private int writeScenarioSummary(String description, List<ClassResult> classResults, String cssClassPrefix,277 int startingScenarioIndex) {278 int scenarioCount = 0;279 if (!classResults.isEmpty()) {280 writer.print("<tr><th colspan=\"5\">");281 writer.print(description);282 writer.print("</th></tr>");283284 int scenarioIndex = startingScenarioIndex;285 int classIndex = 0;286 for (ClassResult classResult : classResults) {287 String cssClass = cssClassPrefix + ((classIndex % 2) == 0 ? "even" : "odd");288289 buffer.setLength(0);290291 int scenariosPerClass = 0;292 int methodIndex = 0;293 for (MethodResult methodResult : classResult.getMethodResults()) {294 List<ITestResult> results = methodResult.getResults();295 int resultsCount = results.size();296 assert resultsCount > 0;297298 ITestResult aResult = results.iterator().next();299 String methodName = Utils.escapeHtml(aResult.getMethod().getMethodName());300 long start = aResult.getStartMillis();301 long duration = aResult.getEndMillis() - start;302303 // The first method per class shares a row with the class304 // header305 if (methodIndex > 0) {306 buffer.append("<tr class=\"").append(cssClass).append("\">");307308 }309310 // Write the timing information with the first scenario per311 // method312 buffer.append("<td><a href=\"#m").append(scenarioIndex).append("\">")313 .append(methodName + "</a></td>").append("<td rowspan=\"1\">" + aResult.getName() + "</td>")314 .append("<td rowspan=\"").append(resultsCount).append("\">")315 .append(parseUnixTimeToTimeOfDay(start)).append("</td>").append("<td rowspan=\"")316 .append(resultsCount).append("\">")317 .append(decimalFormat.format(millisecondsToSeconds(duration))).append("</td></tr>");318 scenarioIndex++;319320 // Write the remaining scenarios for the method321 for (int i = 1; i < resultsCount; i++) {322 buffer.append("<tr class=\"").append(cssClass).append("\">").append("<td><a href=\"#m")323 .append(scenarioIndex).append("\">").append(methodName + "</a></td>")324 .append("<td rowspan=\"1\">" + aResult.getName() + "</td></tr>");325 scenarioIndex++;326 }327328 scenariosPerClass += resultsCount;329 methodIndex++;330 }331332 // Write the test results for the class333 writer.print("<tr class=\"");334 writer.print(cssClass);335 writer.print("\">");336 writer.print("<td rowspan=\"");337 writer.print(scenariosPerClass);338 writer.print("\">");339 writer.print(Utils.escapeHtml(classResult.getClassName()));340 writer.print("</td>");341 writer.print(buffer);342343 classIndex++;344 }345 scenarioCount = scenarioIndex - startingScenarioIndex;346 }347 return scenarioCount;348 }349350 /**351 * Writes the details for all test scenarios.352 */353 protected void writeScenarioDetails() {354 int scenarioIndex = 0;355 for (SuiteResult suiteResult : suiteResults) {356 for (TestResult testResult : suiteResult.getTestResults()) {357 writer.print("<h2>");358 writer.print(Utils.escapeHtml(testResult.getTestName()));359 writer.print("</h2>");360361 scenarioIndex += writeScenarioDetails(testResult.getFailedConfigurationResults(), scenarioIndex);362 scenarioIndex += writeScenarioDetails(testResult.getFailedTestResults(), scenarioIndex);363 scenarioIndex += writeScenarioDetails(testResult.getSkippedConfigurationResults(), scenarioIndex);364 scenarioIndex += writeScenarioDetails(testResult.getSkippedTestResults(), scenarioIndex);365 scenarioIndex += writeScenarioDetails(testResult.getPassedTestResults(), scenarioIndex);366 }367 }368 }369370 /**371 * Writes the scenario details for the results of a given state for a single372 * test.373 */374 private int writeScenarioDetails(List<ClassResult> classResults, int startingScenarioIndex) {375 int scenarioIndex = startingScenarioIndex;376 for (ClassResult classResult : classResults) {377 String className = classResult.getClassName();378 for (MethodResult methodResult : classResult.getMethodResults()) {379 List<ITestResult> results = methodResult.getResults();380 assert !results.isEmpty();381382 ITestResult mResult = results.iterator().next();383 String label = Utils.escapeHtml(384 className + "#" + mResult.getMethod().getMethodName() + " ( " + mResult.getName() + " )");385 for (ITestResult result : results) {386 writeScenario(scenarioIndex, label, result);387 scenarioIndex++;388 }389 }390 }391392 return scenarioIndex - startingScenarioIndex;393 }394395 /**396 * Writes the details for an individual test scenario.397 */398 private void writeScenario(int scenarioIndex, String label, ITestResult result) {399 writer.print("<h3 id=\"m");400 writer.print(scenarioIndex);401 writer.print("\">");402 writer.print(label);403 writer.print("</h3>");404405 writer.print("<table class=\"result\">");406407 // Write test parameters (if any)408 Object[] parameters = result.getParameters();409 int parameterCount = (parameters == null ? 0 : parameters.length);410 if (parameterCount > 0) {411 writer.print("<tr class=\"param\">");412 for (int i = 1; i <= parameterCount; i++) {413 writer.print("<th>Parameter #");414 writer.print(i);415 writer.print("</th>");416 }417 writer.print("</tr><tr class=\"param stripe\">");418 for (Object parameter : parameters) {419 writer.print("<td>");420 writer.print(Utils.escapeHtml(Utils.toString(parameter, Object.class)));421 writer.print("</td>");422 }423 writer.print("</tr>");424 }425426 // Write reporter messages (if any)427 List<String> reporterMessages = Reporter.getOutput(result);428 if (!reporterMessages.isEmpty()) {429 writer.print("<tr><th");430 if (parameterCount > 1) {431 writer.print(" colspan=\"");432 writer.print(parameterCount);433 writer.print("\"");434 }435 writer.print(">Messages</th></tr>");436437 writer.print("<tr><td");438 if (parameterCount > 1) {439 writer.print(" colspan=\"");440 writer.print(parameterCount);441 writer.print("\"");442 }443 writer.print(">");444 writeReporterMessages(reporterMessages);445 writer.print("</td></tr>");446 }447448 // Write exception (if any)449 Throwable throwable = result.getThrowable();450 if (throwable != null) {451 writer.print("<tr><th");452 if (parameterCount > 1) {453 writer.print(" colspan=\"");454 writer.print(parameterCount);455 writer.print("\"");456 }457 writer.print(">");458 writer.print((result.getStatus() == ITestResult.SUCCESS ? "Expected Exception" : "Exception"));459 writer.print("</th></tr>");460461 writer.print("<tr><td");462 if (parameterCount > 1) {463 writer.print(" colspan=\"");464 writer.print(parameterCount);465 writer.print("\"");466 }467 writer.print(">");468 writeStackTrace(throwable);469 writer.print("</td></tr>");470 }471472 writer.print("</table>");473 writer.print("<p class=\"totop\"><a href=\"#summary\">back to summary</a></p>");474 }475476 protected void writeReporterMessages(List<String> reporterMessages) {477 writer.print("<div class=\"messages\">");478 Iterator<String> iterator = reporterMessages.iterator();479 assert iterator.hasNext();480 writer.print(Utils.escapeHtml(iterator.next()));481 while (iterator.hasNext()) {482 writer.print("<br/>");483 writer.print(Utils.escapeHtml(iterator.next()));484 }485 writer.print("</div>");486 }487488 protected void writeStackTrace(Throwable throwable) {489 writer.print("<div class=\"stacktrace\">");490 writer.print(Utils.stackTrace(throwable, true)[0]);491 writer.print("</div>");492 }493494 /**495 * Writes a TH element with the specified contents and CSS class names.496 *497 * @param html498 * the HTML contents499 * @param cssClasses500 * the space-delimited CSS classes or null if there are no501 * classes to apply502 */503 protected void writeTableHeader(String html, String cssClasses) {504 writeTag("th", html, cssClasses);505 }506507 /**508 * Writes a TD element with the specified contents.509 *510 * @param html511 * the HTML contents512 */513 protected void writeTableData(String html) {514 writeTableData(html, null);515 }516517 /**518 * Writes a TD element with the specified contents and CSS class names.519 *520 * @param html521 * the HTML contents522 * @param cssClasses523 * the space-delimited CSS classes or null if there are no524 * classes to apply525 */526 protected void writeTableData(String html, String cssClasses) {527 writeTag("td", html, cssClasses);528 }529530 /**531 * Writes an arbitrary HTML element with the specified contents and CSS532 * class names.533 *534 * @param tag535 * the tag name536 * @param html537 * the HTML contents538 * @param cssClasses539 * the space-delimited CSS classes or null if there are no540 * classes to apply
...
Source:CustomSummaryReport.java
...162 }163 writer.print(">");164165 buffer.setLength(0);166 writeTableData( buffer.append("<a href=\"#t").append(testIndex).append("\">")167 .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());168 writeTableData( integerFormat.format(passedTests), "num");169 writeTableData( integerFormat.format(skippedTests), (skippedTests > 0 ? "num attn" : "num"));170 writeTableData( integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num"));171 writeTableData( decimalFormat.format(millisecondsToSeconds(duration)), "num");172 writeTableData( testResult.getIncludedGroups() );173 writeTableData( testResult.getExcludedGroups() );174175 writer.print("</tr>");176177 totalPassedTests += passedTests;178 totalSkippedTests += skippedTests;179 totalFailedTests += failedTests;180 totalDuration += duration;181182 testIndex++;183 }184 }185186 // Print totals if there was more than one test187 if ( testIndex >= 1 ) {188 writer.print("<tr>");189 writer.print("<th>Total</th>");190 writeTableHeader( integerFormat.format(totalPassedTests), "num");191 writeTableHeader( integerFormat.format(totalSkippedTests), (totalSkippedTests > 0 ? "num attn" : "num"));192 writeTableHeader( integerFormat.format(totalFailedTests), (totalFailedTests > 0 ? "num attn" : "num"));193 writeTableHeader( decimalFormat.format(millisecondsToSeconds(totalDuration)), "num");194 writer.print("<th colspan=\"2\"></th>");195 writer.print("</tr>");196 }197198 writer.print("</table>");199 }200 /**201 * Writes a summary of all the test scenarios.202 */203 protected void writeUserSummary() {204205 TreeMap<String,TreeMap<String,Integer>> userToTestCaseCntMap = new TreeMap<String,TreeMap<String,Integer>>();206207 for ( SuiteResult suiteResult : suiteResults ) {208209 for ( TestResult testResult : suiteResult.getTestResults() ) {210211 @SuppressWarnings("unused")212 String testName = Utils.escapeHtml( testResult.getTestName() );213214 for ( ClassResult classResult : testResult.getFailedTestResults() ) {215 for ( MethodResult methodResult : classResult.getMethodResults() ) {216 List<ITestResult> results = methodResult.getResults();217 int resultsCount = results.size();218 assert resultsCount > 0;219220 ITestResult aResult = results.iterator().next();221 updateUserEntry(aResult,userToTestCaseCntMap,"failure");222 }223 }224 for ( ClassResult classResult : testResult.getSkippedTestResults() ) {225 for ( MethodResult methodResult : classResult.getMethodResults() ) {226 List<ITestResult> results = methodResult.getResults();227 int resultsCount = results.size();228 assert resultsCount > 0;229230 ITestResult aResult = results.iterator().next();231 updateUserEntry(aResult,userToTestCaseCntMap,"skipped");232 }233 }234 for ( ClassResult classResult : testResult.getPassedTestResults() ) {235 for ( MethodResult methodResult : classResult.getMethodResults() ) {236 List<ITestResult> results = methodResult.getResults();237 int resultsCount = results.size();238 assert resultsCount > 0;239240 ITestResult aResult = results.iterator().next();241 updateUserEntry(aResult,userToTestCaseCntMap,"success");242 }243 }244245 }246 }247 writer.print("<table>");248 writer.print("<thead>");249 writer.print("<tr>");250 writer.print("<th>XXX</th>");251 HashMap<String,Integer> hm = new HashMap<String,Integer>();252 for(String user: userToTestCaseCntMap.keySet()){253 writer.print("<th>"+user+"</th>");254 hm.put(user, userToTestCaseCntMap.get(user).get("success")+userToTestCaseCntMap.get(user).get("failure")+userToTestCaseCntMap.get(user).get("skipped"));255 256 }257 writer.print("</tr>");258 writer.print("</thead>");259 writer.print("<tbody>");260 261 writer.print("<tr>");262 writer.print("<td>SUCCESS</td>");263 for(String user: userToTestCaseCntMap.keySet()){264 writer.print("<td>"+userToTestCaseCntMap.get(user).get("success")+"</td>");265 }266 writer.print("</tr>");267 writer.print("<tr>");268 writer.print("<td>FAILURE</td>");269 for(String user: userToTestCaseCntMap.keySet()){270 writer.print("<td>"+userToTestCaseCntMap.get(user).get("failure")+"</td>");271 }272 writer.print("</tr>");273 writer.print("<tr>");274 writer.print("<td>SKIPPED</td>");275 for(String user: userToTestCaseCntMap.keySet()){276 writer.print("<td>"+userToTestCaseCntMap.get(user).get("skipped")+"</td>");277 }278 writer.print("</tr>");279 writer.print("<tr>");280 writer.print("<td>TOTAL</td>");281 for(String user: userToTestCaseCntMap.keySet()){282 writer.print("<td>"+hm.get(user)+"</td>");283 }284 writer.print("</tr>");285 writer.print("</tbody>");286 writer.print("</table>");287 }288289 protected void updateUserEntry(ITestResult aResult, TreeMap<String,TreeMap<String,Integer>> userToTestCaseCntMap, String type){290 String user = "unknown";291 if(aResult.getMethod().getConstructorOrMethod() != null && aResult.getMethod().getConstructorOrMethod().getMethod() != null && aResult.getMethod().getConstructorOrMethod().getMethod().getAnnotation(TestCase.class) != null && aResult.getMethod().getConstructorOrMethod().getMethod().getAnnotation(TestCase.class).Author() !=null){292 user = Utils.escapeHtml(aResult.getMethod().getConstructorOrMethod().getMethod().getAnnotation(TestCase.class).Author()).trim();293 }294 if(userToTestCaseCntMap.containsKey(user)){295 for(String key: userToTestCaseCntMap.keySet()){296 if(user.equalsIgnoreCase(key)){297 if(userToTestCaseCntMap.get(key) == null || userToTestCaseCntMap.get(key).isEmpty()){298 TreeMap<String,Integer> tm = new TreeMap<String,Integer>();299 tm.put("success", 0);300 tm.put("failure", 0);301 tm.put("skipped", 0);302 userToTestCaseCntMap.put(key,tm);303304 }else{305 TreeMap<String,Integer> tm = userToTestCaseCntMap.get(key);306 tm.put(type,tm.get(type)+1);307308 break;309 }310 }311 }312 }else{313 TreeMap<String,Integer> tm = new TreeMap<String,Integer>();314 tm.put("success", 0);315 tm.put("failure", 0);316 tm.put("skipped", 0);317 tm.put(type,1);318 userToTestCaseCntMap.put(user,tm);319 }320321 }322 323 /**324 * Writes a TH element with the specified contents and CSS class names.325 *326 * @param html the HTML contents327 * @param cssClasses the space-delimited CSS classes or null if there are no328 * classes to apply329 */330 protected void writeTableHeader(String html, String cssClasses) {331 writeTag("th", html, cssClasses);332 }333334 /**335 * Writes a TD element with the specified contents.336 *337 * @param html the HTML contents338 */339 protected void writeTableData(String html) {340 writeTableData(html, null);341 }342343 /**344 * Writes a TD element with the specified contents and CSS class names.345 *346 * @param html the HTML contents347 * @param cssClasses the space-delimited CSS classes or null if there are no348 * classes to apply349 */350 protected void writeTableData(String html, String cssClasses) {351 writeTag("td", html, cssClasses);352 }353354 /**355 * Writes an arbitrary HTML element with the specified contents and CSS356 * class names.357 *358 * @param tag the tag name359 * @param html the HTML contents360 * @param cssClasses the space-delimited CSS classes or null if there are no361 * classes to apply362 */363 protected void writeTag(String tag, String html, String cssClasses) {364 writer.print("<");
...
writeTableData
Using AI Code Generation
1import org.testng.annotations.Test;2public class TestNGEmailableReport {3 public void testMethod1() {4 System.out.println("TestNG_ReportsAndLogs -> testMethod1");5 }6 public void testMethod2() {7 System.out.println("TestNG_ReportsAndLogs -> testMethod2");8 }9 public void testMethod3() {10 System.out.println("TestNG_ReportsAndLogs -> testMethod3");11 }12 public void testMethod4() {13 System.out.println("TestNG_ReportsAndLogs -> testMethod4");14 }15 public void testMethod5() {16 System.out.println("TestNG_ReportsAndLogs -> testMethod5");17 }18}
writeTableData
Using AI Code Generation
1EmailableReporter2 er = new EmailableReporter2();2er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, false, "table-id");3EmailableReporter2 er = new EmailableReporter2();4er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, true, "table-id");5EmailableReporter2 er = new EmailableReporter2();6er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, true, "table-id");7EmailableReporter2 er = new EmailableReporter2();8er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, false, "table-id");9EmailableReporter2 er = new EmailableReporter2();10er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, true, "table-id");11EmailableReporter2 er = new EmailableReporter2();12er.writeTableData(new PrintWriter(System.out), new String[]{"col1", "col2"}, new String[][]{{"row1col1", "row1col2"}, {"row2col1", "row2col2"}}, true, "table-id");
writeTableData
Using AI Code Generation
1String html = new String(Files.readAllBytes(Paths.get("C:\\Users\\test\\Desktop\\testng-results.html")));2String[] arr = html.split("3");4String htmlData = "";5for(int i = 0; i < arr.length; i++) {6 String line = arr[i];7 if(line.contains("class=\"test\"")) {8 String[] lineArr = line.split("9");10 for(int j = 0; j < lineArr.length; j++) {11 String line1 = lineArr[j];12 if(line1.contains("class=\"test\"")) {13 String[] lineArr1 = line1.split("14");15 for(int k = 0; k < lineArr1.length; k++) {16 String line2 = lineArr1[k];17 if(line2.contains("class=\"test\"")) {18 String[] lineArr2 = line2.split("19");20 for(int l = 0; l < lineArr2.length; l++) {21 String line3 = lineArr2[l];22 if(line3.contains("class=\"test\"")) {23 String[] lineArr3 = line3.split("24");25 for(int m = 0; m < lineArr3.length; m++) {26 String line4 = lineArr3[m];27 if(line4.contains("class=\"test\"")) {28 String[] lineArr4 = line4.split("29");30 for(int n = 0; n < lineArr4.length; n++) {31 String line5 = lineArr4[n];32 if(line5.contains("class=\"test\"")) {33 String[] lineArr5 = line5.split("34");35 for(int o = 0; o < lineArr5.length; o++) {36 String line6 = lineArr5[o];37 if(line6.contains("class=\"test\"")) {38 String[] lineArr6 = line6.split("39");40 for(int p = 0; p < lineArr6.length; p++) {41 String line7 = lineArr6[p];42 if(line7.contains("class=\"test\"")) {43 String[] lineArr7 = line7.split("44");45 for(int q = 0; q < lineArr7.length; q++) {46 String line8 = lineArr7[q];47 if(line8.contains("class=\"test\"")) {
writeTableData
Using AI Code Generation
1import org.testng.reporters.EmailableReporter2;2EmailableReporter2.writeTableData(table, "data", "blue", false, false);3EmailableReporter2.writeTableData(table, "data", "blue", false, true);4EmailableReporter2.writeTableData(table, "data", "blue", true, false);5EmailableReporter2.writeTableData(table, "data", "blue", true, true);6EmailableReporter2.writeTableData(table, "data", "red", false, false);7EmailableReporter2.writeTableData(table, "data", "red", false, true);8EmailableReporter2.writeTableData(table, "data", "red", true, false);9EmailableReporter2.writeTableData(table, "data", "red", true, true);10EmailableReporter2.writeTableData(table, "data", "green", false, false);11EmailableReporter2.writeTableData(table, "data", "green", false, true);12EmailableReporter2.writeTableData(table, "data", "green", true, false);13EmailableReporter2.writeTableData(table, "data", "green", true, true);14EmailableReporter2.writeTableData(table, "data", "yellow", false, false);15EmailableReporter2.writeTableData(table, "data", "yellow", false, true);16EmailableReporter2.writeTableData(table, "data", "yellow", true
writeTableData
Using AI Code Generation
1public void writeTableData(String[] columns, List<ITestResult> tests, 2 String[] status, StringBuffer buffer) {3 buffer.append("4");5 for (int row = 0; row < tests.size(); row++) {6 ITestResult testResult = tests.get(row);7 buffer.append("8").append("9|");10 for (int col = 0; col < columns.length; col++) {11 String column = columns[col];12 if (column.equals("Test")) {13 String description = getTestDescription(testResult);14 buffer.append(description);15 } else if (column.equals("Description")) {16 String testInstanceName = testResult.getMethod().getDescription();17 buffer.append(testInstanceName);18 } else if (column.equals("Class")) {19 String className = testResult.getTestClass().getName();20 buffer.append(className);21 } else if (column.equals("Method")) {22 String methodName = testResult.getMethod().getMethodName();23 buffer.append(methodName);24 } else if (column.equals("Start")) {25 String startDate = getFormattedDate(testResult.getStartMillis());26 buffer.append(startDate);27 } else if (column.equals("End")) {28 String endDate = getFormattedDate(testResult.getEndMillis());29 buffer.append(endDate);30 } else if (column.equals("Status")) {31 String result = status[row];32 buffer.append(result);33 }34 buffer.append("|");35 }36 }37}38private void writeTableHeader(String[] columns, StringBuffer buffer) {39 buffer.append("40");41 for (int i = 0; i < columns.length; i++) {42 buffer.append("|").append(columns[i]);43 }44 buffer.append("|");45}46private void writeTableFooter(String[] columns, StringBuffer buffer) {47 buffer.append("48");49 for (int i = 0; i < columns.length; i++) {50 buffer.append("|---");51 }52 buffer.append("|");53}54private void writeTable(String[] columns, List<ITestResult> tests, String[] status, 55 StringBuffer buffer) {56 writeTableHeader(columns, buffer
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.
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.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!