NEW Posts – Generating Spark and Pdf Extent Report for “Rest Assured with Maven plugin” and “Rest Assured and Cucumber with Maven plugin”
Introduction
This article deals with generating Extent reports for Cucumber-JVM version 5 using the ExtentReports Cucumber Adapter Plugin. The article details out the procedure to create Spark, HTML, Logger, Json and PDF reports. The adapter plugin is available in the tech.grasshopper groupid in Maven repository. This is based on the existing adapter for version 4 with changes made to work with version 5.
IMPORTANT – ExtentReports has been updated to version 5, which has resulted in multiple reporters getting deprecated. Currently this only supports the Spark, Json and Klov reports. The latest adapter version (2.x) generates only these three reports, along with the custom PDF and HTML reports. To work with ExtentReports version 4, add the 1.5.1 adapter version. Refer to the ‘POM Dependencies’ section for more details.
The various steps required for this are to add the adapter dependency to the POM, configure plugin in the runner, enable report generation and modify report settings.
The adapter also generates the new PDF report. Among other new features are the ability to have customized report folder names with timestamps, adding base64 string images and setting the display order of Spark report. Also a technique for merging reports obtained in rerun executions is mentioned. Detailed explanation of these features are available in the separate sections. These features are only available with the adapter version series 2.x.
An article for creating Extent Report using a Cucumber-JVM 7 adapter can be found here and for a Cucumber-JVM 6 adapter can be found here and for a Cucumber-JVM 4 adapter can be found here .
To create Extent Report using a Maven plugin, which uses the Cucumber JSON report and runs in the post-integration-test phase, refer to this article. This plugin is independent of Cucumber version and works for JSON report generated with Cucumber versions 4.3.0 and above.
Source
The source code for the article is located here. The source code for extentreports-cucumber5-adapter plugin is located here. The artifact can be found in Maven at this location.
POM Dependencies
The latest version of extentreports-cucumber5-adapter dependency needs to be added to the POM, to work with ExtentReports version 5.
<dependency> <groupId>tech.grasshopper</groupId> <artifactId>extentreports-cucumber5-adapter</artifactId> <version>2.17.0</version> <scope>test</scope> </dependency>
The POM for this configuration is located here.
The below version of extentreports-cucumber5-adapter dependency needs to be added to the POM, to work with ExtentReports version 4.
<dependency> <groupId>tech.grasshopper</groupId> <artifactId>extentreports-cucumber5-adapter</artifactId> <version>1.5.1</version> <scope>test</scope> </dependency>
Plugin Configuration
The extentreports-cucumber5-adapter plugin needs to be added to the CucumberOptions annotation of the runner.
@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
Add the colon ‘:’ at the end of the plugin argument, else below exception is thrown.
cucumber.runtime.CucumberException: You must supply an output argument to com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.
Report Activation
First method of activating the report generation is to place extent.properties file in the src/test/resources folder or in the src/test/resources/com/avenstack/adapter folder to be picked up by the adapter. This is ideal for setting up large number of properties. The complete settings for logger and html can be found here. Below examples show the case of the html report.
extent.reporter.spark.start=true extent.reporter.spark.out=test-output/SparkReport/Spark.html
Second way is to add the required key and value pairs to the System properties. There are again two ways of achieving it.
One way is to add the properties to the configuration section of the Maven Surefire or Failsafe plugin. This is also ideal for setting up large number of properties
<configuration> <systemPropertyVariables> <extent.reporter.spark.start>true</extent.reporter.spark.start> <extent.reporter.spark.out>test-output/SparkReport/Spark.html</extent.reporter.spark.out> </systemPropertyVariables> </configuration>
Other way is to pass the property key-values in the Maven command. This is useful for small number of properties.
mvn clean install -DargLine="-Dextent.reporter.spark.start=true -Dextent.reporter.spark.out=test-output/SparkReport/Spark.html"
Report Settings
The configurations like report activation and location can be mentioned in the extent.properties or using maven settings as shown in the section above. To change settings like theme, title, encoding, offlineMode etc, a separate xml file eg. spark-config.xml is required. The location for this file eg. html report needs to be mentioned as value for the key extent.reporter.spark.config.
extent.reporter.spark.config=src/test/resources/spark-config.xml
This xml location key-value pair can also be set using Maven plugin configuration or command line as in the section above.
All that is left to execute the POM and check the reports.
Report Attachments
To add attachments, like screen images, two settings need to be added to the extent.properties. First property, named screenshot.dir, is the directory where the attachments are stored. Second is screenshot.rel.path, which is the relative path from the report file to the screenshot directory. In the below setting, the Spark report (named index.html by default) will navigate to the saved attachments by using the relative path setting.
extent.reporter.spark.out=test-output/SparkReport/
screenshot.dir=test-output/
screenshot.rel.path=../
A more expanded scenario could be storing the images in a folder named ‘screenshots’ and the reports generated in the ‘test-output’ folder. The ‘screenshots‘ and the ‘test-output‘ folders are at the same level. The report will need to step down two folder levels and then move to the required directory.
extent.reporter.spark.out=test-output/SparkReport/
screenshot.dir=screenshot/
screenshot.rel.path=../../screenshot/
If the reports and screenshot are configured to be located in the same folder, then set the screenshot.rel.path value to “./”.
The HTML report also uses the same logic for displaying attachments.
Excel Extent Report [New Feature]
The Excel reporter summarizes the test run results in a dashboard worksheet and other worksheets with feature, scenario, exception, tags, authors and devices details. The dashboard and exception sheets are non-editable.
This report needs to be enabled in the extent.properties file.
extent.reporter.excel.start=true
extent.reporter.excel.out=test output/ExcelReport/ExtentExcel.xlsx
An image of the dashboard worksheet is displayed on the right. A sample report can be found here.
This report gives a high level overview of the test execution. This does not provide step level details such as step text, logs, screenshots etc.
Do not use this report if the setup contains multiple runners as concurrent modification of the same excel file will result in errors.
An article dedicated for this feature will be created soon.
PDF Extent Report [New Feature]
The PDF reporter summarizes the test run results in a dashboard and other sections with feature, scenario and step details. The PDF report needs to be enabled in the extent.properties file.
extent.reporter.pdf.start=true
extent.reporter.pdf.out=test-output/PdfReport/ExtentPdf.pdf
A sample report can be found here.
The default color settings can be modified by using a YAML config file, named pdf-config.yaml in the project src/test/resource folder. There are configuration changes in the latest version.
Do not use this report if the setup contains multiple runners as concurrent modification of the same PDF will result in errors. Better solution would be use a Maven plugin for creating just the PDF report or the complete ExtentReport suite.
The detailed documentation for this feature is available in this article.
Device & Author Tags [New Feature]
The device and author information can be added to the feature files as tags for the feature, scenario, scenario outline and examples keyword. This feature needs to be enabled in the extent.properties file. These tags need to be a prefixed with a predefined character sequence and these will be treated separately from the categories tags. This will display the device and author details in respective tabs of the Spark report. Also the scenario counts will be displayed in the dashboard for both.
The extent.reporter.spark.enable.device and extent.reporter.spark.enable.author settings need to be set to true, for the device and author information to be displayed. Both or one of them can be enabled.
extent.reporter.spark.enable.device=true
extent.reporter.spark.enable.author=true
The default prefix for the device tag is ‘@dev_‘ and for the author it is ‘@aut_‘. The case is ignored. For example the device tag will be ‘@dev_iphone’ and author will be ‘@aut_bloch’. These default values can be changed by using the extent.reporter.spark.prefix.device and extent.reporter.spark.prefix.author settings.
extent.reporter.spark.prefix.device=@device_
extent.reporter.spark.prefix.author=@author_
This feature is available from version 1.8.0 and higher. This currently works only for the Spark and HTML reports.
Spark & PDF Report Status Filter [New Feature]
The Spark and PDF report can be filtered by status, with the help of extent.reporter.statusfilter setting in the extent.properties. This takes a comma delmited case insensitive value of statuses. This corresponds to the ExtentReport status. The filter is applied at the feature level.
The valid values are pass, fail, skip, info and warning. The first three statuses will be most relevant. If an invalid status is provided then this will fail silently and this setting will be ignored.
#Failed and skipped
extent.reporter.statusfilter=fail,skip
#Only passed
extent.reporter.statusfilter=pass
This feature is available from version 2.14.3 and higher. This currently works only for the Spark and PDF reports.
Ported HTML Extent Report [New Feature]
The original HTML Extent Reporter was deprecated in 4.1.3 and removed in 5.0.0. The HTML report available in the adapter is based on the same code base and is similar in appearance. The major changes are in the Freemarker template code which have been modified to work with the Extent Reports version 5. The report code can be found at this location.
The HTML report needs to be enabled in the extent.properties file.
extent.reporter.html.start=true
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
To change settings like theme, title, encoding, offlineMode etc, a separate xml file eg. html-config.xml is required. The location for this file eg. html report needs to be mentioned as value for the key extent.reporter.html.config.
extent.reporter.html.config=src/test/resources/html-config.xml
Customized Report Folder Name [New Feature]
To enable report folder name with date and\or time details, two settings need to be added to the extent.properties. These are basefolder.name and basefolder.datetimepattern. These will be merged to create the base folder name, inside which the reports will be generated. The basefolder.datetimepattern value should be a valid date time formatter pattern.
extent.reporter.spark.out=test-output/SparkReport/
screenshot.dir=test-output/
screenshot.rel.path=../
basefolder.name=reports
basefolder.datetimepattern=d-MMM-YY HH-mm-ss
With the above settings, a base folder with the name reports 10-Aug-20 10-25-50 will contain the reports. Screenshots if any, will be located inside the reports 10-Aug-20 10-25-50/test-output folder structure. Similarly the report will be created in the reports 10-Aug-20 10-25-50/test-output/SparkReport folder structure. The point to remember is that the generated folder name should be valid for the underlying file system.
The delimiter between the name and date time pattern can be controlled by using the basefolder.enable.delimiter setting. The default value is true. When this is set to false, there is no space between the name and pattern. The delimiter value can customized by using the basefolder.delimiter setting. The default value is space.
#default is true
basefolder.enable.delimiter=true
#default is space. Custom delimiter
basefolder.delimiter=_
When the basefolder settings are not provided, the reports and related files are generated without any additional folder.
Spark Report View Order [New Feature]
The default tab view order of the Spark reporter is – test, exception, category, device, author, log, dashboard tabs. Currently this order is fixed and cannot be changed. This new feature allows the order to be changed by adding the extent.reporter.spark.vieworder in the extent.properties files. The below value will display the report with the dashboard tab as default.
extent.reporter.spark.vieworder=dashboard,test,category,exception,author,device,log
The value needs to be a comma delimited text without any spaces. Any error in parsing will silently use the default view order. To restrict the number of tabs, just mention the name of the required tabs. For example, if only the test and dashboard views are needed use the below setting
extent.reporter.spark.vieworder=dashboard,test
An example of a complete file can be found here.
Attach Image as Base64 String [New Feature]
This feature can be used to attach images to the Spark report by setting the src attribute of the img tag to a Base64 encoded string of the image. When this feature is used, no physical file is created. There is no need to modify any step definition code to use this. To enable this, use the below settings in extent.properties, which is false by default.
extent.reporter.spark.base64imagesrc=true
The Spark report file size will be pretty large and there could be memory issues if a substantial number of images are present. A generic thumbnail is created and on clicking the image is displayed. To include an image thumbnail, add the following configuration to the Spark configuration file.
<thumbnailForBase64>true</thumbnailForBase64>
Merging Rerun Reports [New Feature]
This feature is not part of the adapter but Spark rerun reports can be merged by using the artifact mentioned in this article. This will require the generation of JSON Extent report in the Cucumber execution.
Below is the setting for JSON report generation.
extent.reporter.json.start=true
extent.reporter.json.out=test-output/JsonReport/Json.json
Environment or System Info Properties [New Feature]
It is now possible to add environment or system info properties in the extent.properties or pass them in the maven command line. These key value pairs are displayed in the ‘Environment’ section of the dashboard page. The key string should begin with the prefix – ‘systeminfo.‘. Be careful of the dot at the end.
These can be added to the extent.properties as following – ‘systeminfo.os=windows‘. For passing the values in maven command use as following – ‘-Dsysteminfo.core=16‘. Both methods can be used simultaneously, the report will display all the values.
Parallel And\Or Multiple Runner Execution
There is no additional configuration settings required for parallel execution with a single or multiple runners. This is also true for single threaded multiple runner execution.
For parallel execution using JUnit refer here and for TestNG refer here.
Hi Mounish ,
Earlier the Report was having the beautiful design.
But now in the report , CSS seems to be failing . Is there any update that I needs to take care of .
I am using the following configuration.
tech.grasshopper
extentreports-cucumber6-adapter
2.8.2
test
com.github.ralfstuckert.pdfbox-layout
pdfbox2-layout
Please help me to resolve the CSS breaking issue
Spark report? What is breaking? Which section?
I ran the reports today and it looked good.
Use the latest version 2.8.4. Also no need for pdfbox2-layout dependency. Remove it.
Hello Mounish,
I execute feature with parallel, and I found sometime will not genarate html after complete.
The error is like below:
Aug 18, 2021 5:04:31 PM com.aventstack.extentreports.reporter.ExtentSparkReporter flush
SEVERE: An exception occurred
FreeMarker template error:
The following has evaluated to null or missing:
==> info [in template “spark/partials/dashboard.ftl” at line 214, column 24]
—-
Tip: If the failing expression is known to legally refer to something that’s sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use when-presentwhen-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
—-
—-
FTL stack trace (“~” means nesting-related):
– Failed at: #if info.name?? [in template “spark/partials/dashboard.ftl” at line 214, column 19]
– Reached through: #include “partials/${view.toString()}… [in template “spark/spark.spa.ftl” at line 27, column 36]
—-
Java stack trace (for programmers):
—-
freemarker.core.InvalidReferenceException: [… Exception message was already printed; see it above …]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85)
at freemarker.core.UnexpectedTypeException.(UnexpectedTypeException.java:48)
at freemarker.core.NonHashException.(NonHashException.java:49)
at freemarker.core.Dot._eval(Dot.java:48)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.ExistsExpression._eval(ExistsExpression.java:49)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalToBoolean(Expression.java:177)
at freemarker.core.Expression.evalToBoolean(Expression.java:163)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:48)
at freemarker.core.Environment.visit(Environment.java:370)
at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321)
at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:644)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:334)
at freemarker.core.Environment.visit(Environment.java:376)
at freemarker.core.Environment.visitAndTransform(Environment.java:501)
at freemarker.core.CompressedBlock.accept(CompressedBlock.java:42)
at freemarker.core.Environment.visit(Environment.java:334)
at freemarker.core.Environment.include(Environment.java:2925)
at freemarker.core.Include.accept(Include.java:171)
at freemarker.core.Environment.visit(Environment.java:370)
at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321)
at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:644)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:334)
at freemarker.core.Environment.visit(Environment.java:340)
at freemarker.core.Environment.process(Environment.java:313)
at freemarker.template.Template.process(Template.java:383)
at com.aventstack.extentreports.templating.FreemarkerTemplate.processTemplate(FreemarkerTemplate.java:53)
at com.aventstack.extentreports.templating.FreemarkerTemplate.getSource(FreemarkerTemplate.java:39)
at com.aventstack.extentreports.templating.FreemarkerTemplate.writeTemplate(FreemarkerTemplate.java:45)
at com.aventstack.extentreports.reporter.AbstractFileReporter.processTemplate(AbstractFileReporter.java:74)
at com.aventstack.extentreports.reporter.ExtentSparkReporter.flush(ExtentSparkReporter.java:149)
at com.aventstack.extentreports.reporter.ExtentSparkReporter.access$1(ExtentSparkReporter.java:139)
at com.aventstack.extentreports.reporter.ExtentSparkReporter$1.onNext(ExtentSparkReporter.java:121)
at com.aventstack.extentreports.reporter.ExtentSparkReporter$1.onNext(ExtentSparkReporter.java:1)
at io.reactivex.rxjava3.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:310)
at io.reactivex.rxjava3.subjects.PublishSubject.onNext(PublishSubject.java:226)
at com.aventstack.extentreports.ReactiveSubject.onFlush(ReactiveSubject.java:83)
at com.aventstack.extentreports.AbstractProcessor.onFlush(AbstractProcessor.java:85)
at com.aventstack.extentreports.ExtentReports.flush(ExtentReports.java:284)
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.finishReport(ExtentCucumberAdapter.java:281)
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.access$600(ExtentCucumberAdapter.java:59)
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter$8.receive(ExtentCucumberAdapter.java:128)
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter$8.receive(ExtentCucumberAdapter.java:125)
at io.cucumber.core.eventbus.AbstractEventPublisher.send(AbstractEventPublisher.java:51)
at io.cucumber.core.eventbus.AbstractEventBus.send(AbstractEventBus.java:12)
at io.cucumber.core.runtime.CucumberExecutionContext.emitTestRunFinished(CucumberExecutionContext.java:93)
at io.cucumber.core.runtime.CucumberExecutionContext.finishTestRun(CucumberExecutionContext.java:74)
at io.cucumber.testng.TestNGCucumberRunner.finish(TestNGCucumberRunner.java:127)
at io.cucumber.testng.AbstractTestNGCucumberTests.tearDownClass(AbstractTestNGCucumberTests.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320)
at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:217)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:130)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Could you help? Thx
The error seems to be coming due to “System Info”. Refer to source https://github.com/extent-framework/extentreports-java/blob/6d004b293b3f49969ba4e429960822f783a3c87a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/dashboard.ftl#L214
I am not sure why this is happening. Can u try by removing any set System Info key value pairs?
Thanks
Hi Mounish
I was able to generate the reports now. There was issue with my eclipse ide. For attaching the screenshots, is this statement enough- extent.reporter.spark.base64imagesrc=true
or I have to write additional code to attach the screenshots?
Thanks
Mohit
U will need to write the usual code for taking the screenshot through selenium. https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/3adf17732b6a9b3d5a3883e14f41d45a1edfd878/cuke5-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L155.
Two ways of adding these to the reports, setting up the relative paths to the physical image file – refer to the section “Report Attachments”and the base64 embedded style – refer to the section “Attach Image as Base64 String”. Both will need the respective settings in the extent.properties which are mentioned.
The pdf report does not support embedding base64 strings currently.
Thank you Mounish. I will check the sample project and I will get back to you.
Hi Mounish
Thanks for sharing this new and advanced reporting feature. I am using maven and bdd in my project. I’m also using cucumber5 adapter. After I have setup the project, I am getting an error as –
io.cucumber.core.exception.CucumberException:Java.lang.NoClassDefFoundError:couldn’t initialize class Com.aventstack.extentreports.service.ExtentService$ExtentReportsLoader.Could you please suggest what could I be missing?
Thanks
Mohit
Have u checked out the sample implementation – https://github.com/grasshopper7/cuke5-extent-adapter-report. Is the scope for the jars in the POM correctly set?
I am trying to use Extent Report 5 for Cucumber JVM 5. My question is how can I use Reporter object anywhere in my scenarios stepdefinitions to log a customized statement or to attach a screenshot for any statement. Please help.
Statement – https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/3f9e2990629620c23ebf7697b54faabd165357fe/cuke5-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L160
Screenshot – https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/3f9e2990629620c23ebf7697b54faabd165357fe/cuke5-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L162
Thanks for the quick reply Manish. But using scenario.write(), the customized statement passed is displayed as a regular step in the report. Is there any other way possible to write customized statements. Can you provide some help in using below syntax
ExtentSparkReporter spark = new ExtentSparkReporter(“target/sparkReport/spark.html”);
ExtentReports extent = new ExtentReports();
extent.attachReporter(spark);
ExtentTest test = extent.createTest(“My First TC”);
If u r using the adapter then there is no way to access the ExtentTest object, created by the adapter, in the step definition code. Not sure I understand “write customized statement”?
In the extent-config.xml there is a scripts section, where you can add custom javascript to manipulate the report. Maybe you can use this.
Hi,
Instead of getting into test-output folder the screenshot in my project is getting save into the outermost part of the project,i.e., at the end of project. and if test case is failed then in the report it is not reflecting
Which adapter version are u using?
Hi Mounish,
I am using extentreports-cucumber6-adapter-2.6.0 version(tech.grosshopper)..while i am exporting the report via any stream(slack or mail etc) the person unable to view the screenshot.Any solution for this.Thanks in advance
Which report are u sending? Spark or pdf?
Hi Mounish,
Thanks for your contribution.
I’m trying to take screenshots only when a test fails. I tried your code from here but this is taking screenshots after every step. https://github.com/grasshopper7/extentreports-cucumber5-adapter/blob/master/extentreports-cucumber5-adapter/src/test/java/cucumber/examples/java/calculator/ScreenShotStepDefinition.java
Could you please help me with the sample code for screenshots only on Test Failures? Also, When I open the report now I can see the image icon and when I open it I do not see the actual screenshot.
U should check the sample implementation project, link is available in the article. – https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/7af04c1f6856031ebe34eaa7298e54992cdef3ec/cuke5-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L158.
Refer to the ‘Report Attachments’ section for details about setting up the parameters for screenshots. Hopefully it should solve the issues. If not let me know.
How to generate unique report with extent report as it will override each time.
extent.reporter.html.out=Cucumber-Reports/HtmlReport/ExtentHtml.html
is it possible add date function and make report unique and not to override.
This functionality is already available. Search for “Customized Report Folder Name” in the article.
Hello,
I’m able to generate an extent -report but unable to attached the screenshot for the failure scenario.
extent.properties file
extent.reporter.klov.start=false
extent.reporter.spark.start=true
extent.reporter.json.start=true
extent.reporter.pdf.start=true
extent.reporter.logger.start=true
extent.reporter.klov.config=src/test/java/klov.properties
extent.reporter.spark.config=src/test/java/extent-config.xml
extent.reporter.spark.out=test output/Spark/Test-Report.html
extent.reporter.json.out=test output/Json/ExtentJson.json
extent.reporter.pdf.out=test output/PdfReport/Test-Pdf.pdf
extent.reporter.logger.out=test output/Logger
#test,dashboard,category,exception,author,device,log
extent.reporter.spark.vieworder=dashboard,test,category,exception,author,device,log
#embed image as base64 string src
extent.reporter.spark.base64imagesrc=true
screenshot.dir=test output/
screenshot.rel.path=../
systeminfo.os=Windows
systeminfo.version=10
#this is optional and creates the report in base folder name with date time format
#basefolder.name=reports
#basefolder.datetimepattern=d-MMM-YY HH-mm-ss
Any errors? U need to set extent.reporter.spark.base64imagesrc value to false if u do not want base64 images. Refer to this for screenshot code – extent.reporter.spark.base64imagesrc
Hi Mounish ,
AmbiguousStepDefinitionsException is not handled in the pdf report.
For example I have the following feature file
Scenario: Test different status
Given I have a pending step
And I have a ambiguous step
The step definition is given below
@Given(“I have a pending step”)
public void i_have_a_pending_step() {
System.out.println(“pending”);
}
@And(“I have a ambiguous step”)
public void i_have_a_ambiguous_step() {
System.out.println(“ambiguous “);
}
@And(“^I have a ambiguous step$”)
public void i_have_a_ambiguous_step() {
System.out.println(“ambiguous “);
}
This will throw an error io.cucumber.core.runner.AmbiguousStepDefinitionsException in IDE. But in pdf report it is shown as passed. I think it should show a failure. Am I right?
Will have a look at the result calculation. But if I remember correctly, the pdf report generated from the Extent adapter displays the result calculated by the Extent code. What is the result in the Spark report?
Thanks for the quick reply Mounish. The same issue is seen in Spark report also.
1. If the scenario has 4 steps and in the third step AmbiguousStepDefinitionsException occurs the first 3 steps will get passed, 4th step will be skipped and the status of scenario will be shown as skipped.
2. If the scenario has 4 steps and in the fourth step AmbiguousStepDefinitionsException occurs all the 4 steps will get passed and the status of scenario will be shown as passed.
Could you please confirm this from your side also?
Will have a detailed look. Can u open an issue in the github repo?
Sure Mounish. Could you please provide the link also.
I forgot to mention the version of cucumber adapter that I am using. Please find below the dependency in my gradle file.
‘tech.grasshopper:extentreports-cucumber6-adapter:2.6.0’
I just noticed something. Are you using the cucumber 6 adapter with cucumber version 5. Becoz the dependency is version 6 and the article is for version 5. Thx
Sorry Mounish. I have posted the comment accidentally in the wrong article “Cucumber-JVM 5 Report generation”. Please find below my dependencies in my gradle file
implementation ‘tech.grasshopper:extentreports-cucumber6-adapter:2.6.0’
implementation ‘com.github.ralfstuckert.pdfbox-layout:pdfbox2-layout:1.0.0’
testImplementation ‘junit:junit:4.13’
testImplementation ‘io.cucumber:cucumber-java:6.9.1’
testImplementation ‘io.cucumber:cucumber-junit:6.9.1’
Could you please check whether my dependencies are correct?
Hi Mounish,
I am trying to attach jpeg image as screenshot in the extent spark report but image not attaching properly in extent spark report only png images attaching properly .
Could you please help me to resolve this issue.
byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, “image/jpeg”, “”);
I just tried it with the sample project – https://github.com/grasshopper7/cuke5-extent-adapter-report. Changed to jpeg and commented out the base64 setting (extent.reporter.spark.base64imagesrc). This uses the latest adapter version 2.6.0. Works perfectly.
What error r u getting?
Hi Mounish,
Image is not attaching properly in jpeg format . Its just white image with cross button. can u please help what went wrong in jpeg .?
Image is attaching properly in report when png format mentioned .
Screenshot code:
TakesScreenshot ts = (TakesScreenshot) driver;
byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, “image/jpeg”, “”);
Extent.properties:
commented :
#embed image as base64 string src
#extent.reporter.spark.base64imagesrc=true
Pom.xml:
tech.grasshopper
extentreports-cucumber6-adapter
2.6.0
test
Try it with the sample project mentioned earlier. Is the jpeg file generated in the correct folder?
Yes Jpeg image is created correctly in folder but while attaching its creating issue . Just a white image with cross button.
Check the settings – ‘screenshot.dir’ & ‘screenshot.rel.path’, Refer to the ‘Report Attachments’ section in the article.
Report is not generated when cucumber project is run as jar
getting below error when I used this, any help is greatly appreciated
io.cucumber.core.exception.CucumberException: java.lang.NoClassDefFoundError: io/cucumber/core/internal/gherkin/ast/Node
at io.cucumber.core.plugin.PluginFactory.newInstance(PluginFactory.java:118)
at io.cucumber.core.plugin.PluginFactory.instantiate(PluginFactory.java:97)
at io.cucumber.core.plugin.PluginFactory.create(PluginFactory.java:62)
at io.cucumber.core.plugin.Plugins.createPlugins(Plugins.java:32)
at io.cucumber.core.plugin.Plugins.(Plugins.java:25)
at io.cucumber.junit.Cucumber.(Cucumber.java:161)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NoClassDefFoundError: io/cucumber/core/internal/gherkin/ast/Node
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.(ExtentCucumberAdapter.java:87)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at io.cucumber.core.plugin.PluginFactory.newInstance(PluginFactory.java:114)
… 22 more
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.internal.gherkin.ast.Node
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
… 28 more
U need to make sure the dependencies in the project are correct. Refer to this POM https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/master/cuke5-extent-adapter-report/pom.xml.
Hi Mounish,
Could we use the klov report with the updated plugin,?
Would really be nice if you could share an article with its implementation and benefits.
Regards
Santhosh
The plugin should work with klov reporter. U will need to it enable it in the extent.properties by setting the out property to true. I have not used klov yet, but will have a look into it.
Thanks @Mounish. This is strange, HTML Report was the most comprehensive report.
U could try to convince the author of extentreport to bring it back by opening an issue – https://github.com/extent-framework/extentreports-java/issues. What are u missing in the Spark report?
With extentreports-cucumber6-adapter 2.0.0, have we stopped support for HTML report, we only get spark report?
I am not able to generate the HTML report.
#extent.properties
extent.reporter.html.start=true
extent.reporter.spark.start=true
extent.reporter.json.start=true
extent.reporter.spark.config=src/test/resources/extent-config.xml
extent.reporter.html.config=src/test/resources/extent-config.xml
extent.reporter.spark.out=test output/Spark/ExtentSpark.html
extent.reporter.json.out=test output/Json/ExtentJson.json
extent.reporter.html.out=test output/HtmlReport/ExtentHtml.html
Extent version 5 has deprecated most of the reports including html and logger. U need to downgrade to 1.2.0 to work with extent V4 which supports html report also.
The test runs fine but reports are not generated. Here are the
plugin = {“pretty”, “html:target/cucumber-html-report”, “json:target/cucumber-reports/cucumber.json”,
“com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:”}
extent.properties: (also have extent-config.xml in resources folder)
extent.reporter.spark.start=true
extent.reporter.json.start=true
extent.reporter.spark.config=src/test/resources/extent-config.xml
extent.reporter.spark.out=test-output/Spark/ExtentSpark.html
extent.reporter.json.out=test-output/Json/ExtentJson.json
screenshot.dir=test-output/
screenshot.rel.path=../
systeminfo.os=Windows
systeminfo.version=10
basefolder.name=reports
basefolder.datetimepattern=d-MMM-YY HH-mm-ss
pom.xml
tech.grasshopper
extentreports-cucumber5-adapter
1.5.1
The reports should be available in the reports folder. Have u tried with the sample implementation?
In spark report of Features % result showing only after decimal eg, if the result 0.00% it is dispalying as .00% so the digit before decimal is not dispalying
these are displaying only if i use Tags in TestRunner. If we dont use tags , then tags tab will dont dispay in the report. But even for tags also should work and it scenarios should display only once
As I have said earlier, create an issue at the github link https://github.com/grasshopper7/extentreports-cucumber5-adapter/issues with the details and attachments. I will look into it. I am unable to follow your multiple requests for clarifications in the comments forum.
Hi ,
I am have 2 tests in my feature file. But displaying duplicate each test . anybody know answers plz add your comments
Can u add the feature file here? Do the 2 scenarios have the same name?
Feature: Login functionality
Description: Login functionality Valid and Invalid Credentials
@LoginTests
Scenario Outline: Login with valid credentials
Given user is on home page
When go to login page
And enter username “” and password “”
And click login button
Then moves to login success page
And user logout of the application
Examples:
| username | | password |
| santosh2006043@gmail.com | | Qwer$123 |
@LoginTests
Scenario Outline: Login with invalid credentials
Given user is on home page
When go to login page
And enter username “” and password “”
And click login button
Then user see login failure message
Examples:
| username | | password |
| santosh2006043@gmail.com | | Qwer$123456 |
In report displaying duplicates as below.
STATUS TIMESTAMP TESTNAME
18:34:42 PM Login with valid credentials
Login functionality.Login with valid credentials
18:34:42 PM Login with valid credentials
Login functionality.Login with valid credentials
18:35:13 PM Login with invalid credentials
Login functionality.Login with invalid credentials
18:35:13 PM Login with invalid credentials
Login functionality.Login with invalid credentials
above screenshot extra step name stepDefinitions.LoginSteps.afterSite(io.cucumber.java.Scenario) is diplaying in Tests page . How to remove this step name from the report?
Below are logs dispalyed in Logger hrml file
[Login functionality] started
08.20.2020 00:30:15 PASS |—[Login with valid credentials] started @LoginTests
08.20.2020 00:30:15 PASS |—[Login with valid credentials] started @LoginTests
08.20.2020 00:30:15 PASS |—[Given user is on home page] started
08.20.2020 00:30:17 PASS |—[Given user is on home page]
08.20.2020 00:30:17 PASS |—[When go to login page] started
08.20.2020 00:30:31 PASS |—[When go to login page]
08.20.2020 00:30:31 PASS |—[And enter username “santosh2006043@gmail.com” and password “Qwer$123”] started
08.20.2020 00:30:33 PASS |—[And enter username “santosh2006043@gmail.com” and password “Qwer$123”]
08.20.2020 00:30:33 PASS |—[And click login button] started
08.20.2020 00:30:52 PASS |—[And click login button]
08.20.2020 00:30:52 PASS |—[Then moves to login success page] started
08.20.2020 00:30:53 PASS |—[Then moves to login success page]
08.20.2020 00:30:53 PASS |—[And user logout of the application] started
08.20.2020 00:30:56 PASS |—[And user logout of the application]
08.20.2020 00:30:56 FAIL |—[Login with invalid credentials] started @LoginTests
08.20.2020 00:30:56 PASS |—[Login with invalid credentials] started @LoginTests
08.20.2020 00:30:56 PASS |—[Given user is on home page] started
08.20.2020 00:31:00 PASS |—[Given user is on home page]
08.20.2020 00:31:00 PASS |—[When go to login page] started
08.20.2020 00:31:08 PASS |—[When go to login page]
08.20.2020 00:31:08 PASS |—[And enter username “santosh2006043@gmail.com” and password “Qwer$123456”] started
08.20.2020 00:31:08 PASS |—[And enter username “santosh2006043@gmail.com” and password “Qwer$123456”]
08.20.2020 00:31:08 PASS |—[And click login button] started
08.20.2020 00:31:15 PASS |—[And click login button]
08.20.2020 00:31:15 PASS |—[Then user see login failure message] started
08.20.2020 00:31:16 PASS |—[Then user see login failure message]
08.20.2020 00:31:16 FAIL |—[Login with invalid credentials] started @LoginTests
08.20.2020 00:31:16 PASS |—[Given user is on home page] started
08.20.2020 00:31:16 PASS |—[Given user is on home page]
08.20.2020 00:31:16 PASS |—[When go to login page] started
08.20.2020 00:31:22 PASS |—[When go to login page]
08.20.2020 00:31:22 PASS |—[And enter username “santosh2006043@gmail.com” and password “12345”] started
08.20.2020 00:31:23 PASS |—[And enter username “santosh2006043@gmail.com” and password “12345”]
08.20.2020 00:31:23 PASS |—[And click login button] started
08.20.2020 00:31:25 PASS |—[And click login button]
08.20.2020 00:31:25 FAIL |—[Then user see login failure message] started
These are not duplicate lines in the Logger report. They are actually two different lines. First one reports that the step is started and the second one mentions the actual step. Check the word ‘started’ in the the first one.I will check the duplicated initial test name lines.
08.20.2020 00:30:15 PASS |—[Login with valid credentials] started @LoginTests
08.20.2020 00:30:15 PASS |—[Login with valid credentials] started @LoginTests
You should consider moving to Spark report as the Logger and HTML report will be removed as I am going to move the adapter dependency to Extent Report 5 version.
Plus if this is your actual feature file there seems to be 2 things u should look at. I am not familiar with the Description keyword. The examples table has double || delimiters. Only one is enough.
Only in tags tab the scenarios are displaying duplicate and in tags section on dashboard page in these two tags places the scenarios displaying duplicate
Mounish ,
Anything got why displaying duplicate scenarios in tags tab .
and below step name is displaying above screenshot . How to remove this step name? I want only screenshot
stepDefinitions.LoginSteps.afterSite(io.cucumber.java.Scenario)
Can u open an issue in github – https://github.com/grasshopper7/extentreports-cucumber5-adapter/issues? Do attach the feature file and report in the issue.
Hello,
I’m not sure that the screenshot relative path is working. I have the following setup:
screenshot.dir=test-output/
screenshot.rel.path=../
The screenshot is always saving to the test-output folder. How do I get it to save to the test run folder if I have my output like this:
extent.reporter.html.out=test-output/Run_072920/test-results-report.html
Try
screenshot.dir=test-output/Run_072920/
screenshot.rel.path=../
Hi,
I dont see json getting generated for SparkReporter similar to feature available in ExtentReport 4.1.5 version. Also, how to configure modelBuilder.createDomainFromJsonArchive in extent-config.xml ?
This was very good feature and would really be helpful if you continue for Cucumber as well.
Thanks!
The plugin creates reports for currently executing scenarios rather than getting past run data for appending. Can u add some details how you are using this kind of functionality? Also not sure of json from SparkReporter, are u generating this by using the extent JSONFormatter reporter?
Hi Mounish,
Really Appreciate this post, tried it out and works ! Thank you.
Would like to know few more things,
1. Is there a way where we can fail the step explicitly (i.e. custom message failure from the step definitions like step.fail(“message”); ) ?
2.Screenshots to be added on the same step using the file name (currently i have the capture screenshot on a separate file in Hooks.java and this adds a new step in the report, like stepDefinitions.Hooks.afterSite(io.cucumber.java.Scenario) Img)
Regards,
Santhosh
Point 1 – Use the fail(“….”) of junit or testng to fail the step explicitly. Do take into account that any following steps in the scenario will be skipped.
Pont 2 – Move the before hook to the step definition file and get hold off the scenario object. Then u can capture the images in the step.
Thanks for the reply, will try it out and keep you posted.
Hi Mounish
Is there a possibility to set the report path programmatically instead of extent.properties file .i.e. to create to a new run folder with the timestamp, this helps in storing any previous run reports as well for validations?
Regards
Check the ‘Report Settings’ section of this article.
Hi Mounish,
I am also looking for help with setting the report path programmatically. I checked the Report Settings section of the article. Is your suggestion to add the date/time stamp to the run command using maven? I think what we are looking for is a way to automate this so that each run with be in a unique location using the System time for example, so that nothing has to be changed manually between runs.
Yeah passing the timestamp in the Maven command is the easiest. But i get the point that it is a pain. This will need an addition to the parsing code of the extent.properties file as currently it does not recognize any timestamp patterns. Have created an issue to track it – https://github.com/grasshopper7/extentreports-cucumber5-adapter/issues/12
Something like:
extent.reporter.html.out=test-output/Run_/test-results-report.html
Hi Mounish,
Quick update, was able figure it out to do it programmatically with something like:
…
reportsPath=”reports/new-extent/ExtentHtml”+currentDate+”.html”
System.setProperty(“extent.reporter.html.start”, “true”);
System.setProperty(“extent.reporter.html.config”, “configs/extent-config.xml”);
System.setProperty(“extent.reporter.html.out”, reportsPath);
…
similarly for the the other settings
Let me know your thoughts
U can do it this way. The issue u will face is when attachments are required for reports. For example if it is ‘test-output for all reports, the attachment files will be overwritten and only the latest ones available. Worse case if the order of test execution is changed, a wrong image will be displayed in the previous reports. So you will need to also modify the test-output property to make it unique for each test run. The other thing is that this value is fixed in the test code. Have opened an issue here so that this can be set in the extent.properties itself – https://github.com/grasshopper7/extentreports-cucumber5-adapter/issues/12. Will try to get this done in a couple of days.
Hey please help with this I am not able to resolve this issue
Currentyly i am using adapater 5 plugin
below is this error when i run test using maven command :
io.cucumber.core.exception.CucumberException: java.lang.NoClassDefFoundError: com/aventstack/extentreports/reporter/ConfigurableReporter
Caused by: java.lang.NoClassDefFoundError: com/aventstack/extentreports/reporter/ConfigurableReporter
Caused by: java.lang.ClassNotFoundException: com.aventstack.extentreports.reporter.ConfigurableReporter
extent.properties file :
extent.reporter.html.start=true
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
extent.reporter.html.config=src/test/resources/extent-config.xml
POM File :
tech.grasshopper
extentreports-cucumber5-adapter
1.3.2
test
com.vimalselvam
cucumber-extentsreport
3.0.2
com.aventstack
extentreports
3.1.1
org.freemarker
freemarker
2.3.30
Are u using maven? No need to include com.vimalselvam.cucumber-extentsreport at all. The com.aventstack.extentreports and the freemarker jars will be included as transitive dependencies if u r using maven etc. Just include the extentreports-cucumber5-adapter jar. Refer to this pom – https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/master/cuke5-extent-adapter-report/pom.xml. Note that the adapter version in the POM is old, use the latest one.
Hey! I am able to generate both the reports but facing issue with adding screenshot. I am using Selenium with Cucumber and currently have added just the plugin in Test Runner Class so every time I Run through Runner Class it will generate both reports. Need your help on how to attach screenshots in the report.
What kind of issue are you facing? How are u adding the screenshots, using scenario.embed() in cucumber code?
Yes tried that but didn’t work. Unfortunately can’t publish the code online for your reference. Can you please help with a sample code snippet which can be used in the Step Definition file
Can u try with version 1.3.1. I had made some changes in screenshot code in latest release. Which report are u generating? Just add a snippet of the relevant code, remove all other details. Can u check if the image is being created in the folder. Check if u have setup the screenshot.dir and screenshot.rel.path variable in extent.properties.
Example of screenshot addition – https://github.com/grasshopper7/extentreports-cucumber5-adapter/blob/f24ebb7515b8f545693ed16016e4efd54b0ce41e/extentreports-cucumber5-adapter/src/test/java/cucumber/examples/java/calculator/ScreenShotStepDefinition.java#L37
Thank you so much for your help! Now I am able to embed screenshots in both the reports by using the @AfterStep in Step Definition File. Will it be possible to capture screenshot and embed the same inside let’s suppose given method or when method ? The @Afterstep is working for me but since this executes after every step in the scenario I don’t want that and want the code to add screenshot in report for only two steps out of 6 steps in my cucumber scenario.
Yes, it can be done easily. You just need to store the Scenario object in the step definition class. Use the Before hook and pass the Scenario object as single parameter. Cucumber will inject the scenario object. Use this scenario object anywhere to embed screenshots
Will it be possible to send a sample piece of code for the same. I am trying but unable to implement the same. I have actually just started with Java and Cucumber that’s why such issue. Sorry for troubling you so much 🙁
private Scenario scenario
@Before <--- cucumber import for this public void before(Scenario scen) { scenario = scen; } @Given public void given() { scenario.embed(......); }
Thanks a lot Man! You are a life saver! Really appreciate your help. I was able to call the scenario.embed anywhere in the Step Definition File. One small question:
My StepDefinitionFile extends another class file “testDriver” which has various generic method. Can I call this scenario.embed in the testDriver class?
U can call it anywhere, but u should ideally use this in the step definition classes. Else the testdriver will have responsibility that is not core to it. Extending a testDriver class for the stepdefinition, for just getting access to webdriver instance, is not a good design. They have nothing to do with each other. Though this is the pattern followed in majority of tutorials.
Thanks a ton Man! The reporting part is perfectly integrated and working well. Need one suggestion: Any way we can capture screenshot of the full page to embed in the report?
I do not understand. Screenshots are for the full screen when taken by selenium. Can u clarify?
I mean when selenium captures the screenshot, it captures whatever page is being displayed but at times the page is big and you need to scroll down from the current visible page to see contents appearing below. Is it possible to capture the entire page from header to footer and not just what is being displayed on the screen?
U can try this tool – https://github.com/pazone/ashot
RemoteTestNG] detected TestNG version 6.9.10
[TestNGContentHandler] [WARN] It is strongly recommended to add “” at the top of your file, otherwise TestNG may fail or not work as expected.
[TestNG] Running:
C:\Users\varun.garg\AppData\Local\Temp\testng-eclipse-1609892830\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeClass setUpClass
io.cucumber.core.exception.CucumberException: Couldn’t load plugin class: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter
at io.cucumber.core.options.PluginOption.loadClass(PluginOption.java:117)
at io.cucumber.core.options.PluginOption.parsePluginName(PluginOption.java:102)
at io.cucumber.core.options.PluginOption.parse(PluginOption.java:86)
at io.cucumber.core.options.RuntimeOptionsBuilder$ParsedPluginData.addPluginName(RuntimeOptionsBuilder.java:238)
at io.cucumber.core.options.RuntimeOptionsBuilder.addPluginName(RuntimeOptionsBuilder.java:62)
at io.cucumber.core.options.CucumberOptionsAnnotationParser.addPlugins(CucumberOptionsAnnotationParser.java:97)
at io.cucumber.core.options.CucumberOptionsAnnotationParser.parse(CucumberOptionsAnnotationParser.java:52)
at io.cucumber.testng.TestNGCucumberRunner.(TestNGCucumberRunner.java:79)
at io.cucumber.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at io.cucumber.core.options.PluginOption.loadClass(PluginOption.java:110)
… 32 more
===============================================
Default test
Tests run: 0, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 0, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.XMLReporter@436a4e4b: 12 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@5ad851c9: 4 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@6b419da: 20 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@258e2e41: 28 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@b62fe6d: 0 ms
“Caused by: java.lang.ClassNotFoundException: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter” — Check if the correct adapter version 5 dependency is available. Maybe u should try the setup with a new clean basic project first.
I have setup the project by using cucumber version 5.5.0 as mentioned in this repo https://github.com/grasshopper7/extentreports-cucumber5-adapter
Thank you for putting up this dependency. I am using the below dependency.
tech.grasshopper
extentreports-cucumber5-adapter
1.3.1
test
Both HTML and Spark reports are getting generated but issue screenshots are not available in either of them. However I can see .png images in /test-output/.
Can you help me out in this?
Do u have the screenshot key-value pairs in extent.properties? Let me check this out and will update here. Thanks
Can u try to check out the latest code and try it – https://github.com/grasshopper7/extentreports-cucumber5-adapter. Would appreciate your feedback as code was working for me earlier also. There was a bug in the adapter code related to the screenshot key-value pair.
Hi Mounish,
I upgraded the version to 1.4.0.
But still I cannot see screenshot in the report. I prefer to see them in Spark report as it is much cleaner.
Also I have noticed that previous screenshots are not getting deleted is it possible to fix this.
Here is my extent.properties:
extent.reporter.html.start=true
extent.reporter.logger.start=false
extent.reporter.spark.start=true
extent.reporter.html.config=src/test/resources/extent-config.xml
extent.reporter.logger.config=src/test/resources/extent-config.xml
extent.reporter.spark.config=src/test/resources/extent-config.xml
extent.reporter.html.out=test-output/extent/HtmlReport/ExtentHtml.html
extent.reporter.logger.out=test-output/extent/Logger
extent.reporter.spark.out=test-output/extent/Spark
screenshot.dir=test-output/
screenshot.rel.path=../
entent-config.xml
default
UTF-8
http
Extent
Grasshopper Report
bottom
The settings of the ‘out’ property or the screenshot properties need to be changed. Easiest would be to remove the extent part from the ‘out’ properties and screenshots should start displaying. eg. extent.reporter.spark.out=test-output/Spark. Or u could try changing the ‘screenshot.rel.path’ property to ‘../../’. Refer to the sample POM at this location – https://github.com/grasshopper7/cuke5-extent-adapter-report/blob/master/cuke5-extent-adapter-report/src/test/resources/extent.properties.
The image files are not deleted but are modified with new contents if they exist.
Thank you Mounish for quick reply. I did above changes still screenshots are not coming in Sparks – Index.tml report.
In DOM I can see now the image path is correct as compared to earlier one.
I have observed there is a div inside which I can where all src and image paths are metioned but its style display is set to “none”.
Is it something due to this thing is not working?
Modified extent.properties:
extent.reporter.html.start=true
extent.reporter.logger.start=false
extent.reporter.spark.start=true
extent.reporter.html.config=src/test/resources/extent-config.xml
extent.reporter.logger.config=src/test/resources/extent-config.xml
extent.reporter.spark.config=src/test/resources/extent-config.xml
extent.reporter.html.out=test-output/extent/HtmlReport/ExtentHtml.html
extent.reporter.logger.out=test-output/Logger
extent.reporter.spark.out=test-output/Spark
screenshot.dir=test-output/
screenshot.rel.path=../../
if u change the spark.out to ‘test-output/Spark’, use the previous setting of ‘screenshot.rel.path’ which was ‘../’. In my previous comment u needed to change one of the settings not both. Just copy the extent.properties from the sample implementation.
I think the issue is different. I have changed the file as you suggested.
In browser console I can see errors which says “Not allowed to load resources”.
Any idea how to fix this?
Extent report:
extent.reporter.html.start=true
extent.reporter.logger.start=true
extent.reporter.spark.start=true
extent.reporter.json.start=true
extent.reporter.html.config=src/test/resources/extent-config.xml
extent.reporter.logger.config=src/test/resources/extent-config.xml
extent.reporter.spark.config=src/test/resources/extent-config.xml
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
extent.reporter.logger.out=test-output/Logger
extent.reporter.spark.out=test-output/Spark
extent.reporter.json.out=test-output/JsonReport/ExtentJson.json
screenshot.dir=test-output/
screenshot.rel.path=../
How are u accessing the report? Locally or through a server setup?
Issue got resolved. Many thanks to you for helping me.
I was opening report through my IntelliJ idea and it was opening as localhost at the start.
But when opened directly from the folder I am able to see images in screenshot.
Is there something we need to fix as many times we open reports directly from our IDE?
U can try posting the query on stackoverflow under intellij topic. Intellij support folks monitor the queue and sort out queries.
Reports are not getting generated. Test case is running but report.html file generated under test-output folder using extent.properties info
Are u getting any error in the console? U are saying reports not generated but u have a report.html in the folder. I am unable to understand. Can u share your code or create a public repository with the relevant code? Thanks.
Sorry, by mistake ‘not’ was not added.
Situation is I am to run the runner file with the setup of cucumber 5 extent adapter and it’s running end 2 end without any error in console. I am using extent properties and extent-config.xml file as well but report.html file is not generated. under the given path. Overall test is running fine but report is not generated in any folder.
The only thing i can think of is that maybe the start key of the reporter is set to false in the extent.properties. For example, extent.reporter.spark.start=true.
it is set to true, also extent.reporter.html.start=true. Still report is not getting generated and no error is throwing.
Please assist asap
Hi Mounish.. I am trying to include the extentReports cucumber 5 adapter dependency in POM file and getting the dependency not found error.. I have included other required dependencies as well. i have no clue why i am getting this error. can you please reply me back.. thanks
I think the mistake is in the groupid of the dependency. Make sure you are using this groupid – “tech.grasshopper”. If this does not fix the error, do add the dependency u r using. thx
Thank you for your reply.. error got resolved now
io.cucumber.core.exception.CucumberException: java.lang.NoSuchFieldError: VERSION_2_3_29
at io.cucumber.core.plugin.PluginFactory.newInstance(PluginFactory.java:85)
at io.cucumber.core.plugin.PluginFactory.instantiate(PluginFactory.java:68)
at io.cucumber.core.plugin.PluginFactory.create(PluginFactory.java:55)
at io.cucumber.core.plugin.Plugins.createPlugins(Plugins.java:48)
at io.cucumber.core.plugin.Plugins.(Plugins.java:25)
at io.cucumber.junit.Cucumber.(Cucumber.java:159)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NoSuchFieldError: VERSION_2_3_29
at com.aventstack.extentreports.reporter.BasicFileReporter.start(BasicFileReporter.java:98)
at com.aventstack.extentreports.ReportObservable.register(ReportObservable.java:192)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
at com.aventstack.extentreports.ExtentReports.attachReporter(ExtentReports.java:82)
at com.aventstack.extentreports.service.ExtentService$ExtentReportsLoader.attach(ExtentService.java:254)
at com.aventstack.extentreports.service.ExtentService$ExtentReportsLoader.initHtml(ExtentService.java:213)
at com.aventstack.extentreports.service.ExtentService$ExtentReportsLoader.createViaProperties(ExtentService.java:128)
at com.aventstack.extentreports.service.ExtentService$ExtentReportsLoader.(ExtentService.java:98)
at com.aventstack.extentreports.service.ExtentService.getInstance(ExtentService.java:30)
at com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.(ExtentCucumberAdapter.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at io.cucumber.core.plugin.PluginFactory.newInstance(PluginFactory.java:81)
… 22 more
Do u have freemarker-2.3.29.jar dependency included in the project? Maybe u have the wrong version
No, I am using Maven project and there is no free maker dependency I am using
Freemarker is used internally by extentreports. Check this – https://github.com/extent-framework/extentreports-java/blob/ca7b138bc2879a9c9c46a42412df0305f7048180/src/main/java/com/aventstack/extentreports/templating/TemplateConfig.java#L8. Maven should automatically include the freemarker jar into your classpath.
Any idea how to exclude freemaker from extent report in pom to resolve this versioning issue. Any solutions from your end.
This is required by extentreports jar internally to generate reports and is essential. You could raise an issue with extent repository – https://github.com/extent-framework/extentreports-java.
I tried to attach screenshot using embed. But it is not attached to the report.
With which report? html, logger or spark?
With HTML report I tried
I just tested it out with version 1.2.0 and got the screenshots for all 3 reports. Can you add the relevant code? Else try with the spark report which is similar to html report. Html report is anyway deprecated.
Thanks for your quick reply Mounish. Now I am able to attach screenshot to HTML Report. One more doubt I had is if we open dashboard in HTML Report, we will have three sections namely Features, Scenarios, Steps. In Steps sections, we are having number of Steps passed, scenarios failed, skipped and other. It should display as “Steps failed” instead of “Scenarios failed” right?
You are correct. This is a known issue even in version 4 adapter. This needs to be fixed in the Freemaker template of the Html report in the extentreport source and not in the adapter code. But as the Html report is deprecated the author of extentreport may have decided not to fix it. U should consider using the Spark report as Html report could be removed in future extentreports version. Spark is pretty much the same as Html report. Hope this helps you.
Hello,
Thanks for your contribution.
I am getting this error while I use cucumber5 extent adapter. Could you please help me?
java.lang.ClassCastException: com.aventstack.extentreports.reporter.ExtentHtmlReporter incompatible with com.aventstack.extentreports.reporter.ExtentSparkReporter
Are u getting any other details in the stacktrace like location, class etc? DO u have a sample public repository i can look up? Thx
I was thinking I could use them directly in context of cucumber adapter.
Adding systeminfo should be doable. Can u add this is as an issue in github https://github.com/grasshopper7/extentreports-cucumber5-adapter? Will look into it. Thanks
Thank you very much Mounish and Anshoo for the great support to community.
Can I request little bit more details on System Info and AutherName etc.
I saw Anshoo’s comment that ExtentService can be used for the same, however a simple example would be great help.
Regards,
Deepak Arora
U can refer to this for details about using these – https://extentreports.com/docs/versions/4/java/#current-version. Or are u looking for ways to use them in the context of cucumber adapter?
Hi Mounish.
Thank you for your contributions. Can you please publish this adapter under your owned groupID? I will point to your artifact giving full credit for your work from the official page so the community has access.
Hi… I will upload the artifact and inform you. Thanks
Hi,
The artifact is available here – https://mvnrepository.com/artifact/tech.grasshopper/extentreports-cucumber5-adapter.
Thank you. I have updated the repository here:
https://github.com/extent-framework/extentreports-cucumber5-adapter
Cheers!
Maven Dependency error, Cucumber 5 adapter is not available there yet
As I have mentioned in the post this is not an official implementation jar so I cannot upload it to third party repository.. U will need to download the jar from this location https://github.com/grasshopper7/extentreports-cucumber5-adapter/blob/master/extentreports-cucumber5-adapter/extentreports-cucumber5-adapter.jar and use the command mentioned in the plugin installation.
This jar does not exist
Not sure what the maven dependency declaration you are using but here is the jar location – https://mvnrepository.com/artifact/tech.grasshopper/extentreports-cucumber5-adapter/1.0.0. U cld copy the dependency information from the same location