0
votes

How can I add timestamps to the HTML report for the test run start/end and for scenario start/end in Cucumber-JVM?

Is there a Cucumber option I can add to RunWith JUnit runner?

2
Scenario start\end times can be added in after and before hooks. Pass in the scenario object and use write(text) method. This will be reflected in the report with the WriteEvent callback. For test start\end u will need to modify the HTMLFOrmatter code and add as a custom plugin. Register the TestStartEvent and TestFinishEvent if required and get the timestamp in the callback methods. event.getTimeStamp(). - Grasshopper
Thanks, I figured out something like this in the mean time. - Mate Mrše

2 Answers

2
votes

It's simple!!!!!!

Don't mention any folder path in plugin com.cucumber.listener.ExtentCucumberFormatter.

Example :

plugin= { "pretty", "html:FeaturesReport", "html:target/site/cucumber-pretty", "json:target/cucumber.json",

      "com.cucumber.listener.ExtentCucumberFormatter:",

},
  1. Run project and refresh it.
  2. check report will generate in default folder output/Run_with system time/report.html

If you want to generate a report in a specified path with a timestamp

just follow the below steps.

  1. goto maven dependencies.

  2. search cucumber-extentsreport.jar

  3. extend jar and select com.cucumber.listener package

  4. copy entire code in ExtentProperties class

  5. right on package and create new enum with name of ExtentProperties

  6. then paste ExtentProperties class code in the created enum.

  7. search below method

ExtentProperties() { 
    this.reportPath = "output" + File.separator + "Run_" + System.currentTimeMillis() +File.separator+ "report.html"; 
    this.projectName = "default"; 
}

8.And Replace With below code

String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

String userDir =System.getProperty("user.dir");

ExtentProperties()

{

    this.reportPath = "Extent_Reports" + File.separator + "" + 
    timeStamp.replace(":","").replace(".","_") + File.separator + "Execution 
report.html"; 
    this.projectName = "default";

}
  1. Run the project then refresh the project.

10.check report will generate in specified path with the name.

Extent_Reports/_2020_06_16_19_14_07/Execution report.html

Please comment if you have any questions

1
votes

Work with latest cucumber version, you can get start timestamp of each scenario in json report as below:

"elements": [
  {
    "start_timestamp": "2019-11-18T11:06:15.606Z",
  ....
  }