Q27 of 38 · CI/CD & DevOps

How do you containerise a Playwright or Selenium test suite for consistent CI execution?

CI/CD & DevOpsMidci-cddockerplaywrightseleniumcontainerstest-environment

Short answer

Short answer: Package the test suite into a Docker image that includes the test runner, browser binaries, and all dependencies. Run the container in CI so the execution environment is identical across every engineer's machine and every CI agent.

Detail

Browser tests are environment-sensitive — font rendering, timezone, and missing browser dependencies all produce different failures locally versus CI. Containerising eliminates this by pinning the exact OS, browser version, and Node runtime.

For Playwright, Microsoft publishes official Docker images (mcr.microsoft.com/playwright) with all browser dependencies pre-installed. Your Dockerfile layers your test code on top. For Selenium, the Selenium Grid Docker images follow the same pattern.

In CI, run the container with environment variables for base URL and credentials injected at runtime. Mount a volume or use artifact upload to extract reports and screenshots after the run. The same image can be run locally for debugging — eliminating "works on my machine" entirely.

// EXAMPLE

Dockerfile.test

FROM mcr.microsoft.com/playwright:v1.44.0-jammy
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npx", "playwright", "test"]

// WHAT INTERVIEWERS LOOK FOR

Knowing why containerisation solves CI flakiness (environment parity). Familiarity with Playwright or Selenium Docker images. Volume-mounting reports and injecting config via env vars.