Extent Report in Selenium

Profile picture for user arilio666

Extent Reports is a popular reporting framework that can be used with Selenium to generate interactive and visually appealing reports of test execution results. 

It provides detailed information about the tests that have been executed, including test status, steps, and logs, making it easier for testers to identify and troubleshoot issues.

1.) Dependencies


     <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.1.5</version>
        </dependency>   
  • Add this XML to POM and install via maven.

2.) Extent Initiation

ExtentReports extent = new ExtentReports();
        ExtentHtmlReporter spark = new ExtentHtmlReporter("target/Sparkkk.html");
        extent.attachReporter(spark);
        extent.createTest("MyFirstTest").log(Status.PASS, "This is a logging event for MyFirstTest, and it passed!");
        extent.flush();
  • So this is how we can initiate the extent report.
  • This object will add test details such as test name, description, and status.
  • Using the ExtentHtmlReporter class, we set the target as a directory to store.
  • Then we attach the report using the attachReporter method.
  • Add logs and screenshots to the test using the ExtentTest object. This will provide additional information about the test execution and help to identify issues.
  • At the end of the test execution, call the ExtentReports object's flush() method to generate the report.

3.) Execution

package week4.day2;

import org.openqa. Selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Ext {
    ChromeDriver driver;
    ExtentReports extent;
    ExtentHtmlReporter extentRep;
    ExtentTest testCase;

    @Test
    private void verifyUrl() {
        testCase = extent.createTest("Print URL");
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();

        driver.get("http://programsbuzz.com/user/login");

        driver.manage().window().maximize();

        System.out.println("Current Page URL Is: " + driver.getCurrentUrl());

        String currentUrl = driver.getCurrentUrl();
        if (currentUrl.contains("login")) {

            testCase.log(Status.PASS, "Actual Title!");

        } else {
            testCase.log(Status.FAIL, "Not Actual Title!");

        }
    }

    @BeforeSuite
    private void extentLaunch() {
        extent = new ExtentReports();
        extentRep = new ExtentHtmlReporter("target/extHtml.html");
        extent.attachReporter(extentRep);
    }

    @AfterSuite
    private void finOper() {
        driver.quit();
        extent.flush();

    }

}
  • Here we are verifying the current URL of the programsbuzz page.
  • In the BeforeSuite, we initialize the extent report class and keep the variable static outside.
  • In AfterSuite, we flush the report.
  • In the Test hook, we used the reporter's logged facility and logged the current title to be truthful.
  • Else return failed scenario in the report.
  • We can see that the test has passed, which is what the report looks like.