Cucumber Extent Report 

Cucumber Extent Report produces awesome reports with test logs and better visual graphics. It is named a Cucumber Extent Reporter.

 

Steps to add Cucumber Extent Report

Step 1: Add Cucumber Extent Reporter dependency to Maven Project

<!-- https://mvnrepository.com/artifact/com.vimalselvam/cucumber-extentsreport -->

<dependency>

    <groupId>com.vimalselvam</groupId>

    <artifactId>cucumber-extentsreport</artifactId>

    <version>3.1.1</version>

</dependency>

 

Step 2: Create an extent config to the project

Extent Config file will be used by the Cucumber Extent Report plugin to read the report configuration. Create extent-config.xml file and set various factors like :

Report Theme: It will set the theme of the report. It can be standard or dark. It is set by <theme>

Document Encoding: <encoding> : UFT-8

Title of the Report: This will display the title of the document on the Browser Tab. It is set by <documentTitle>

Name of the Report: This will display at the top of the Report. It is set by <reportName>

Global Date Format: It sets the date in yyyy-MM-dd. Format. It is set by <dateFormat>

Global Time Format: It sets the time in Like this HH:mm:ss. It is set by <timeFormat>


<?xml version="1.0" encoding="UTF-8"?>

<extentreports>

  <configuration>

    <!-- report theme --> <!-- standard, dark -->

    <theme>standard</theme>


    <!-- document encoding -->  <!-- defaults to UTF-8 -->

    <encoding>UTF-8</encoding>


    <!-- protocol for script and stylesheets -->   <!-- defaults to https -->

    <protocol>https</protocol>


    <!-- title of the document -->

    <documentTitle>TEQuality - Cucumber Test Report</documentTitle>


    <!-- report name - displayed at top-nav -->

    <reportName> TEQuality - Cucumber Report</reportName>


    <!-- global date format override -->  <!-- defaults to yyyy-MM-dd -->

    <dateFormat>yyyy-MM-dd</dateFormat>


    <!-- global time format override -->   <!-- defaults to HH:mm:ss -->

    <timeFormat>HH:mm:ss</timeFormat>


    <!-- custom javascript -->

    <scripts>

      <![CDATA[

        $(document).ready(function() {
    

        });

      ]]>

    </scripts>


    <!-- custom styles -->

    <styles>

      <![CDATA[
    

      ]]>

    </styles>

  </configuration>

</extentreports>

 

Step 3: Make an entry for the Path of the config in the Configuration.properties file.

reportConfigPath=/Users/cucumber/BDD/extent-config.xml

 

Step 4: Create a class ConfigFileReader which will read the configuration property

import java.io.IOException;

import java.io.InputStream;

import java.util.Properties;


public class ConfigFileReader {

public String getReportConfigPath(){

    Properties prop = new Properties();

    InputStream input = null;

    try

    {

        prop.load(getClass().getClassLoader().getResourceAsStream("/Users/path/to/the/PropertyFiles/Configuration.properties"));

        String reportConfigPath = prop.getProperty("reportConfigPath");

        if(reportConfigPath!= null) return reportConfigPath;

        else throw new RuntimeException("Report Config Path not specified in the Configuration.properties file for the Key:reportConfigPath");       

    }

    catch (IOException io) {

        io.printStackTrace();

    }finally {

        if (input != null) {

            try {

                input.close();

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

    }   

   return null;
}

}

Step 5: Modify the Test Runner to implement Extent Report

import java.io.File;


import java.io.IOException;

import java.text.SimpleDateFormat;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

import java.util.Date;

import org.apache.commons.io.FileUtils;

import org.junit.AfterClass;

import org.junit.BeforeClass;

import org.junit.runner.RunWith;

import com.cucumber.listener.ExtentProperties;

import com.cucumber.listener.Reporter;

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)

@CucumberOptions(

plugin = {"com.cucumber.listener.ExtentCucumberFormatter:"},       

features = {"/Users/cucumber/BDD/feature"},

tags= {"@SmokeTest"},

monochrome = true

 )

public class Runner {


    @BeforeClass

    public static void setup() {

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

        ExtentProperties extentProperties = ExtentProperties.INSTANCE;

        extentProperties.setReportPath("cucumber-reports/"+timeStamp.replace(":","_").replace(".","_")+".html");

    }


    @AfterClass

    public static void writeExtentReport() {


                   Reporter.loadXMLConfig(new File("/Users/cucumber/BDD/extent-config.xml"));

                   Reporter.setSystemInfo("User Name", System.getProperty("user.name"));

                    Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone"));

                    Reporter.setSystemInfo("Machine", "Windows 10" + "64 Bit");

                    Reporter.setSystemInfo("Selenium", "3.7.0");

                    Reporter.setSystemInfo("Maven", "3.5.2");

                    Reporter.setSystemInfo("Java Version", "1.8.0_151");     
             }

    }

Step 6: Right Click on TestRunner class and Click Run As  >> JUnit Test.