Reputation: 21
I am running Cucumber+Serenity Tests using Junit:
Code snippet:
JUnitCore engine = new JUnitCore();
engine.addListener(new TextListener(System.out));
engine.run(featureClass);
For the each test execution individual html report is getting generated ,but aggregated(combined) report is not getting generated using HtmlAggregateStoryReporter directly(Reffered:https://github.com/serenity-bdd/serenity-core/issues/244)
Here is the code snippet that I used,it is getting hanged and aggregation is not completing .I am calling after all the Cucumber+Serenity Tests are completed:
HtmlAggregateStoryReporter reporter = new HtmlAggregateStoryReporter("PoC-Test");
File sourceDirectory = new File("C:\\PoC-Test\\target\\site\\serenity\\");
reporter.setSourceDirectory(sourceDirectory);
reporter.generateReportsForTestResultsFrom(reporter.getSourceDirectory());
C:\PoC-Test\target\site\serenity\ is the location where the individual Tests reports are getting generated,Could you please help me to find out what is wrong in this code?
Please share any sample working code,if any?
Upvotes: 2
Views: 18066
Reputation: 2962
HtmlAggregateStoryReporter - Generates an aggregate acceptance test report in HTML form. Reads all the reports from the output directory to generates aggregate HTML reports summarizing the results. This class connects to JIRA and generates requirements tab in the report.
Source code of the class => HtmlAggregateStoryReporter.java
This class requires:
Code snippet:
private void generateHtmlStoryReports() throws IOException {
getReporter().setSourceDirectory(sourceOfTestResult());
getReporter().setOutputDirectory(outputDirectory);
getReporter().setIssueTrackerUrl(issueTrackerUrl);
getReporter().setJiraUrl(jiraUrl);
getReporter().setJiraProject(jiraProject);
getReporter().setJiraUsername(jiraUsername);
getReporter().setJiraPassword(jiraPassword);
getReporter().generateReportsForTestResultsFrom(sourceOfTestResult());
}
Full code:(referenced from massapi)
import net.thucydides.core.Thucydides;
import net.thucydides.core.ThucydidesSystemProperty;
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.reports.html.HtmlAggregateStoryReporter;
import net.thucydides.core.util.EnvironmentVariables;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
/**
* Generate aggregate XML acceptance test reports.
x *
*/
@Mojo(name = "aggregate", requiresProject = false)
public class ThucydidesAggregatorMojo extends AbstractMojo {
/**
* Aggregate reports are generated here
*/
@Parameter(property = "thucydides.outputDirectory", defaultValue = "${project.build.directory}/site/thucydides", required=true)
public File outputDirectory;
/**
* Thucydides test reports are read from here
*/
@Parameter(property = "thucydides.source", defaultValue = "${project.build.directory}/site/thucydides", required=true)
public File sourceDirectory;
/**
* URL of the issue tracking system to be used to generate links for issue numbers.
*/
@Parameter
public String issueTrackerUrl;
/**
* Base URL for JIRA, if you are using JIRA as your issue tracking system.
* If you specify this property, you don't need to specify the issueTrackerUrl.
*/
@Parameter
public String jiraUrl;
@Parameter
public String jiraUsername;
@Parameter
public String jiraPassword;
/**
* JIRA project key, which will be prepended to the JIRA issue numbers.
*/
@Parameter
public String jiraProject;
/**
* Base directory for requirements.
*/
@Parameter
public String requirementsBaseDir;
EnvironmentVariables environmentVariables;
/**
* Thucydides project key
*/
@Parameter(property = "thucydides.project.key", defaultValue = "default")
public String projectKey;
protected void setOutputDirectory(final File outputDirectory) {
this.outputDirectory = outputDirectory;
}
protected void setSourceDirectory(final File sourceDirectory) {
this.sourceDirectory = sourceDirectory;
}
public void prepareExecution() {
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
configureEnvironmentVariables();
}
private EnvironmentVariables getEnvironmentVariables() {
if (environmentVariables == null) {
environmentVariables = Injectors.getInjector().getProvider(EnvironmentVariables.class).get() ;
}
return environmentVariables;
}
private void configureEnvironmentVariables() {
Locale.setDefault(Locale.ENGLISH);
updateSystemProperty(ThucydidesSystemProperty.THUCYDIDES_PROJECT_KEY.getPropertyName(), projectKey, Thucydides.getDefaultProjectKey());
updateSystemProperty(ThucydidesSystemProperty.THUCYDIDES_TEST_REQUIREMENTS_BASEDIR.toString(),
requirementsBaseDir);
}
private void updateSystemProperty(String key, String value, String defaultValue) {
if (value != null) {
getEnvironmentVariables().setProperty(key, value);
} else {
getEnvironmentVariables().setProperty(key, defaultValue);
}
}
private void updateSystemProperty(String key, String value) {
if (value != null) {
getEnvironmentVariables().setProperty(key, value);
}
}
private HtmlAggregateStoryReporter reporter;
protected void setReporter(final HtmlAggregateStoryReporter reporter) {
this.reporter = reporter;
}
public void execute() throws MojoExecutionException {
prepareExecution();
try {
generateHtmlStoryReports();
} catch (IOException e) {
throw new MojoExecutionException("Error generating aggregate thucydides reports", e);
}
}
protected HtmlAggregateStoryReporter getReporter() {
if (reporter == null) {
reporter = new HtmlAggregateStoryReporter(projectKey);
}
return reporter;
}
private void generateHtmlStoryReports() throws IOException {
getReporter().setSourceDirectory(sourceOfTestResult());
getReporter().setOutputDirectory(outputDirectory);
getReporter().setIssueTrackerUrl(issueTrackerUrl);
getReporter().setJiraUrl(jiraUrl);
getReporter().setJiraProject(jiraProject);
getReporter().setJiraUsername(jiraUsername);
getReporter().setJiraPassword(jiraPassword);
getReporter().generateReportsForTestResultsFrom(sourceOfTestResult());
}
private File sourceOfTestResult() {
if ((sourceDirectory != null) && (sourceDirectory.exists())) {
return sourceDirectory;
} else {
return outputDirectory;
}
}
}
Upvotes: 1
Reputation: 641
Are you adding the Serenty's aggregate
goal to your build? What build tool are you using?
Here's a solution which should work for Maven:
Either
serenity:aggregate
goal to your call statement. This will run your build and execute aggregation of the report. E.g.:mvn test -Dserenity.outputDirectory=C:/PoC-Test/target/site/serenity serenity:aggregate
or
serenity:aggregate
after your build is done, e.g.:mvn serenity:aggregate -Dserenity.outputDirectory=C:/PoC-Test/target/site/serenity
Upvotes: 1