selenium-webdriver HTML Reports ExtentReports


This example covers the implementation of ExtentReports in Selenium using TestNG, Java and Maven.

ExtentReports are available in two versions, community and commercial. For the ease and demonstration purpose, we will be using community version.

1. Dependency

Add the dependency in your Maven pom.xml file for extent reports.


2. Configure plugins

Configure the maven surefire plugin as below in pom.xml

    <defaultGoal>clean test</defaultGoal>

3. Sample test with ExtentReports

Now, create a test with name

public class TestBase {
    WebDriver driver;

    ExtentReports extent;
    ExtentTest logger;
    ExtentHtmlReporter htmlReporter;
    String htmlReportPath = "C:\\Screenshots/MyOwnReport.html"; //Path for the HTML report to be saved

    public void setup(){
        htmlReporter = new ExtentHtmlReporter(htmlReportPath);
        extent = new ExtentReports();

        System.setProperty("", "pathto/chromedriver.exe");
        driver = new ChromeDriver();

    public void test1(){
        logger.log(Status.INFO, "Opened site");
        assertEquals(driver.getTitle()), "Google");
        logger.log(Status.PASS, "Google site loaded");

    public void getResult(ITestResult result) throws Exception {
        if (result.getStatus() == ITestResult.FAILURE)
            logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " Test case FAILED due to below issues:", ExtentColor.RED));
        else if (result.getStatus() == ITestResult.SUCCESS)
            logger.log(Status.PASS, MarkupHelper.createLabel(result.getName() + " Test Case PASSED", ExtentColor.GREEN));
        else if (result.getStatus() == ITestResult.SKIP)
            logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " Test Case SKIPPED", ExtentColor.BLUE));

    public void testend() throws Exception {

    public void tearDown() throws Exception {