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