Writing to Cucumber HTML reports

We can write to Cucumber HTML report using  write method of Scenario class.

Below step definition class illustrates how to write to HTML report. Note how we have passed scenario object to Before method.

package org.softpost;

import com.google.common.primitives.Bytes;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import junit.framework.Assert;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

 * Created by Sagar on 12-07-2016.
public class seleniumsteps {
    WebDriver driver;
    Scenario scenario;

    public void launchBrowser(Scenario scenario){
        driver = new FirefoxDriver();
       this.scenario = scenario;

    @Given("^I am on the www\\.softpost\\.org home page$")
    public void i_am_on_the_www_softpost_org_home_page() throws Throwable {
        scenario.write("Navigated to www.softpost.org");

    @Then("^I verify that title contains tutorials$")
    public void i_verify_that_title_contains_tutorials() throws Throwable {

    @Then("^I verify that title contains tutooorials$")
    public void i_verify_that_title_contains_tutooorials() throws Throwable {

    public void killBrowser(){
        scenario.write("Finished scenario");
        if (scenario.isFailed()) {
         scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");

Here is the sample HTML report.

Writing to cucumber HTML report

Writing to cucumber HTML report

You may also like...