0
0
Selenium Javatesting~8 mins

WebDriver setup (ChromeDriver) in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - WebDriver setup (ChromeDriver)
Folder Structure
src/
 └── test/
      └── java/
           └── com/
                └── example/
                     ├── base/
                     │    └── WebDriverManager.java
                     ├── pages/
                     │    └── HomePage.java
                     ├── tests/
                     │    └── HomePageTest.java
                     └── utils/
                          └── ConfigReader.java

resources/
 └── config.properties

pom.xml
Test Framework Layers
  • Base Layer: Contains WebDriverManager class to initialize and manage the ChromeDriver instance.
  • Page Objects: Classes representing web pages, encapsulating locators and actions (e.g., HomePage).
  • Tests: Test classes that use page objects and WebDriver to perform test scenarios.
  • Utilities: Helper classes like ConfigReader to read configuration such as URLs and timeouts.
  • Resources: Configuration files like config.properties for environment settings.
Configuration Patterns
  • Use a config.properties file to store environment URLs, browser type, and timeouts.
  • ConfigReader utility reads these properties at runtime.
  • Browser selection: Currently fixed to ChromeDriver but can be extended for other browsers.
  • Driver setup: Use WebDriverManager library to manage ChromeDriver binaries automatically.
  • Environment handling: Use properties to switch between dev, test, or prod URLs without code changes.
Test Reporting and CI/CD Integration
  • Use TestNG framework for running tests and generating XML reports.
  • Integrate with CI tools like Jenkins or GitHub Actions to run tests on code commits.
  • Configure reports to show pass/fail status, screenshots on failure, and logs.
  • Store reports as artifacts in CI for easy access and historical tracking.
Best Practices
  • Use WebDriverManager: Avoid manual driver binary management by using io.github.bonigarcia WebDriverManager.
  • Encapsulate WebDriver setup: Keep driver initialization in a single class to avoid duplication and ease maintenance.
  • Use properties files: Externalize environment and browser settings for flexibility.
  • Close driver properly: Quit the driver after tests to free resources.
  • Use explicit waits: Avoid flaky tests by waiting for elements properly instead of fixed sleeps.
Self Check

Where in this folder structure would you add a new page object class for the Login page?

Key Result
Centralize ChromeDriver setup in a base class using WebDriverManager and externalize configs for flexible, maintainable Selenium tests.