private void generateForResult(ITestResult ans, ITestNGMethod method, int resultSetSize) { Object[] parameters = ans.getParameters(); boolean hasParameters = parameters != null && parameters.length > 0; if (hasParameters) { tableStart("result", null); m_out.print("<tr class=\"param\">"); for (int x = 1; x <= parameters.length; x++) { m_out.print("<th>Parameter #" + x + "</th>"); } m_out.println("</tr>"); m_out.print("<tr class=\"param stripe\">"); for (Object p : parameters) { m_out.println("<td>" + Utils.escapeHtml(p.toString()) + "</td>"); } m_out.println("</tr>"); } List<String> msgs = Reporter.getOutput(ans); boolean hasReporterOutput = msgs.size() > 0; Throwable exception = ans.getThrowable(); boolean hasThrowable = exception != null; if (hasReporterOutput || hasThrowable) { if (hasParameters) { m_out.print("<tr><td"); if (parameters.length > 1) { m_out.print(" colspan=\"" + parameters.length + "\""); } m_out.println(">"); } else { m_out.println("<div>"); } if (hasReporterOutput) { if (hasThrowable) { m_out.println("<h3>Test Messages</h3>"); } for (String line : msgs) { m_out.println(line + "<br/>"); } } if (hasThrowable) { boolean wantsMinimalOutput = ans.getStatus() == ITestResult.SUCCESS; if (hasReporterOutput) { m_out.println("<h3>" + (wantsMinimalOutput ? "Expected Exception" : "Failure") + "</h3>"); } generateExceptionReport(exception, method); } if (hasParameters) { m_out.println("</td></tr>"); } else { m_out.println("</div>"); } } if (hasParameters) { m_out.println("</table>"); } }
private void write2LogFile(ITestResult iTestResult, File testFolder) { BufferedWriter out = null; try { if (testFolder == null) { LogUtils.log("Can not write to file test folder is null"); return; } String output = SGTestNGReporter.getOutput(); if (StringUtils.isEmpty(output)) { LogUtils.log("nothing to write to log file"); return; } String parameters = TestNGUtils.extractParameters(iTestResult); File testLogFile = new File( testFolder.getAbsolutePath() + "/" + iTestResult.getName() + "(" + parameters + ").log"); if (!testLogFile.createNewFile()) { LogUtils.log( "Failed to create log file [" + testLogFile + "];\n log output: " + Reporter.getOutput()); return; } FileWriter fstream = new FileWriter(testLogFile); out = new BufferedWriter(fstream); out.write(output); } catch (Exception e) { LogUtils.log("Failed to write to log file result - " + iTestResult, e); } finally { SGTestNGReporter.reset(); if (out != null) { try { out.close(); } catch (IOException e) { LogUtils.log("Failed closing stream", e); // ignore } } } }