0
0
Selenium Javatesting~8 mins

Page title and URL retrieval in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Page title and URL retrieval
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── pages/
                │   └── HomePage.java
                ├── tests/
                │   └── HomePageTest.java
                ├── utils/
                │   └── WebDriverFactory.java
                └── config/
                    └── TestConfig.java
  
Test Framework Layers
  • Driver Layer: Manages WebDriver setup and teardown (e.g., WebDriverFactory.java).
  • Page Objects: Classes representing web pages with methods to retrieve title and URL (e.g., HomePage.java).
  • Tests: Test classes that use page objects to verify page title and URL (e.g., HomePageTest.java).
  • Utilities: Helper classes for common functions like waits or logging.
  • Configuration: Holds environment settings, browser types, and credentials (e.g., TestConfig.java).
Configuration Patterns

Use a TestConfig.java class or test.properties file to manage:

  • Base URLs for different environments (dev, staging, production).
  • Browser types (Chrome, Firefox) to run tests on.
  • Timeouts and wait durations.

Example snippet in TestConfig.java:

public class TestConfig {
    public static final String BASE_URL = "https://example.com";
    public static final String BROWSER = "chrome";
    public static final int TIMEOUT_SECONDS = 10;
}
Test Reporting and CI/CD Integration
  • Use TestNG or JUnit reports to show test pass/fail results.
  • Integrate with CI tools like Jenkins or GitHub Actions to run tests automatically on code changes.
  • Generate HTML or XML reports for easy review.
  • Include screenshots on failure for debugging.
Best Practices
  • Use Page Object Model: Keep page title and URL retrieval methods inside page classes.
  • Explicit Waits: Wait for page load before retrieving title or URL to avoid flaky tests.
  • Centralize Configuration: Manage URLs and browser settings in one place for easy updates.
  • Clear Test Assertions: Assert expected title and URL with meaningful messages.
  • Clean Driver Management: Properly open and close browser sessions in setup and teardown methods.
Self Check

Where would you add a new method to retrieve the page URL for the Login page in this framework structure?

Key Result
Organize tests using Page Object Model with clear layers for driver, pages, tests, utilities, and config to retrieve page title and URL reliably.