/** * Writes the content of the sb string to the file named filename in outDir. If * outDir does not exist, it is created. * * @param outputDir the output directory (may not exist). If <tt>null</tt> then current directory is used. * @param fileName the filename * @param sb the file content */ public static void writeFile(@Nullable String outputDir, String fileName, String sb) { final String outDirPath= outputDir != null ? outputDir : ""; final File outDir= new File(outDirPath); writeFile(outDir, fileName, sb, null); }
/** * Writes the content of the sb string to the file named filename in outDir. If outDir does not * exist, it is created. * * @param outputDir the output directory (may not exist). If <tt>null</tt> then current directory * is used. * @param fileName the filename * @param sb the file content */ public static void writeFile(@Nullable String outputDir, String fileName, String sb) { final String outDirPath = outputDir != null ? outputDir : ""; final File outDir = new File(outDirPath); writeFile(outDir, fileName, sb, null); }
/** * Writes the content of the sb string to the file named filename in outDir encoding the output as UTF-8. * If outDir does not exist, it is created. * * @param outputDir the output directory (may not exist). If <tt>null</tt> then current directory is used. * @param fileName the filename * @param sb the file content */ public static void writeUtf8File(@Nullable String outputDir, String fileName, String sb) { final String outDirPath= outputDir != null ? outputDir : ""; final File outDir= new File(outDirPath); writeFile(outDir, fileName, escapeUnicode(sb), "UTF-8"); }
private void generateReporterOutput(XmlSuite xmlSuite) { StringBuilder sb = new StringBuilder(); // // Reporter output // sb.append("<h2>Reporter output</h2>") .append("<table>"); List<String> output = Reporter.getOutput(); for (String line : output) { sb.append("<tr><td>").append(line).append("</td></tr>\n"); } sb.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), REPORTER_OUTPUT, sb.toString()); }
private void generateClasses(XmlSuite xmlSuite) { StringBuilder sb = new StringBuilder(); sb.append("<table border='1'>\n") .append("<tr>\n") .append("<th>Class name</th>\n") .append("<th>Method name</th>\n") .append("<th>Groups</th>\n") .append("</tr>") ; for (ITestClass tc : m_classes.values()) { sb.append(generateClass(tc)); } sb.append("</table>\n"); Utils.writeFile(getOutputDirectory(xmlSuite), CLASSES, sb.toString()); }
private void generateMain(XmlSuite xmlSuite, ISuite sr) { String index = String.format("<html><head><title>Results for %s</title></head>%n", sr.getName()) + "<body>Select a result on the left-hand pane.</body>" + "</html>\n"; Utils.writeFile(getOutputDirectory(xmlSuite), "main.html", index); }
private void generateXmlFile(XmlSuite xmlSuite) { String content = xmlSuite.toXml().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>"); String sb = "<html><head><title>testng.xml for "+ xmlSuite.getName() + "</title></head><body><tt>" + content + "</tt></body></html>"; Utils.writeFile(getOutputDirectory(xmlSuite), TESTNG_XML, sb); }
private void generateIndex(XmlSuite xmlSuite, ISuite sr) { String index = String.format("<html><head><title>Results for %s</title></head>%n", sr.getName()) + "<frameset cols=\"26%,74%\">\n" + "<frame src=\"toc.html\" name=\"navFrame\">\n" + "<frame src=\"main.html\" name=\"mainFrame\">\n" + "</frameset>\n" + "</html>\n"; Utils.writeFile(getOutputDirectory(xmlSuite), "index.html", index); }
/** * Writes the content of the sb string to the file named filename in outDir encoding the output as * UTF-8. If outDir does not exist, it is created. * * @param outputDir the output directory (may not exist). If <tt>null</tt> then current directory * is used. * @param fileName the filename * @param sb the file content */ public static void writeUtf8File(@Nullable String outputDir, String fileName, String sb) { final String outDirPath = outputDir != null ? outputDir : ""; final File outDir = new File(outDirPath); writeFile(outDir, fileName, escapeUnicode(sb), "UTF-8"); }
private void generateClasses(XmlSuite xmlSuite) { StringBuilder sb = new StringBuilder(); sb.append("<table border='1'>\n") .append("<tr>\n") .append("<th>Class name</th>\n") .append("<th>Method name</th>\n") .append("<th>Groups</th>\n") .append("</tr>"); for (ITestClass tc : m_classes.values()) { sb.append(generateClass(tc)); } sb.append("</table>\n"); Utils.writeFile(getOutputDirectory(xmlSuite), CLASSES, sb.toString()); }
/** * Generate information about methods and groups */ private void generateMethodsAndGroups(XmlSuite xmlSuite, ISuite suite) { StringBuilder sb = new StringBuilder(); Map<String, Collection<ITestNGMethod>> groups = suite.getMethodsByGroups(); sb.append("<h2>Groups used for this test run</h2>"); if (groups.size() > 0) { sb.append("<table border=\"1\">\n") .append("<tr> <td align=\"center\"><b>Group name</b></td>") .append("<td align=\"center\"><b>Methods</b></td></tr>"); String[] groupNames = groups.keySet().toArray(new String[groups.size()]); Arrays.sort(groupNames); for (String group : groupNames) { Collection<ITestNGMethod> methods = groups.get(group); sb.append("<tr><td>").append(group).append(CLOSE_TD); StringBuilder methodNames = new StringBuilder(); Map<ITestNGMethod, ITestNGMethod> uniqueMethods = Maps.newHashMap(); for (ITestNGMethod tm : methods) { uniqueMethods.put(tm, tm); } for (ITestNGMethod tm : uniqueMethods.values()) { methodNames.append(tm.toString()).append("<br/>"); } sb.append("<td>").append(methodNames.toString()).append("</td></tr>\n"); } sb.append("</table>\n"); } Utils.writeFile(getOutputDirectory(xmlSuite), GROUPS, sb.toString()); }
private void generateReporterOutput(XmlSuite xmlSuite) { StringBuilder sb = new StringBuilder(); // // Reporter output // sb.append("<h2>Reporter output</h2>").append("<table>"); List<String> output = Reporter.getOutput(); for (String line : output) { sb.append("<tr><td>").append(line).append("</td></tr>\n"); } sb.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), REPORTER_OUTPUT, sb.toString()); }
private void generateExcludedMethodsReport(XmlSuite xmlSuite, ISuite suite) { Collection<ITestNGMethod> excluded = suite.getExcludedMethods(); StringBuilder sb2 = new StringBuilder("<h2>Methods that were not run</h2><table>\n"); for (ITestNGMethod method : excluded) { ConstructorOrMethod m = method.getConstructorOrMethod(); if (m != null) { sb2.append("<tr><td>") .append(m.getDeclaringClass().getName()).append(".").append(m.getName()); String description = method.getDescription(); if(isStringNotEmpty(description)) { sb2.append("<br/>").append(SP2).append("<i>").append(description).append("</i>"); } sb2.append("</td></tr>\n"); } } sb2.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), METHODS_NOT_RUN, sb2.toString()); }
private void generateIndex(XmlSuite xmlSuite, ISuite sr) { String index = String.format("<html><head><title>Results for %s</title></head>%n", sr.getName()) + "<frameset cols=\"26%,74%\">\n" + "<frame src=\"toc.html\" name=\"navFrame\">\n" + "<frame src=\"main.html\" name=\"mainFrame\">\n" + "</frameset>\n" + "</html>\n"; Utils.writeFile(getOutputDirectory(xmlSuite), "index.html", index); }
/** * Writes a property file for each suite result. * * @param xmlSuite - The {@link XmlSuite} suite. * @param suite - The {@link ISuite} object. */ private void generateSuites(XmlSuite xmlSuite, ISuite suite) { Map<String, ISuiteResult> suiteResults = suite.getResults(); for (ISuiteResult sr : suiteResults.values()) { ITestContext testContext = sr.getTestContext(); StringBuilder sb = new StringBuilder(); for (ISuiteResult suiteResult : suiteResults.values()) { sb.append(suiteResult.toString()); } Utils.writeFile(getOutputDirectory(xmlSuite), testContext.getName() + ".properties", sb.toString()); } } }
private void generateMain(XmlSuite xmlSuite, ISuite sr) { String index = String.format("<html><head><title>Results for %s</title></head>%n", sr.getName()) + "<body>Select a result on the left-hand pane.</body>" + "</html>\n"; Utils.writeFile(getOutputDirectory(xmlSuite), "main.html", index); }
log(FORMAT, 3, " Directory " + outDir + " exists: " + outDir.exists()); outputFile.createNewFile(); writeFile(outputFile, sb, encoding);
private void generateXmlFile(XmlSuite xmlSuite) { String content = xmlSuite .toXml() .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll(" ", " ") .replaceAll("\n", "<br/>"); String sb = "<html><head><title>testng.xml for " + xmlSuite.getName() + "</title></head><body><tt>" + content + "</tt></body></html>"; Utils.writeFile(getOutputDirectory(xmlSuite), TESTNG_XML, sb); }
private void generateExcludedMethodsReport(XmlSuite xmlSuite, ISuite suite) { Collection<ITestNGMethod> excluded = suite.getExcludedMethods(); StringBuilder sb2 = new StringBuilder("<h2>Methods that were not run</h2><table>\n"); for (ITestNGMethod method : excluded) { ConstructorOrMethod m = method.getConstructorOrMethod(); if (m != null) { sb2.append("<tr><td>") .append(m.getDeclaringClass().getName()) .append(".") .append(m.getName()); String description = method.getDescription(); if (isStringNotEmpty(description)) { sb2.append("<br/>").append(SP2).append("<i>").append(description).append("</i>"); } sb2.append("</td></tr>\n"); } } sb2.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), METHODS_NOT_RUN, sb2.toString()); }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { m_outputDirectory = outputDirectory; XMLStringBuffer xsb = new XMLStringBuffer(" "); xsb.push(D, "id", "suites"); generateSuites(xmlSuites, suites, xsb); xsb.pop(D); String all; try { all = Files.readFile(new File(m_outputDirectory + "/head")); Utils.writeFile(m_outputDirectory, "index2.html", all + xsb.toXML()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }