
com.github.mkolisnyk.cucumber.reporting.CucumberFeatureMapReport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-reports Show documentation
Show all versions of cucumber-reports Show documentation
Library generating different Cucumber reports
package com.github.mkolisnyk.cucumber.reporting;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.codehaus.plexus.util.StringUtils;
import org.testng.Assert;
import com.github.mkolisnyk.cucumber.reporting.types.breakdown.BreakdownReportInfo;
import com.github.mkolisnyk.cucumber.reporting.types.breakdown.BreakdownTable;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberFeatureResult;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberScenarioResult;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberStepResult;
public class CucumberFeatureMapReport extends CucumberBreakdownReport {
private String drawScenario(CucumberScenarioResult scenario) {
String output = String.format("%s ", scenario.getDescription());
for (CucumberStepResult step : scenario.getSteps()) {
output = output.concat(String.format("%s %s ",
step.getKeyword(),
step.getName()));
if (StringUtils.isNotBlank(step.getDocString())) {
output = output.concat(String.format("%s ",
step.getDocString()));
}
if (step.getRows() != null) {
output += String.format(
Locale.US,
"",
step.getResult().getStatus());
for (int i = 0; i < step.getRows().length; i++) {
output += "";
for (int j = 0; j < step.getRows()[i].length; j++) {
output += String.format(Locale.US,
"%s ", StringEscapeUtils.escapeHtml(step.getRows()[i][j]));
}
output += " ";
}
output += "
";
}
}
return output + "
";
}
private Map splitScenariosByFeatures(CucumberScenarioResult[] scenarios) {
Map result = new HashMap();
for (CucumberScenarioResult scenario : scenarios) {
String featureName = scenario.getFeature().getName();
if (result.containsKey(featureName)) {
result.put(featureName, ArrayUtils.add(result.get(featureName), scenario));
} else {
result.put(featureName, new CucumberScenarioResult[] {scenario});
}
}
return result;
}
private String drawCell(CucumberScenarioResult[] scenarios) {
String output = "";
int index = 0;
Map resultsMap = splitScenariosByFeatures(scenarios);
for (String featureName : resultsMap.keySet()) {
output = output.concat(String.format("- Feature: %s
", featureName));
for (CucumberScenarioResult scenario : resultsMap.get(featureName)) {
output = output.concat(String.format("- Scenario: %s",
index,
scenario.getName()));
output = output.concat(String.format("
",
index,
drawScenario(scenario)));
index++;
}
output = output.concat("
");
}
output += "
";
return output;
}
@Override
public void executeReport(BreakdownReportInfo info, BreakdownTable table, boolean toPDF) throws Exception {
CucumberFeatureResult[] features = readFileContent(true);
File outFile = new File(
this.getOutputDirectory() + File.separator + this.getOutputName()
+ "-" + info.getReportSuffix() + ".html");
FileUtils.writeStringToFile(outFile, generateBreakdownReport(features, info, table)
.replaceAll("\"hoverTable\"", "\"_hoverTable\""));
if (toPDF) {
this.exportToPDF(outFile, info.getReportSuffix());
}
}
@Override
protected String generateBody(BreakdownTable table,
CucumberFeatureResult[] features) throws Exception {
CucumberScenarioResult[] scenarios = new CucumberScenarioResult[] {};
for (int j = 0; j < features.length; j++) {
CucumberScenarioResult[] elements = features[j].getElements();
for (int i = 0; i < elements.length; i++) {
elements[i].setFeature(features[j]);
}
scenarios = ArrayUtils.addAll(scenarios, elements);
}
CucumberScenarioResult[][][] results = table.valuateScenarios(scenarios);
String rowHeadings = generateRowHeading(table);
String[] headingRows = rowHeadings.split("");
Assert.assertEquals(headingRows.length - 1, results.length);
String content = "";
for (int i = 0; i < results.length; i++) {
String row = headingRows[i];
for (int j = 0; j < results[i].length; j++) {
row = row.concat(drawCell(results[i][j]));
}
row = row.concat("");
content = content.concat(row);
}
return content;
}
//updatedContent = updatedContent.replaceAll("\"hoverTable\"", "\"_hoverTable\"");
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy