0
0
Selenium Javatesting~8 mins

Test parallelization in CI in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Test parallelization in CI
Folder Structure
selenium-java-project/
├── src/
│   └── test/
│       └── java/
│           ├── pages/           # Page Object classes
│           ├── tests/           # Test classes
│           ├── utils/           # Utility classes (e.g., WebDriverFactory)
│           └── listeners/       # TestNG listeners for reporting
├── testng.xml                  # TestNG suite configuration for parallel runs
├── pom.xml                     # Maven build and dependency management
└── ci/
    └── Jenkinsfile             # CI pipeline script with parallel stages
Test Framework Layers
  • Driver Layer: WebDriverFactory manages browser instances, supports thread-safe parallel execution.
  • Page Objects: Encapsulate UI elements and actions for reusability and maintainability.
  • Tests: Test classes using TestNG annotations, designed to run independently for parallel execution.
  • Utilities: Helper classes for common functions like waits, logging, and data handling.
  • Listeners: TestNG listeners capture test events and generate reports.
  • Configuration: testng.xml defines parallel execution strategy and thread count.
Configuration Patterns
  • testng.xml: Defines test suites and sets parallel="methods" or parallel="classes" with thread-count to enable parallel test execution.
  • WebDriverFactory: Uses ThreadLocal<WebDriver> to provide isolated browser instances per thread.
  • Environment Properties: Use property files or system variables to select environment (dev, staging, prod) and browser type.
  • CI Pipeline: Jenkinsfile or similar config triggers tests with parallel stages or parallel test execution enabled.
  • Credentials: Securely stored in environment variables or CI secrets, injected at runtime.
Test Reporting and CI/CD Integration
  • TestNG Reports: Default HTML reports generated after test runs showing pass/fail status per test method.
  • Allure or Extent Reports: Enhanced reporting with screenshots, logs, and history support.
  • CI Integration: Jenkins or other CI tools run tests in parallel, collect reports, and mark build status accordingly.
  • Parallel Logs: Use thread-safe logging to avoid mixed logs from parallel tests.
  • Post-build Actions: Archive reports and send notifications (email, Slack) based on test results.
Best Practices for Test Parallelization in CI
  1. Isolate Tests: Ensure tests do not share state or data to avoid flaky results when run in parallel.
  2. Use ThreadLocal WebDriver: Provide separate browser instances per thread to prevent interference.
  3. Configure Parallelism in testng.xml: Control parallel execution granularity and thread count carefully to balance speed and resource use.
  4. Manage Test Data: Use unique or independent test data sets per test to avoid conflicts.
  5. Integrate with CI Properly: Configure CI pipelines to run tests in parallel and collect reports reliably.
Self Check

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

Key Result
Use TestNG with ThreadLocal WebDriver and testng.xml parallel settings to run Selenium Java tests in parallel within CI pipelines.