πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 89 of 100
Selenium Grid & Docker
Advanced

Running Parallel Test Execution inside Docker Selenium Grid

🐳Scenario Overview

Running Parallel Test Execution inside Docker Selenium Grid

Key Takeaways & Cheat Sheet

  • βœ“Use docker-compose to orchestrate dynamic grid hubs and nodes
  • βœ“Scale browser node containers dynamically using scale CLI parameters
  • βœ“Wrap WebDriver sessions in ThreadLocal to ensure execution safety
  • βœ“Use high-speed memory mounting (/dev/shm) to prevent crashes

Short Direct Answer

To run tests in parallel, orchestrate a Docker Selenium Grid. Use a `docker-compose.yml` file to launch a centralized Hub container along with scalable Chrome/Firefox Node containers. In your test framework, wrap the driver in `ThreadLocal` and configure TestNG thread pools to run tests concurrently.

⚠️ Senior Warning (Red Flag)

Avoid using browser node containers without shared memory mounting (/dev/shm). Modern browsers use significant shared memory, and containers will crash on large pages without this flag.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

Docker Selenium Grid is a highly scalable testing solution. You can spin up, scale, and tear down entire multi-browser execution environments in seconds.

SeleniumAutomation.java
Selenium 4 + Java
// βœ… Docker-Compose Configuration Snippet:
// version: "3"
// services:
//   selenium-hub:
//     image: selenium/hub:latest
//     ports:
//       - "4444:4444"
//   chrome-node:
//     image: selenium/node-chrome:latest
//     depends_on:
//       - selenium-hub
//     environment:
//       - SE_EVENT_BUS_HOST=selenium-hub
//     volumes:
//       - /dev/shm:/dev/shm # βœ… Crucial shared memory volume block to prevent browser crashes

// βœ… Scaling nodes command:
// docker-compose up --scale chrome-node=5 -d