0
0
Selenium Javatesting~8 mins

Extent report customization in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Extent report customization
Folder Structure
selenium-java-project/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/example/app/
│   │           └── (application code)
│   └── test/
│       └── java/
│           └── com/example/tests/
│               ├── base/
│               │   └── BaseTest.java          # Base test class with setup/teardown
│               ├── pages/
│               │   └── LoginPage.java         # Page Object classes
│               ├── tests/
│               │   └── LoginTest.java         # Test classes
│               ├── utils/
│               │   ├── ExtentManager.java     # ExtentReports setup and customization
│               │   ├── ConfigReader.java      # Reads config properties
│               │   └── WebDriverFactory.java  # WebDriver setup
│               └── listeners/
│                   └── TestListener.java     # Listens to test events for reporting
└── test-output/
    └── extent-reports/                        # Generated Extent report files
Test Framework Layers
  • Driver Layer: WebDriverFactory.java manages browser drivers and sessions.
  • Page Objects: Classes like LoginPage.java encapsulate UI elements and actions.
  • Test Layer: Test classes (e.g., LoginTest.java) contain test methods using page objects.
  • Utilities:
    • ExtentManager.java configures and customizes ExtentReports (themes, system info, report path).
    • ConfigReader.java loads environment variables and credentials.
    • WebDriverFactory.java initializes WebDriver instances.
    • TestListener.java hooks into test lifecycle events to log results to ExtentReports.
  • Configuration: Properties files and ConfigReader.java manage environment and browser settings.
Configuration Patterns
  • Environment Properties: Use config.properties to store URLs, credentials, and browser types.
  • Dynamic Report Path: ExtentManager.java creates timestamped report folders under test-output/extent-reports/ for uniqueness.
  • Report Customization: Set report theme (dark/light), document title, and system info (OS, tester name) in ExtentManager.java.
  • Listener Integration: TestListener.java automatically logs test start, pass, fail, and skip events to ExtentReports.
  • Browser Selection: ConfigReader.java reads browser choice from properties to initialize correct WebDriver.
Test Reporting and CI/CD Integration
  • ExtentReports Output: Generates interactive HTML reports with detailed logs, screenshots, and test status.
  • Screenshot Capture: On test failure, TestListener.java captures screenshots and attaches them to the report.
  • CI/CD Integration: Configure Jenkins or GitHub Actions to run tests and archive ExtentReports from test-output/extent-reports/.
  • Report Archiving: Store reports as build artifacts for historical test result tracking.
  • Notification: Optionally send report links or summaries via email or chat after CI runs.
Best Practices for Extent Report Customization
  1. Centralize Report Setup: Use a single ExtentManager class to configure and provide the ExtentReports instance.
  2. Use Listeners: Implement TestNG listeners to automatically log test events without cluttering test code.
  3. Include Screenshots: Attach screenshots on failures to help diagnose issues quickly.
  4. Customize Report Appearance: Set themes, titles, and system info to make reports clear and professional.
  5. Keep Reports Organized: Use timestamped folders to avoid overwriting and to keep history of test runs.
Self Check

Where in this folder structure would you add a new method to capture and attach screenshots to the Extent report on test failure?

Key Result
Use a centralized ExtentManager and TestNG listeners to customize and generate detailed ExtentReports with screenshots and environment info.