How to use writeScenarioDetails method of org.testng.reporters.EmailableReporter2 class

Best Testng code snippet using org.testng.reporters.EmailableReporter2.writeScenarioDetails

Source:CustomReport.java Github

copy

Full Screen

...113// writeReportTitle(System.getProperty("brand") + " | " + System.getProperty("device") + " | " +System.getProperty("os_version") + " | " +System.getProperty("environment"));114// }115// writeSuiteSummary();116// writeScenarioSummary();117// writeScenarioDetails();118// writer.print("</body>");119// }120//121// protected void writeReportTitle(String title) {122// writer.print("<center><h1>" + title + " - " + getDateAsString() + "</h1></center>");123// }124//125// protected void writeDocumentEnd() {126// writer.print("</html>");127// }128//129// protected void writeSuiteSummary() {130//131// int totalPassedTests = 0;132// int totalSkippedTests = 0;133// int totalFailedTests = 0;134// long totalDuration = 0;135//136// writer.print("<center>");137// writer.print("<table>");138// writer.print("<tr>");139// writer.print("<th>Test</th>");140// writer.print("<th># Passed</th>");141//// writer.print("<th># Skipped</th>");142// writer.print("<th># Failed</th>");143//// writer.print("<th>Seconds</th>");144//// writer.print("<th>Included Groups</th>");145//// writer.print("<th>Excluded Groups</th>");146// writer.print("</tr>");147//148// int testIndex = 0;149// for (SuiteResult suiteResult : suiteResults) {150// writer.print("<tr><th colspan=\"7\">");151// writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));152// writer.print("</th></tr>");153//154// for (TestResult testResult : suiteResult.getTestResults()) {155// int passedTests = testResult.getPassedTestCount();156// int skippedTests = testResult.getSkippedTestCount();157// int failedTests = testResult.getFailedTestCount();158//// long duration = testResult.getDuration();159//160// writer.print("<tr");161// if ((testIndex % 2) == 1) {162// writer.print(" class=\"stripe\"");163// }164// writer.print(">");165//166// buffer.setLength(0);167// writeTableData(buffer.append("<a href=\"#t").append(testIndex).append("\">")168// .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());169// writeTableData(integerFormat.format(passedTests), "num");170//// writeTableData(integerFormat.format(skippedTests), (skippedTests > 0 ? "num attn" : "num"));171// writeTableData(integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num"));172//// writeTableData(decimalFormat.format(millisecondsToSeconds(duration)), "num");173//// writeTableData(testResult.getIncludedGroups());174//// writeTableData(testResult.getExcludedGroups());175//176// writer.print("</tr>");177//178// totalPassedTests += passedTests;179// totalSkippedTests += skippedTests;180// totalFailedTests += failedTests;181//// totalDuration += duration;182//183// testIndex++;184// }185// }186//187// // Print totals if there was more than one test188// if (testIndex >= 1) {189// writer.print("<tr>");190// writer.print("<th>Total</th>");191// writeTableHeader(integerFormat.format(totalPassedTests), "num");192//// writeTableHeader(integerFormat.format(totalSkippedTests), (totalSkippedTests > 0 ? "num attn" : "num"));193// writeTableHeader(integerFormat.format(totalFailedTests), (totalFailedTests > 0 ? "num attn" : "num"));194//// writeTableHeader(decimalFormat.format(millisecondsToSeconds(totalDuration)), "num");195//// writer.print("<th colspan=\"2\"></th>");196// writer.print("</tr>");197// }198//199// writer.print("</table>");200// writer.print("</center>");201// }202//203// /**204// * Writes a summary of all the test scenarios.205// */206// protected void writeScenarioSummary() {207// writer.print("<center>");208// writer.print("<table>");209// writer.print("<thead>");210// writer.print("<tr>");211// writer.print("<th>Test Name</th>");212// writer.print("<th>Status</th>");213// writer.print("<th>Start</th>");214//// writer.print("<th>Seconds</th>");215// writer.print("</tr>");216// writer.print("</thead>");217//218// int testIndex = 0;219// int scenarioIndex = 0;220// for (SuiteResult suiteResult : suiteResults) {221// writer.print("<tbody><tr><th colspan=\"5\">");222// writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));223// writer.print("</th></tr></tbody>");224//225// for (TestResult testResult : suiteResult.getTestResults()) {226// writer.print("<tbody id=\"t");227// writer.print(testIndex);228// writer.print("\">");229//230// String testName = Utils.escapeHtml(testResult.getTestName());231//232// scenarioIndex += writeScenarioSummary(testName233// + " &#8212; failed (configuration methods)",234// testResult.getFailedConfigurationResults(), "failed",235// scenarioIndex236// );237// scenarioIndex += writeScenarioSummary(testName238// + " &#8212; failed", testResult.getFailedTestResults(),239// "failed", scenarioIndex240// );241// scenarioIndex += writeScenarioSummary(testName242// + " &#8212; skipped (configuration methods)",243// testResult.getSkippedConfigurationResults(), "skipped",244// scenarioIndex245// );246//// scenarioIndex += writeScenarioSummary(testName247//// + " &#8212; skipped",248//// testResult.getSkippedTestResults(), "skipped",249//// scenarioIndex250//// );251// scenarioIndex += writeScenarioSummary(testName252// + " &#8212; passed", testResult.getPassedTestResults(),253// "passed", scenarioIndex254// );255//256// writer.print("</tbody>");257//258// testIndex++;259// }260// }261//262// writer.print("</table>");263// writer.print("</center>");264// }265//266// /**267// * Writes the scenario summary for the results of a given state for a single268// * test.269// */270// private int writeScenarioSummary(String description, List<ClassResult> classResults,271// String cssClassPrefix, int startingScenarioIndex) {272// int scenarioCount = 0;273// if (!classResults.isEmpty()) {274// writer.print("<tr><th colspan=\"5\">"); //All Tests - Passed275// writer.print(description);276// writer.print("</th></tr>");277//278// int scenarioIndex = startingScenarioIndex;279// int classIndex = 0;280// for (ClassResult classResult : classResults) {281// String cssClass = cssClassPrefix + ((classIndex % 2) == 0 ? "even" : "odd");282//283// buffer.setLength(0);284//285// int scenariosPerClass = 0;286// int methodIndex = 0;287// for (MethodResult methodResult : classResult.getMethodResults()) {288// List<ITestResult> results = methodResult.getResults();289// int resultsCount = results.size();290// assert resultsCount > 0;291//292// aResult = results.iterator().next();293// String methodName = Utils.escapeHtml(aResult.getMethod().getMethodName());294// long start = aResult.getStartMillis();295// long duration = aResult.getEndMillis() - start;296//297// // The first method per class shares a row with the class298// // header299// if (methodIndex > 0) {300// buffer.append("<tr class=\"").append(cssClass)301// .append("\">");302//303// }304//305//306// String testStatus = String.valueOf(aResult.isSuccess());307// if (testStatus.equals("true")) {308// testStatus = "Passed";309// } else if (testStatus.equals("false")) {310// testStatus = "Failed";311// } else {312// testStatus = "Skipped";313// }314//315// // Write the timing information with the first scenario per method - Method name with a link316// buffer.append("<td><a href=\"#m").append(scenarioIndex)317// .append("\">").append(methodName + "</a></td>")318// .append("<td rowspan=\"1\">" + testStatus + "</td>") //Description319// .append("<td rowspan=\"")320// .append(resultsCount).append("\">").append(parseUnixTimeToTimeOfDay(start)) //Start321// .append("</td>").append("<td rowspan=\"")322// .append(resultsCount).append("\">")323//// .append(decimalFormat.format(millisecondsToSeconds(duration)))324// .append("</td></tr>"); //Seconds325// scenarioIndex++;326//327// // Write the remaining scenarios for the method328// for (int i = 1; i < resultsCount; i++) {329// buffer.append("<tr class=\"").append(cssClass)330// .append("\">").append("<td><a href=\"#m") //Method name331// .append(scenarioIndex).append("\">")332// .append(methodName + "</a></td>")333// .append("<td rowspan=\"1\">" + aResult.getName() + "</td></tr>");334// scenarioIndex++;335// }336//337// scenariosPerClass += resultsCount;338// methodIndex++;339// }340//341//342// // Write the test results for the class343// writer.print("<tr class=\"");344// writer.print(cssClass);345// writer.print("\">");346//// writer.print("<td rowspan=\""); //class name - no need347//// writer.print(scenariosPerClass);348//// writer.print("\">");349//// writer.print(Utils.escapeHtml(classResult.getClassName()));350//// writer.print("</td>");351// writer.print(buffer);352//353// classIndex++;354// }355// scenarioCount = scenarioIndex - startingScenarioIndex;356// }357// return scenarioCount;358// }359//360// /**361// * Writes the details for all test scenarios.362// */363// protected void writeScenarioDetails() {364// int scenarioIndex = 0;365// for (SuiteResult suiteResult : suiteResults) {366// for (TestResult testResult : suiteResult.getTestResults()) {367// writer.print("<h2>");368// writer.print(Utils.escapeHtml(testResult.getTestName()));369// writer.print("</h2>");370//371// scenarioIndex += writeScenarioDetails(372// testResult.getFailedConfigurationResults(), scenarioIndex);373// scenarioIndex += writeScenarioDetails(374// testResult.getFailedTestResults(), scenarioIndex);375// scenarioIndex += writeScenarioDetails(376// testResult.getSkippedConfigurationResults(), scenarioIndex);377// scenarioIndex += writeScenarioDetails(378// testResult.getSkippedTestResults(), scenarioIndex);379// scenarioIndex += writeScenarioDetails(380// testResult.getPassedTestResults(), scenarioIndex);381// }382// }383// }384//385// /**386// * Writes the scenario details for the results of a given state for a single387// * test.388// */389// private int writeScenarioDetails(List<ClassResult> classResults, int startingScenarioIndex) {390// int scenarioIndex = startingScenarioIndex;391// for (ClassResult classResult : classResults) {392// String className = classResult.getClassName();393// for (MethodResult methodResult : classResult.getMethodResults()) {394// List<ITestResult> results = methodResult.getResults();395// assert !results.isEmpty();396//397// ITestResult mResult = results.iterator().next();398// String label = Utils.escapeHtml(className + "#"399// + mResult.getMethod().getMethodName() + " ( " + mResult.getName() + " )");400// for (ITestResult result : results) {401// writeScenario(scenarioIndex, label, result);402// scenarioIndex++;403// } ...

