Updated recently
Last updated:
Quick Answer: Docker containerizes your test environment so tests run identically on any machine. For Playwright: use the official mcr.microsoft.com/playwright image. For Selenium: use selenium/standalone-chrome.
Why Docker for Test Automation?
- Consistency: Same browser version and dependencies everywhere
- Reproducibility: “Works on my machine” is eliminated
- Isolation: Clean environment each run
- CI/CD speed: Docker images cache layers
Playwright Docker Setup
# Dockerfile
FROM mcr.microsoft.com/playwright:v1.40.0-jammy
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npx", "playwright", "test"]
Selenium Docker Setup
# docker-compose.yml
version: '3.8'
services:
selenium-chrome:
image: selenium/standalone-chrome:latest
ports:
- "4444:4444"
shm_size: '2gb'
tests:
build: .
depends_on:
- selenium-chrome
environment:
- SELENIUM_HUB_URL=http://selenium-chrome:4444/wd/hub
Best Practices
- Use official images: Microsoft and Selenium maintained images
- Cache npm layers: Copy package.json first, then npm ci
- Set shm_size: Browsers need shared memory (2gb)
- Multi-stage builds: Smaller images for faster CI
Training Resources
Master test automation with SkilBrill Playwright Training.
FAQ
Do I need Docker for test automation?
Not required, but highly recommended for CI/CD pipelines and consistent environments.
