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.
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.
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(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Initialize ExtentReports with custom title, report name, and dark theme | ExtentReports ready to log test steps with customized settings | - | PASS |
| 2 | Launch Chrome browser using Selenium WebDriver | Chrome browser window opened and ready | - | PASS |
| 3 | Create a new test entry in ExtentReports named 'Verify Page Title' | Test log initialized for this test case | - | PASS |
| 4 | Navigate browser to 'https://example.com' | Browser displays the Example Domain page | - | PASS |
| 5 | Retrieve the page title from the browser | Page title is 'Example Domain' | Verify page title equals 'Example Domain' | PASS |
| 6 | Log success message in ExtentReports for title verification | Test log updated with pass status | - | PASS |
| 7 | Close the browser and flush ExtentReports to write the report file | Browser closed, report file 'extent-custom-report.html' generated with custom settings | - | PASS |