How to Add Logs in Cucumber Extent Report

Profile picture for user devraj

This article will discuss how to generate logs for the cucumber extent report we generated earlier using the grasshopper plugin. You can generate the logs using the scenario instance or using the ExtentCucumberAdapter class.

Table of Content

  1. Generate logs using scenario instance
  2. Generate logs using ExtentCucumberAdapter addTestStepLog() method
  3. Generate logs using ExtentCucumberAdapter log() method
  4. Video Tutorial

Generate logs using scenario instance

You can use the log() method to output text into the report. This method only accepts a string, unlike the extent adapter, which provides several parameters.

Generate logs using ExtentCucumberAdapter addTestStepLog() method

This method is similar to scenario.log() method, which accepts only string.

ExtentCucumberAdapter.addTestStepLog("Log added using Add Test Step Log");

Generate logs using ExtentCucumberAdapter logs() method

With the Extent Cucumber Adapter logs() method, you can use different extent statuses like Pass, Fail, and Skip. Also, you can attach a screenshot and use other markups.

1. Info

ExtentCucumberAdapter.getCurrentStep().log(Status.INFO, "Test INFO");

2. Warning

ExtentCucumberAdapter.getCurrentStep().log(Status.WARNING, "Test WARNING");

3. Skip

ExtentCucumberAdapter.getCurrentStep().log(Status.SKIP, "Test SKIPPED");

4. Pass

ExtentCucumberAdapter.getCurrentStep().log(Status.PASS, "Test PASS");

5. Fail

ExtentCucumberAdapter.getCurrentStep().log(Status.FAIL, "Test Fail");

6. Using Markup

ExtentCucumberAdapter.getCurrentStep().log(Status.INFO, MarkupHelper.createLabel("My Label", ExtentColor.RED));

7. Screenshot

ExtentCucumberAdapter.getCurrentStep().log(Status.FAIL, MediaEntityBuilder.createScreenCaptureFromBase64String(getBase64Screenshot()).build());

For getBase64Screenshot() method refer How to add screenshot in cucumber extent report.

Video Tutorial: how to print logs in cucumber report