Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I call HtmlAggregateStoryReporter programmatically to get achieve the mvn serenity:aggregrate command #2358

Closed
LayMui opened this issue Jan 12, 2021 · 2 comments

Comments

@LayMui
Copy link

LayMui commented Jan 12, 2021

I am running the serenity using java command (not maven)
however, the artefact has the missing index.html

I create a file with the code snippet
package demo.report;

import net.thucydides.core.Thucydides;
import net.thucydides.core.reports.html.HtmlAggregateStoryReporter;

import java.io.File;
import java.io.IOException;

import io.cucumber.plugin.ConcurrentEventListener;
import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.EventPublisher;
import io.cucumber.plugin.event.TestRunFinished;
import io.cucumber.plugin.event.TestRunStarted;

public class Initialization implements ConcurrentEventListener {
private EventHandler setup = event -> {
// System.out.println("setup!!");
};

    private EventHandler<TestRunFinished> teardown = event -> {
        File sourceDirectory = new File("target/site/serenity/");
        HtmlAggregateStoryReporter reporter = new HtmlAggregateStoryReporter(Thucydides.getDefaultProjectKey());
        reporter.setOutputDirectory(sourceDirectory);
        try {
            reporter.generateReportsForTestResultsFrom(sourceDirectory);
        }
        catch (IOException e)
        {
            System.out.println("generateReportsForTestResultsFrom exception ");
            e.printStackTrace();
        }
    };
    
    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestRunStarted.class, setup);
        publisher.registerHandlerFor(TestRunFinished.class, teardown);
    }

}

and in my Cucumber test runner:
package demo;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
plugin = {"pretty", "demo.report.Initialization"},
features = "classpath:features",
strict = true,
snippets = CucumberOptions.SnippetType.CAMELCASE
)
public class CucumberTestSuite {

}

in the java command

  • java -Dcucumber.plugin=classpath:demo.report -Dcucumber.filter.tags=@app -Dcucumber.features=classpath:features -Dcucumber.glue=classpath:demo.stepdefinitions -Dwebdriver.driver=appium -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -Dappium.autoAcceptAlerts=true -Dappium.platformName=$DEVICEFARM_DEVICE_PLATFORM_NAME -Dappium.app=$DEVICEFARM_APP_PATH org.testng.TestNG -junit -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10

but artefact didn't generate any serenity report, that is the target/site/serenity is not even generated

is there a system system properties that I can set to achieve mvn serenity:aggregrate?

@wakaleo
Copy link
Member

wakaleo commented Jan 12, 2021

It's doable but you would need to look at the internal Serenity APIs to find a way. Why don't you just use maven or gradle?

@GianniGiglio
Copy link
Contributor

GianniGiglio commented Apr 20, 2021

@LayMui

Here is what I use:

private static ResultChecker generateHtmlStoryReports() throws IOException {
HtmlAggregateStoryReporter htmlAggregateStoryReporter = new HtmlAggregateStoryReporter("reportName");
htmlAggregateStoryReporter.setSourceDirectory(new File("build/site/report"));
htmlAggregateStoryReporter.setOutputDirectory(new File("build/site/report"));
htmlAggregateStoryReporter.generateReportsForTestResultsFrom(new File("build/site/report"));
return new ResultChecker(htmlAggregateStoryReporter.getOutputDirectory());
}

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants