0
0
Selenium Javatesting~8 mins

Docker Selenium Grid in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Docker Selenium Grid
Folder Structure
selenium-grid-project/
├── src/
│   └── test/
│       └── java/
│           ├── pages/
│           │   └── LoginPage.java
│           ├── tests/
│           │   └── LoginTest.java
│           └── utils/
│               └── WebDriverFactory.java
├── docker/
│   ├── docker-compose.yml
│   └── grid-config/
│       └── custom-config.toml
├── resources/
│   └── testdata/
│       └── users.csv
├── testng.xml
└── README.md
Test Framework Layers
  • Driver Layer: WebDriverFactory.java manages remote WebDriver instances connecting to Selenium Grid via Docker.
  • Page Objects: Classes in pages/ represent UI pages with methods to interact with elements.
  • Test Layer: Test classes in tests/ contain test methods using TestNG framework.
  • Utilities: Helper classes for reading test data, logging, and WebDriver setup.
  • Docker Layer: docker-compose.yml defines Selenium Grid Hub and Nodes containers for parallel browser execution.
  • Configuration: testng.xml and property files manage test suites and environment variables.
Configuration Patterns
  • Docker Compose: docker/docker-compose.yml configures Selenium Hub and browser nodes (Chrome, Firefox) with network settings.
  • Environment Variables: Use Java system properties or TestNG parameters to select browser type and grid URL at runtime.
  • Credentials & Secrets: Store sensitive data outside source code, e.g., environment variables or encrypted files.
  • TestNG XML: Defines test groups, parallel execution, and parameters for flexible test runs.
  • WebDriverFactory: Reads config to create RemoteWebDriver instances pointing to Selenium Grid hub URL.
Test Reporting and CI/CD Integration
  • TestNG Reports: Default HTML and XML reports generated after test execution.
  • Allure Reporting: Integrate Allure for detailed, user-friendly test reports with screenshots and logs.
  • CI/CD Pipelines: Use Jenkins, GitHub Actions, or GitLab CI to start Docker Selenium Grid, run tests, and publish reports automatically.
  • Docker Cleanup: Pipeline scripts should start and stop Selenium Grid containers cleanly to avoid resource leaks.
  • Parallel Execution: Configure TestNG and Selenium Grid to run tests in parallel for faster feedback.
Best Practices
  1. Use Page Object Model: Keep UI interactions separate from test logic for maintainability.
  2. Isolate Tests: Each test should create and quit its own WebDriver session to avoid state leaks.
  3. Parameterize Browsers: Run tests on multiple browsers by passing parameters, leveraging Selenium Grid's parallel nodes.
  4. Explicit Waits: Use explicit waits instead of implicit waits to handle dynamic page elements reliably.
  5. Version Control Docker Files: Keep Docker compose and config files under version control for reproducibility.
Self Check

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

Key Result
Use Docker Selenium Grid with Page Object Model and TestNG for scalable, parallel browser testing.