0
0
Selenium Javatesting~10 mins

Extent report customization in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page, performs a simple check, and logs the test steps and results using a customized Extent Report. It verifies that the page title matches the expected value and records the outcome in the report.

Test Code - TestNG with Selenium and ExtentReports
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentReportCustomizationTest {
    WebDriver driver;
    ExtentReports extent;
    ExtentTest test;

    @BeforeClass
    public void setup() {
        // Setup ExtentReports with custom configuration
        ExtentSparkReporter spark = new ExtentSparkReporter("extent-custom-report.html");
        spark.config().setDocumentTitle("Custom Test Report");
        spark.config().setReportName("Login Page Tests");
        spark.config().setTheme(Theme.DARK);

        extent = new ExtentReports();
        extent.attachReporter(spark);

        // Setup WebDriver
        driver = new ChromeDriver();
    }

    @Test
    public void verifyPageTitle() {
        test = extent.createTest("Verify Page Title");
        test.info("Navigating to example.com");
        driver.get("https://example.com");

        String title = driver.getTitle();
        test.info("Page title retrieved: " + title);

        Assert.assertEquals(title, "Example Domain");
        test.pass("Page title is as expected.");
    }

    @AfterClass
    public void teardown() {
        driver.quit();
        extent.flush();
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Initialize ExtentReports with custom title, report name, and dark themeExtentReports ready to log test steps with customized settings-PASS
2Launch Chrome browser using Selenium WebDriverChrome browser window opened and ready-PASS
3Create a new test entry in ExtentReports named 'Verify Page Title'Test log initialized for this test case-PASS
4Navigate browser to 'https://example.com'Browser displays the Example Domain page-PASS
5Retrieve the page title from the browserPage title is 'Example Domain'Verify page title equals 'Example Domain'PASS
6Log success message in ExtentReports for title verificationTest log updated with pass status-PASS
7Close the browser and flush ExtentReports to write the report fileBrowser closed, report file 'extent-custom-report.html' generated with custom settings-PASS
Failure Scenario
Failing Condition: Page title does not match 'Example Domain'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify on the web page?
AThe page contains a login form
BThe page URL is 'https://google.com'
CThe page title matches 'Example Domain'
DThe page background color is dark
Key Result
Customizing the Extent Report with meaningful titles and themes improves report readability and helps stakeholders quickly understand test results.