Cucumber custom html report using Extent Report

This was the one long pending post that I wanted to share with you all. I would like to share my happiness that my first open source java library got published in Apache Maven to generate the custom report for Cucumber using Extent report.

My main goal was to create a custom report for the cucumber-jvm. But I don’t want to invest time in reinventing or developing htmls. I was searching for the library which can easily produce me the nice report with more details.

Then I found the ExtentReports authored by Anshoo Arora. There are many posts covering on how to use this library in your TestNG tests as a listener. However we always missed on how to use this in cucumber-jvm. Hence the cucumber-extentsreport library evolved. Let’s see the action part before you think I’m boring you.

I’ve created a new page for updates about this plugin. Kindly refer the page on how to use this library here: Cucumber Extent Reporter.

92 Replies to “Cucumber custom html report using Extent Report”

  1. hi Vimal,

    Great plugin..have been waiting for this. Just wanted to know if there is a possibility of taking screen shot and attaching it to step on failure, adding logging description of scenario and feature file and information on scenario.

    Please suggest if there is any method available to add these onto the report.

    Thanks and regards,
    Karthik

    1. Hey,

      Got it.. I just had to specify the scenario description and feature description after the” Fearture:” and “Scenario:”

  2. I am getting the below error:
    cucumber.runtime.CucumberException: Couldn’t load plugin class: com.cucumber.listener.ExtentCucumberFormatter

    1. Shami: Kindly provide me more information. The runner class would be more helpful to me. If possible, pom.xml also.

      1. I’m facing same problem as Shami above. Here is my runner class below:

        import java.io.File;

        import org.junit.BeforeClass;
        import org.junit.runner.RunWith;
        import com.cucumber.listener.ExtentCucumberFormatter;
        import cucumber.api.CucumberOptions;
        import cucumber.api.junit.Cucumber;

        @RunWith(Cucumber.class)
        @CucumberOptions(features={“src/features”},
        glue={“steps”},
        tags={“@sanity,@prod”},
        plugin = {“pretty”,”html:target/cucumber”, “com.cucumber.listner.ExtentCucumberFormatter”})
        public class RunCukes
        {

        @BeforeClass
        public static void setup() {
          ExtentCucumberFormatter.initiateExtentCucumberFormatter();
        
          ExtentCucumberFormatter.loadConfig(new File("src/extent-config.xml"));
        
          // User can add the system information as follows
          ExtentCucumberFormatter.addSystemInfo("Browser Name", "Firefox");
          ExtentCucumberFormatter.addSystemInfo("Browser version", "v49.0.2");
          ExtentCucumberFormatter.addSystemInfo("Selenium version", "v3.0.1");
        }
        

        }

          1. The runner class is shared in the example shown in this article. Kindly share your code for us to help you better.

  3. Hi Vimal,

    Thank you for the great plugin !!! I have encountered a problem with the plugin when ever Scneario Outline is used with Examples. Report is printing the steps from the last scenario steps. My scenario is given below

    Scenario Outline: Login to website
    Given User is on Login Page
    When User Enters “” in userName Textbox
    And User Enters “” in Password Textbox
    And User Select “” in Domain Combobox
    And User Clicks LoginButton
    Then Home Page is displayed

    Examples: 
      | UserName     | Password    | Domain  |
      | abc | def | ghk |
    

    Scenario: Click on Collabaration zone
    Given User is on Home Page
    When User clicks Collabaration zone
    Then Collabaration Zone Tab should be opened

    The report logs correctly for the first scenario. However for second scenario it is just repeating the steps for first scenario with values.

    Could you please help in resolving this.

    Regards,

  4. Hi Vimal,

    One more observation from my side. If the system on which test is being run is not connected to internet then the reporting format is not displayed.
    We work for bank and mostly on intranet. Is there any work around for this.

    Regards,

  5. hi Vimal,

    is there a way to modify the path of report generation?

    i need this as i have to configure the path of the report to jenkins worksspace so that the jenkins job can send mail with report

    thanks and regards,
    karthik

    1. Yes there is. It has been mentioned in the article itself. Use this to generate report at your desired location: @CucumberOptions(plugin = {“com.cucumber.listener.ExtentCucumberFormatter:output/report.html”}). This will generate report.html at output directory.

    2. Hi Karthik,

      Are you able to setup jenkins to pick up the report and send it through email, if yes can you please let me know how did you do that?

      Cheers
      Kishore

  6. Hi Vimal,

    Its working as expected. Thank you for extending it to cucumber. However i could see total tests count is incorrect when i executed scenarios.

    Tests view its showing 6 tests failed which is correct but total tests count is being shown as 12. Could you please let me know if there is any issue with plugin.

  7. Its my bad.. Showing only child tests is working as expected. One more question, in the categories sections it is counting feature name also as one test along with other tests that were failed. For now its not a priority for me as dashboard is showing correct results. However, please let me know in case am missing something here.

  8. Hey Vimal,

    Thanks for the awesome plugin. I am following your instructions on the readme to load the extent-config.xml in my run class

    (ExtentCucumberFormatter.loadConfig(new File(“your config xml file path”));)

    but it seems like the loadConfig is not available. Any idea on how to fix it?

    Thanks,
    Kyle

  9. Hi Vimal,

    Thanks for this wonderful report ,when I implemented this report using version 1.0.0 everything worked fine however when I used version 1.1.0 I got the below errors. Also, is there a way this report can be shared? so that other team members can see it because at the moment it sits on my local.

    java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:219)
    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 cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:290)
    at com.sun.proxy.$Proxy19.close(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.close(JUnitReporter.java:213)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

    Kind regards
    Akin

    1. Hello Vimal,

      Even I’m also facing the same issue. When i looked at the code i thought I might have to pass the systemInfo but even after that its the same issue. Any idea why this is happening?

      Regards
      Shashi

      1. Hi Vimal,
        Thanks for your excellent work. The problem “java.lang.NullPointerException
        at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:219)” seems to still persist despite all my consultation. Could you please shed more light on this because I am still struggling with it.
        Many thanks,
        Lawrence

      2. Vimal i am getting java.lang.NoSuchMethodError: com.relevantcodes.extentreports.ExtentReports.addSystemInfo(Ljava/util/Map;)Lcom/relevantcodes/extentreports/ExtentReports;
        at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:228)

        please help

  10. Hi Vimal,

    Thanks for the awesome plugin.
    I am facing issues in generating screenshots through jenkins, local machine screenshots are getting generated and is stored under output directory along with html report.
    Jenkins report is generated properly but without screenshot.
    workspace output directory of jenkins does not contain any screenshots.
    I have used html publisher plugin in jenkins.

    I am using @CucumberOptions(plugin = {“com.cucumber.listener.ExtentCucumberFormatter:output/report.html”}) for report generation and same After method which you have mentioned for generating screenshots (without any changes).

    Do you have any idea on this issue? waiting for your inputs.

    Regards,
    Shwetha

    1. Shwetha, are you facing the problem still. Let me know where are you with this issue now. I’ll try to help you.

  11. Even, I’m facing the following issue:

    java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:219)
    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 cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:290)
    at com.sun.proxy.$Proxy12.close(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.close(JUnitReporter.java:213)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Any idea how to resolve this?

    Thanks,
    Tanmoy

  12. Hi Vimal,

    Screenshots attachment worked properly without any issues. Mistake was from my end i had created jenkins job name with space so under workspace there was 2 folders created for reporting. After deleting the space in jenkins job name. Screenshots are working fine without issues.

    Plugin works both for linux and windows os.

    Regards,
    Shwetha Kulkarni

  13. Getting issues with the 1.1 jar file

    java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:219)
    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 cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:290)
    at com.sun.proxy.$Proxy12.close(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.close(JUnitReporter.java:213)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at

    Any solutions for this?

  14. Does this reporting work real-time to show the step it is executing or it needs completion of cucumber scenario, before report is generated

  15. Hi Vimal,
    Thanks for integrating cucumber to the extent reports. It works fine for me and generates the cool report. However, i have noticed that for some scenarios the ‘STEPNAME’ is not coming in the report. The details section is showing the status in the correct order however. But without the STEPNAME we wont know which step passed or failed. I am not able to debug the cause as i see scenarios with and without STEPNAME in the same report.

    I am using 1.1.0 version.

  16. Hey,

    First of all great thanks for this great post.

    I have one questio, I am working in a project where a multiple tests (using cuvucmber) are launched.
    I would like that the report.html generated will contains the result of all the test, but when I launch the test, the file is overwritte and only contains the information of the last test executed.

    I have tryed to edit the “ExtentCucumberFormatter.initiateExtentCucumberFormatter();” as a “ExtentCucumberFormatter.initiateExtentCucumberFormatter(file-path, false);” but it isnt working.

    Could you help me?

    Thanks in advance!

  17. Hi

    Is there any way to log the custom messages from Step Definitions into Extent Reports?

    Please help me if any one have solution for this.

    Thanks
    Prathap

  18. Hi Mukund,

    Thank you for your response.

    Actually right now we are using Cucumber HTML reports. Even this reports look and feel is very good. I tried writing custom messages using write(String) method it is working fine. But issue is when i use multiple write(String) methods in one Step Definition method in HTML reports those custom messages are displaying in single line. So obviously this is creating mess up in reports and i tried by passing (\n) expression also but still its unable to log that messages in line by line.

    Can you please look provide me solution how i can log custom messages in line by line instead of in single line.

    Thank you in Advance!!!!

    Regards,
    Prathap

  19. Hi Prathap,

    I have the same kind of scenario in my project, and I initialized my scenario in @Before hooks and used scenario.write(“line1”);
    scenario.write(“line2);

    this works absolutely fine for me.

    1. No Mukund, you can’t do that. The step result is being handled by cucumber and in the CucumberExtentReporter we just listen to the result object.

  20. Hi Regis,

    I tried using write methods as you suggested but those messages are logging in single in reports.

    For you how messages are logging in reports are they logging in line by line else logging in single line ?

  21. Hi Regis,

    Can please prove snap shot of your code how you have written to log messages line by line when we use multiple writers in single glue method.

  22. Hi Vimal,

    Whatever issue Vishnu and Duarte Ferreira is getting even am also getting it.

    Please help us to resolve this issue.

    1. Prathap, whatever the issue you are mentioning, I’m unable to receive from my end. Kindly raise an issue in github link provided and add the sample project for me to reproduce.

  23. Hi Vimal,

    I’m having issues with the Setup, I’ve copied all your Setup() Method’s Code, and ran the Script but I keep getting this Error message:
    java.lang.NoSuchMethodError: com.relevantcodes.extentreports.ExtentReports.(Ljava/lang/String;Ljava/lang/Boolean;Lcom/relevantcodes/extentreports/DisplayOrder;Lcom/relevantcodes/extentreports/NetworkMode;Ljava/util/Locale;)

    This error message is coming from this: ExtentCucumberFormatter.initiateExtentCucumberFormatter();

    I even added this: ExtentCucumberFormatter.initiateExtentCucumberFormatter(new File (“/Users/mbeaman/Desktop/Reports/CRM/cucumberReport.html”));

    and this: ExtentCucumberFormatter.initiateExtentCucumberFormatter(new File (“/Users/mbeaman/Desktop/Reports/CRM/cucumberReport.html”), null, null, null, null);

    and this: ExtentCucumberFormatter.initiateExtentCucumberFormatter(new File (“/Users/mbeaman/Desktop/Reports/CRM/cucumberReport.html”), false, “OLDEST_FIRST”, “OFFLINE”, null);

    but the same error message appears. Please help 🙂

          1. HI It is resolved now. I have used below dependencies.

            xml-apis
            xml-apis
            2.0.2

                <dependency>
                    <groupId>org.freemarker</groupId>
                    <artifactId>freemarker</artifactId>
                    <version>2.3.23</version>
                </dependency>
            

            Report looks very good and thanks for the cucumber integration with extent reports.

  24. Hi Vimal,

    Is there any way I can get test step in the report rather than attaching to every scenario, as our product team needs to verify every screenshots.

    By the way awesome work.

  25. Hi Vimal i have the reports
    @RunWith(Cucumber.class)
    @CucumberOptions(
    strict = false,
    features = “classpath:features”,
    plugin = {“com.cucumber.listener.ExtentCucumberFormatter”

    Is there any way i can add more comments or Logs in the Report other than just the Scenarion , Feature and Steps Name .

    I want to add some comment to the Test with in the Test and i want it to appear on the Report

    You help would be appreciated

    1. Hi Ivan,

      Currently there is no support for adding custom log message. I’ll add this in the next release. It would be great if you could log an issue in the github project for tracking purpose.

  26. Hi Vimal,
    First of all thanks for the cucumber extent integration….
    I am facing an issue with screenshot on scenario failure.My feature file contains multiple scenarios and thus in the teardown() method using @After i haven’t killed the browser driver.The problem is 3 screenshots are taken for the scenario failure.
    It would be great if you could point me out my mistake.

  27. Hi Vimal

    In my feature file every scenario corresponds to a separate test case. In the generated report, same count of test and steps is displayed.
    i want the count of test as the number of scenarios that are executed and not equal to the number of steps.
    And the the graph for steps shows some extra steps under info.
    can you please let me know what changes need to be done for this change to be reflected in report.

  28. Hi Vimal,

    There is some issue with the extent.css.Because of which test logs and screenshots are not getting displayed in the report,even though they are present.
    Could you please check this one ?

  29. Hi Vimal,
    Can you tell me, how to add more columns along with Test Step, Status,Details in extent report.
    I want to add some more columns in reports,is it possible ?

    1. Currently there is no direct way to add. I’ll include this feature in the upcoming release and update here.

  30. Screenshots are not embedded in the report using the command : Reporter.addScreenCaptureFromPath(“path”).

    The path is correct and the image exists at the location. The screenshots are saved in .png format and on debug all the functions for adding screenshot are traversed correctly without any exception.

    What can be the possible issue

    1. Mr. Tester, kindly log an issue in the github repo with the code sample for me to reproduce the issue. I’ll have a look and try to help you.

  31. Hi Vimal, In my project we are using java 1.6 and the cucumber extent plug in version 3.0.1 is require java 1.8. Is there a way to make it work in java 1.6 ? so that I can eliminate this java version dependency. – Prakash

  32. Hi Vimal,

    Thanks for the for the plugin it is awesome.

    The code in cucumber runner works fine but when I use a custom gradle task the plugin not able to read the extentConfig.xml file. It provides the extent report with default config.

    How can I make your plugin use the extentConfig.xml from the custom gradle task, below is the task which is running my tests.
    task testLocal(dependsOn: [‘testClasses’]) << {
    javaexec {
    systemProperties = System.properties
    main = “cucumber.api.cli.Main”
    classpath = sourceSets.test.runtimeClasspath
    jvmArgs = [“-Dfile.encoding=UTF-8”, “-Denv=local”]
    args = [‘–tags’, “@web”,
    ‘–plugin’, ‘junit:build/junit-test-report.xml’,
    ‘–plugin’, ‘pretty’,
    ‘–plugin’, ‘html:build/cucumber-html-report’,
    ‘–plugin’, ‘json:build/cucumber-report.json’,
    ‘–plugin’, ‘com.cucumber.listener.ExtentCucumberFormatter:masterdash-ui-test/build/extentreport.html’,
    ‘–glue’, ‘utils’,
    ‘–glue’, ‘context’,
    ‘–glue’, ‘stepDefs’,
    ‘–strict’,
    ‘src/test/resources’

        ]
    }
    

    }

Leave a Reply