Closed MansiVyas4 closed 4 years ago
Hi,
I have noticed there are a lot of questions here about adding the system info, steplogs and screenshots. A lot of people that where working with cucumber where using the plugin by vimalselvam. With this you could easily add all this things to the report.
This plugin is not working in combination with the cucumber4 and new extent reports version/adapter. It is required to use the new cucumber4 adapter as a plugin. Like many noticed, it is not possible to add steplogs and screentshots to report like you used to in older versions. Some issues are opened about this. It is possible to embed an image to the scenario, but it is not working correctly for everyone. And some don't want an embedded image but an icon refering to the image.
Until there is a fix or different way of doing this in a new version. I worked arround it to restore these functionality, so I thought i'd share this. Here is what I did:
I download the 4 classes of the adapter from the sources, and added them to my project (ExtentCucumberAdapter,ExtentService,TestSourcesModel, URLOutputStream). Then offcourse you must change the packages to correspond with your package structure. And refer to your local version of the adapter in your testrunner as a plugin.
plugin = {"my.packages.adapter.ExtentCucumberAdapter:"
I have added these 3 methods the ExtentCucumberAdapter class.
public static synchronized void addStepLog(final String message){
stepTestThreadLocal.get().info(message);
}
public static synchronized void addStepScreenCaptureFromPath(final String imagePath) throws IOException {
stepTestThreadLocal.get().addScreenCaptureFromPath(imagePath);
}
public static synchronized void addStepScreenCaptureFromPath(final String imagePath, final String title) throws IOException {
stepTestThreadLocal.get().addScreenCaptureFromPath(imagePath, title);
}
Because of the threadlocal variabels it will work fine when running in parallel.
Now you can use these to add the steplogs and screenshots the report from you script:
ExtentCucumberAdapter.addStepLog("step log message here");
(i have written a ReporterUtil arround it which i use in testcode, so if it changes in the future only need to change to util)
The ExtentReports to set the systeminfo on is available via the ExtentService
public static void setSystemInfo(String key, String value) {
getExtentReports().setSystemInfo(key, value);
}
private static ExtentReports getExtentReports() {
return ExtentService.getInstance();
}
The custom xml config can be loaded by creating a new HTML reporter with same file location as the HTML reporter. And then loading the config.
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(System.getProperty("extent.reporter.html.out"));
getExtentReports().attachReporter(htmlReporter);
htmlReporter.loadXMLConfig(path);
getExtentReports().flush();
@thomasdeurloo Thanks for your Insights, I've raised Pull Request#35 which also incorporates methods to set SystemInfo, TestRunnerOutput using ExtentService
All - the ExtentService
is available to override any default settings or add new ones. Is that not working?
Hello,
I have used extent reports where i am able to add author , system info & but i am not able to do same with cucumber adapter. Is this functionality not included??? Also, I was my failure text to be resized.. Any way out doing it??