Full Screen

Full Screen

Source:CustomEmailableReporter.java Github

copy

Full Screen

...107 protected void writeBody() {108 writer.print("<body>");109 writeSuiteSummary();110 writeScenarioSummary();111 writeScenarioDetails();112 writer.print("</body>");113 }114 @Override115 protected void writeDocumentEnd() {116 writer.print("</html>");117 }118 @Override119 protected void writeSuiteSummary() {120 NumberFormat integerFormat = NumberFormat.getIntegerInstance();121 NumberFormat decimalFormat = NumberFormat.getNumberInstance();122 int totalPassedTests = 0;123 int totalSkippedTests = 0;124 int totalFailedTests = 0;125 long totalDuration = 0;126 writer.print("<h1>Test Summary</h1>");127 writer.print("<table>");128 writer.print("<tr>");129 writer.print("<th>Test</th>");130 writer.print("<th># Passed</th>");131 writer.print("<th># Skipped</th>");132 writer.print("<th># Failed</th>");133 writer.print("<th>Time (ms)</th>");134 writer.print("<th>Included Groups</th>");135 writer.print("<th>Excluded Groups</th>");136 writer.print("</tr>");137 int testIndex = 0;138 for (SuiteResult suiteResult : suiteResults) {139 writer.print("<tr><th colspan=\"7\">");140 writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));141 writer.print("</th></tr>");142 for (TestResult testResult : suiteResult.getTestResults()) {143 int passedTests = testResult.getPassedTestCount();144 int skippedTests = testResult.getSkippedTestCount();145 int failedTests = testResult.getFailedTestCount();146 long duration = testResult.getDuration();147 writer.print("<tr");148 if ((testIndex % 2) == 1) {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 + " &#8212; failed (configuration methods)",218 testResult.getFailedConfigurationResults(), "failed",219 scenarioIndex);220 scenarioIndex += writeScenarioSummary(testName221 + " &#8212; failed", testResult.getFailedTestResults(),222 "failed", scenarioIndex);223 scenarioIndex += writeScenarioSummary(testName224 + " &#8212; skipped (configuration methods)",225 testResult.getSkippedConfigurationResults(), "skipped",226 scenarioIndex);227 scenarioIndex += writeScenarioSummary(testName228 + " &#8212; skipped",229 testResult.getSkippedTestResults(), "skipped",230 scenarioIndex);231 scenarioIndex += writeScenarioSummary(testName232 + " &#8212; 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())...

Full Screen

Full Screen

Source:CustomReporter.java Github

copy

Full Screen

...91 writer.print("<body>");92 writeReportTitle( "TestNG Report" );93 writeSuiteSummary();94 writeScenarioSummary();95 writeScenarioDetails();96 writer.print("</body>");97 }98 protected void writeReportTitle( String title ) {99 writer.print( "<center><h1>" + title + " - " + getDateAsString() + "</h1></center>" );100 }101 protected void writeDocumentEnd() {102 writer.print("</html>");103 }104 protected void writeSuiteSummary() {105 int totalPassedTests = 0;106 int totalSkippedTests = 0;107 int totalFailedTests = 0;108 long totalDuration = 0;109 writer.print("<table>");110 writer.print("<tr>");111 writer.print("<th>Test</th>");112 writer.print("<th># Passed</th>");113 writer.print("<th># Skipped</th>");114 writer.print("<th># Failed</th>");115 writer.print("<th>Seconds</th>");116 writer.print("<th>Included Groups</th>");117 writer.print("<th>Excluded Groups</th>");118 writer.print("</tr>");119 int testIndex = 0;120 for ( SuiteResult suiteResult : suiteResults ) {121 writer.print("<tr><th colspan=\"7\">");122 writer.print( Utils.escapeHtml( suiteResult.getSuiteName() ) );123 writer.print("</th></tr>");124 for ( TestResult testResult : suiteResult.getTestResults() ) {125 int passedTests = testResult.getPassedTestCount();126 int skippedTests = testResult.getSkippedTestCount();127 int failedTests = testResult.getFailedTestCount();128 long duration = testResult.getDuration();129 writer.print("<tr");130 if ((testIndex % 2) == 1) {131 writer.print(" class=\"stripe\"");132 }133 writer.print(">");134 buffer.setLength(0);135 writeTableData( buffer.append("<a href=\"#t").append(testIndex).append("\">")136 .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());137 writeTableData( integerFormat.format(passedTests), "num");138 writeTableData( integerFormat.format(skippedTests), (skippedTests > 0 ? "num attn" : "num"));139 writeTableData( integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num"));140 writeTableData( decimalFormat.format(millisecondsToSeconds(duration)), "num");141 writeTableData( testResult.getIncludedGroups() );142 writeTableData( testResult.getExcludedGroups() );143 writer.print("</tr>");144 totalPassedTests += passedTests;145 totalSkippedTests += skippedTests;146 totalFailedTests += failedTests;147 totalDuration += duration;148 testIndex++;149 }150 }151 // Print totals if there was more than one test152 if ( testIndex >= 1 ) {153 writer.print("<tr>");154 writer.print("<th>Total</th>");155 writeTableHeader( integerFormat.format(totalPassedTests), "num");156 writeTableHeader( integerFormat.format(totalSkippedTests), (totalSkippedTests > 0 ? "num attn" : "num"));157 writeTableHeader( integerFormat.format(totalFailedTests), (totalFailedTests > 0 ? "num attn" : "num"));158 writeTableHeader( decimalFormat.format(millisecondsToSeconds(totalDuration)), "num");159 writer.print("<th colspan=\"2\"></th>");160 writer.print("</tr>");161 }162 writer.print("</table>");163 }164 /**165 * Writes a summary of all the test scenarios.166 */167 protected void writeScenarioSummary() {168 writer.print("<table>");169 writer.print("<thead>");170 writer.print("<tr>");171 writer.print("<th>Class</th>");172 writer.print("<th>Method</th>");173 writer.print("<th>Name</th>");174 writer.print("<th>Start</th>");175 writer.print("<th>Seconds</th>");176 writer.print("</tr>");177 writer.print("</thead>");178 int testIndex = 0;179 int scenarioIndex = 0;180 for ( SuiteResult suiteResult : suiteResults ) {181 writer.print("<tbody><tr><th colspan=\"5\">");182 writer.print( Utils.escapeHtml( suiteResult.getSuiteName() ) );183 writer.print("</th></tr></tbody>");184 for ( TestResult testResult : suiteResult.getTestResults() ) {185 writer.print("<tbody id=\"t");186 writer.print(testIndex);187 writer.print("\">");188 String testName = Utils.escapeHtml( testResult.getTestName() );189 scenarioIndex += writeScenarioSummary(testName190 + " &#8212; failed (configuration methods)",191 testResult.getFailedConfigurationResults(), "failed",192 scenarioIndex193 );194 scenarioIndex += writeScenarioSummary(testName195 + " &#8212; failed", testResult.getFailedTestResults(),196 "failed", scenarioIndex197 );198 scenarioIndex += writeScenarioSummary(testName199 + " &#8212; skipped (configuration methods)",200 testResult.getSkippedConfigurationResults(), "skipped",201 scenarioIndex202 );203 scenarioIndex += writeScenarioSummary(testName204 + " &#8212; skipped",205 testResult.getSkippedTestResults(), "skipped",206 scenarioIndex207 );208 scenarioIndex += writeScenarioSummary(testName209 + " &#8212; passed", testResult.getPassedTestResults(),210 "passed", scenarioIndex211 );212 writer.print("</tbody>");213 testIndex++;214 }215 }216 writer.print("</table>");217 }218 /**219 * Writes the scenario summary for the results of a given state for a single220 * test.221 */222 private int writeScenarioSummary( String description, List<ClassResult> classResults,223 String cssClassPrefix, int startingScenarioIndex ) {224 int scenarioCount = 0;225 if (!classResults.isEmpty()) {226 writer.print("<tr><th colspan=\"5\">");227 writer.print(description);228 writer.print("</th></tr>");229 int scenarioIndex = startingScenarioIndex;230 int classIndex = 0;231 for ( ClassResult classResult : classResults ) {232 String cssClass = cssClassPrefix + ((classIndex % 2) == 0 ? "even" : "odd");233 buffer.setLength(0);234 int scenariosPerClass = 0;235 int methodIndex = 0;236 for ( MethodResult methodResult : classResult.getMethodResults() ) {237 List<ITestResult> results = methodResult.getResults();238 int resultsCount = results.size();239 assert resultsCount > 0;240 ITestResult aResult = results.iterator().next();241 String methodName = Utils.escapeHtml(aResult.getMethod().getMethodName());242 long start = aResult.getStartMillis();243 long duration = aResult.getEndMillis() - start;244 // The first method per class shares a row with the class245 // header246 if (methodIndex > 0) {247 buffer.append("<tr class=\"").append(cssClass)248 .append("\">");249 }250 // Write the timing information with the first scenario per method251 buffer.append("<td><a href=\"#m").append(scenarioIndex)252 .append("\">").append( methodName + "</a></td>" )253 .append( "<td rowspan=\"1\">" + aResult.getName() + "</td>" )254 .append( "<td rowspan=\"")255 .append(resultsCount).append("\">").append( parseUnixTimeToTimeOfDay(start) )256 .append( "</td>").append("<td rowspan=\"" )257 .append(resultsCount).append("\">")258 .append( decimalFormat.format( millisecondsToSeconds( duration ) ) ).append("</td></tr>");259 scenarioIndex++;260 // Write the remaining scenarios for the method261 for ( int i = 1; i < resultsCount; i++ ) {262 buffer.append("<tr class=\"").append(cssClass)263 .append("\">").append("<td><a href=\"#m")264 .append(scenarioIndex).append("\">")265 .append( methodName + "</a></td>" )266 .append("<td rowspan=\"1\">" + aResult.getName() + "</td></tr>" );267 scenarioIndex++;268 }269 scenariosPerClass += resultsCount;270 methodIndex++;271 }272 // Write the test results for the class273 writer.print("<tr class=\"");274 writer.print(cssClass);275 writer.print("\">");276 writer.print("<td rowspan=\"");277 writer.print(scenariosPerClass);278 writer.print("\">");279 writer.print(Utils.escapeHtml(classResult.getClassName()));280 writer.print("</td>");281 writer.print(buffer);282 classIndex++;283 }284 scenarioCount = scenarioIndex - startingScenarioIndex;285 }286 return scenarioCount;287 }288 /**289 * Writes the details for all test scenarios.290 */291 protected void writeScenarioDetails() {292 int scenarioIndex = 0;293 for ( SuiteResult suiteResult : suiteResults ) {294 for ( TestResult testResult : suiteResult.getTestResults() ) {295 writer.print("<h2>");296 writer.print( Utils.escapeHtml( testResult.getTestName() ) );297 writer.print("</h2>");298 scenarioIndex += writeScenarioDetails(299 testResult.getFailedConfigurationResults(), scenarioIndex);300 scenarioIndex += writeScenarioDetails(301 testResult.getFailedTestResults(), scenarioIndex);302 scenarioIndex += writeScenarioDetails(303 testResult.getSkippedConfigurationResults(), scenarioIndex);304 scenarioIndex += writeScenarioDetails(305 testResult.getSkippedTestResults(), scenarioIndex);306 scenarioIndex += writeScenarioDetails(307 testResult.getPassedTestResults(), scenarioIndex);308 }309 }310 }311 /**312 * Writes the scenario details for the results of a given state for a single313 * test.314 */315 private int writeScenarioDetails( List<ClassResult> classResults, int startingScenarioIndex ) {316 int scenarioIndex = startingScenarioIndex;317 for ( ClassResult classResult : classResults ) {318 String className = classResult.getClassName();319 for ( MethodResult methodResult : classResult.getMethodResults() ) {320 List<ITestResult> results = methodResult.getResults();321 assert !results.isEmpty();322 ITestResult mResult = results.iterator().next();323 String label = Utils.escapeHtml( className + "#"324 + mResult.getMethod().getMethodName() + " ( " + mResult.getName() +" )" );325 for ( ITestResult result : results ) {326 writeScenario( scenarioIndex, label, result );327 scenarioIndex++;328 }329 }...

Full Screen

Full Screen

Source:EmailableReporter2.java Github

copy

Full Screen

...98 protected void writeBody() {99 writer.println("<body>");100 writeSuiteSummary();101 writeScenarioSummary();102 writeScenarioDetails();103 writer.println("</body>");104 }105 protected void writeDocumentEnd() {106 writer.println("</html>");107 }108 protected void writeSuiteSummary() {109 NumberFormat integerFormat = NumberFormat.getIntegerInstance();110 NumberFormat decimalFormat = NumberFormat.getNumberInstance();111 int totalPassedTests = 0;112 int totalSkippedTests = 0;113 int totalFailedTests = 0;114 long totalDuration = 0;115 writer.println("<table>");116 writer.print("<tr>");117 writer.print("<th>Test</th>");118 writer.print("<th># Passed</th>");119 writer.print("<th># Skipped</th>");120 writer.print("<th># Failed</th>");121 writer.print("<th>Time (ms)</th>");122 writer.print("<th>Included Groups</th>");123 writer.print("<th>Excluded Groups</th>");124 writer.println("</tr>");125 int testIndex = 0;126 for (SuiteResult suiteResult : suiteResults) {127 writer.print("<tr><th colspan=\"7\">");128 writer.print(Utils.escapeHtml(suiteResult.getSuiteName()));129 writer.println("</th></tr>");130 for (TestResult testResult : suiteResult.getTestResults()) {131 int passedTests = testResult.getPassedTestCount();132 int skippedTests = testResult.getSkippedTestCount();133 int failedTests = testResult.getFailedTestCount();134 long duration = testResult.getDuration();135 writer.print("<tr");136 if ((testIndex % 2) == 1) {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 + " &#8212; failed (configuration methods)",201 testResult.getFailedConfigurationResults(), "failed",202 scenarioIndex);203 scenarioIndex += writeScenarioSummary(testName204 + " &#8212; failed", testResult.getFailedTestResults(),205 "failed", scenarioIndex);206 scenarioIndex += writeScenarioSummary(testName207 + " &#8212; skipped (configuration methods)",208 testResult.getSkippedConfigurationResults(), "skipped",209 scenarioIndex);210 scenarioIndex += writeScenarioSummary(testName211 + " &#8212; skipped",212 testResult.getSkippedTestResults(), "skipped",213 scenarioIndex);214 scenarioIndex += writeScenarioSummary(testName215 + " &#8212; 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);...

Full Screen

Full Screen

Source:ReportOverview.java Github

copy

Full Screen

...128 protected void writeBody() {129 writer.println(" <body>");130 writer.println(" <h1 style='text-align:center;'>Selenified Test Results</h1>");131 writeSuiteSummary();132 writeScenarioDetails();133 writer.println(" </body>");134 }135 /**136 * Generates the high level summary of the test report137 */138 @Override139 protected void writeSuiteSummary() {140 int totalPassedTests = 0;141 int totalSkippedTests = 0;142 int totalFailedTests = 0;143 for (SuiteResult suiteResult : suiteResults) {144 for (TestResult testResult : suiteResult.getTestResults()) {145 totalPassedTests += testResult.getPassedTestCount();146 totalSkippedTests += testResult.getSkippedTestCount();147 totalFailedTests += testResult.getFailedTestCount();148 }149 }150 String overallCssClass = SUCCESS;151 if (totalSkippedTests > 0) {152 overallCssClass = WARNING;153 }154 if (totalFailedTests > 0) {155 overallCssClass = DANGER;156 }157 writer.println(" <div class='container' style='font-size:large;'>");158 writer.println(" <table class='table table-bordered' style='width:100%;text-align:center;'>");159 writer.println(" <thead>");160 writer.print(" <tr class='" + overallCssClass + "'>");161 headerCell("Tests");162 headerCell("Passed");163 headerCell("Skipped");164 headerCell("Failed");165 writer.println(TR);166 writer.println(" </thead>");167 writer.println(" <tbody>");168 writer.print(" <tr class='" + overallCssClass + "'>");169 cell(integerFormat.format((long) totalPassedTests + totalSkippedTests + totalFailedTests));170 cell(integerFormat.format(totalPassedTests));171 cell(integerFormat.format(totalSkippedTests));172 cell(integerFormat.format(totalFailedTests));173 writer.println(TR);174 writer.println(" </tbody>");175 writer.println(" </table>");176 writer.println(" </div>");177 }178 /**179 * Creates a table with each test case run and it's details180 */181 @Override182 protected void writeScenarioDetails() {183 writer.println(" <div class='container'>");184 writer.println(" <table class='table sort'>");185 writer.println(" <thead>");186 writer.print(" <tr>");187 headerCell("Browser");188 headerCell("Test Suite");189 headerCell("Test Case");190 headerCell("Status");191 headerCell("Report");192 writer.println(TR);193 writer.println(" </thead>");194 writer.println(" <tbody>");195 for (SuiteResult suiteResult : suiteResults) {196 for (TestResult testResult : suiteResult.getTestResults()) {...

Full Screen

Full Screen

writeScenarioDetails

Using AI Code Generation

copy

Full Screen

1package com.howtodoinjava.demo.testng;2import org.testng.annotations.Test;3{4 public void testMethodOne()5 {6 System.out.println("TestNGEmailableReporterTest -> testMethodOne");7 }8 public void testMethodTwo()9 {10 System.out.println("TestNGEmailableReporterTest -> testMethodTwo");11 }12}13package com.howtodoinjava.demo.testng;14import org.testng.annotations.Test;15{16 public void testMethodOne()17 {18 System.out.println("TestNGEmailableReporterTest2 -> testMethodOne");19 }20 public void testMethodTwo()21 {22 System.out.println("TestNGEmailableReporterTest2 -> testMethodTwo");23 }24}25package com.howtodoinjava.demo.testng;26import org.testng.annotations.Test;27{28 public void testMethodOne()29 {30 System.out.println("TestNGEmailableReporterTest3 -> testMethodOne");31 }32 public void testMethodTwo()33 {34 System.out.println("TestNGEmailableReporterTest3 -> testMethodTwo");35 }36}37package com.howtodoinjava.demo.testng;38import org.testng.annotations.Test;39{40 public void testMethodOne()41 {42 System.out.println("TestNGEmailableReporterTest4 -> testMethodOne");43 }44 public void testMethodTwo()45 {46 System.out.println("TestNGEmailableReporterTest4 -> testMethodTwo");47 }48}49package com.howtodoinjava.demo.testng;50import org.testng.annotations.Test;51{52 public void testMethodOne()53 {54 System.out.println("TestNGEmailableReporterTest5 -> testMethodOne");55 }56 public void testMethodTwo()57 {58 System.out.println("TestNGEmailableReporterTest5 -> testMethodTwo");59 }60}61package com.howtodoinjava.demo.testng;62import org.testng.annotations.Test;63{

Full Screen

Full Screen

writeScenarioDetails

Using AI Code Generation

copy

Full Screen

1 String scenarioDetails = "## " + scenario.getName() + "2 scenarioDetails += "### " + scenario.getUri() + "3 scenarioDetails += "### " + scenario.getLine() + "4 scenarioDetails += "|Status|" + scenario.getStatus() + "5 scenarioDetails += "|Tags|" + scenario.getTags() + "6 scenarioDetails += "|Steps|" + scenario.getSteps() + "7 scenarioDetails += "|Steps Count|" + scenario.getSteps().size() + "8 scenarioDetails += "|Duration|" + scenario.getDuration() + "9 scenarioDetails += "|Keyword|" + scenario.getKeyword() + "10 scenarioDetails += "|Line|" + scenario.getLine() + "11 scenarioDetails += "|Id|" + scenario.getId() + "12 scenarioDetails += "|Type|" + scenario.getType() + "13 scenarioDetails += "|Description|" + scenario.getDescription() + "14 scenarioDetails += "|Comments|" + scenario.getComments() + "15 scenarioDetails += "|Before|" + scenario.getBefore() + "16 scenarioDetails += "|After|" + scenario.getAfter() + "17 writeScenarioDetails(scenarioDetails)18 String stepDetails = "## " + scenario.getName() + "19 stepDetails += "### " + scenario.getUri() + "20 stepDetails += "### " + scenario.getLine() + "21 scenario.getSteps().each { step ->22 stepDetails += "|${step.getName()}|${step.getStatus()}|${step.getDuration()}|${step.getKeyword()}|${step.getLine()}|${step.getMatch().getLocation()}

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