0
0
Selenium Javatesting~8 mins

Base page class pattern in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Base page class pattern
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── base/
                │   └── BasePage.java
                ├── pages/
                │   ├── LoginPage.java
                │   └── HomePage.java
                ├── tests/
                │   ├── LoginTest.java
                │   └── HomeTest.java
                └── utils/
                    ├── DriverFactory.java
                    └── WaitUtils.java
Test Framework Layers
  • Base Layer: BasePage.java contains common methods like click, type, wait, and driver management. All page classes extend this.
  • Page Objects: Classes like LoginPage.java and HomePage.java represent web pages. They use locators and methods specific to each page.
  • Tests: Test classes like LoginTest.java contain test methods that use page objects to perform actions and assertions.
  • Utilities: Helper classes like DriverFactory.java manage WebDriver setup and teardown. WaitUtils.java provides explicit wait methods.
Configuration Patterns
  • Use config.properties file to store environment URLs, browser types, and credentials.
  • DriverFactory reads config to initialize WebDriver for Chrome, Firefox, etc.
  • Use Java system properties or Maven profiles to switch environments (dev, test, prod) at runtime.
  • Keep sensitive data like passwords encrypted or use environment variables.
Test Reporting and CI/CD Integration
  • Integrate TestNG reports for detailed test execution results.
  • Use Allure or ExtentReports for rich HTML reports with screenshots on failure.
  • Configure CI tools like Jenkins or GitHub Actions to run tests on code push.
  • Publish reports as build artifacts and notify team via email or chat.
Best Practices for Base Page Class Pattern
  • Single Responsibility: BasePage should only have common reusable methods, not page-specific logic.
  • Use Explicit Waits: Include wait methods in BasePage to avoid flaky tests.
  • Encapsulation: Keep locators private in page classes and expose only meaningful actions.
  • Inheritance: All page classes extend BasePage to reuse code and maintain consistency.
  • Driver Management: BasePage holds WebDriver instance passed from test or driver factory.
Self Check

Where would you add a new page object class for the "Profile" page in this framework structure?

Key Result
Use a BasePage class to hold common web page methods and have all page objects extend it for code reuse and maintainability.