Guide10 min read

Regression testing and Docker: Without a reproducible environment, your screenshots are worthless

Without Docker, your screenshots change from one machine to another. Fonts, rendering, resolutions: everything diverges.

Contents
  1. Why screenshots differ from one machine to another
  2. Docker: the identical environment, every time
  3. Dockerizing your visual testing setup: the key steps
  4. Benefits beyond reproducibility
  5. Where Delta-QA fits into this approach
  6. Common mistakes to avoid with Docker and visual testing
  7. FAQ

Reproducible environment: an identical software configuration on every run (same operating system, same libraries, same fonts, same rendering engine) ensuring that a test's results don't vary depending on the machine it runs on.

You've set up visual testing. You compare screenshots. Your tests pass locally. And when they run on CI, you get 47 reported differences, none of which matches a real bug.

Most teams have lived this scenario, and draw the wrong conclusion: "Visual testing is too noisy, it doesn't work."

Visual testing works very well. What doesn't work is your environment.

A screenshot taken on macOS with Apple fonts will never be pixel-identical to one taken on Ubuntu with FreeType fonts. The same browser at 1920x1080 doesn't render the same at 100% and at 125% scaling. Anti-aliasing, font hinting, sub-pixel smoothing: everything differs.

Docker solves this problem. And if you do visual testing without Docker, you're wasting your time.

The essentials on one page (definition, no-code automation, tool selection grid): Automated regression testing, no-code.

Why screenshots differ from one machine to another

To understand why Docker is essential, you need to understand what makes a screenshot differ between two machines, even when the code is strictly identical.

Font rendering: culprit number one

Font rendering is by far the first source of differences between screenshots. Each operating system uses its own typographic rendering engine. macOS uses Core Text, which favors fidelity to the font's design. Windows uses DirectWrite, which favors alignment to the pixel grid. Linux uses FreeType, whose behavior varies depending on the fontconfig configuration.

The result: the same text, with the same font, at the same size, on the same page, doesn't produce the same pixels depending on the operating system. The differences are sometimes invisible to the naked eye: a one-pixel shift, slightly different smoothing. But a pixel-by-pixel comparison tool detects them and flags them as regressions.

And that's not all. The available fonts vary from one system to another. If your CSS specifies a font that isn't installed on the CI machine, the browser uses a fallback font. That substitution can change the spacing, the line height, the character width, and therefore the entire layout.

The browser's rendering engine

Even when using the same browser (Chrome, for example), the exact version of the rendering engine influences the result. Chrome 120 doesn't produce exactly the same rendering as Chrome 122 for certain CSS properties. The differences are marginal, but in the context of a pixel-by-pixel comparison, they're enough to generate false positives.

On your development machine, you have Chrome 124. On CI, the runner uses Chrome 118. The screenshots don't match. It's not a bug in your application: it's an environment inconsistency.

Resolution and scaling

Your screen's DPI (dots per inch) influences the rendering. A Retina screen (2x) produces screenshots at a different resolution from a standard (1x) screen. The viewport can be the same (1280x720), but the physical pixels are different, and the rendering of CSS elements (borders, shadows, rounded corners) varies accordingly.

CI servers generally have no physical screen. They use a virtual framebuffer (Xvfb on Linux) whose DPI configuration can differ from that of your development machine. If this configuration isn't explicitly controlled, you get subtle but persistent differences.

Docker: the identical environment, every time

Docker solves these problems by encapsulating the entire test environment in a container. The same operating system, the same fonts, the same browser, the same version, the same rendering configuration: whether the container runs on your macOS machine, on a Linux GitHub Actions runner, or on an EC2 instance.

What the container must contain

A Docker container for visual testing must include several components that standard Docker images don't provide.

First, the fonts. All the fonts your application uses must be installed in the container. Not only the Google Fonts that your CSS imports via a link: those fonts are downloaded on the fly and may vary in version. Install them locally in the container to guarantee that the same version is used on every run.

Second, a fixed browser version. Don't use "the latest version of Chrome". Pin a specific version. When you decide to update, you update your Docker image, regenerate your baselines, and start again from a clean state. It's an explicit decision, not a side effect.

Third, the rendering configuration. Linux's fontconfig configuration, the virtual framebuffer's DPI, the anti-aliasing settings: everything must be explicitly defined in the Dockerfile. Leave nothing to default values, because defaults change between Linux distributions and between versions of those distributions.

Fourth, the system dependencies. The shared libraries needed for the browser to run in headless mode (libgbm, libnss3, libatk, etc.) must be present and in compatible versions. A missing or wrong-version library can change the rendering in a way that is imperceptible but detectable by comparison.

The base image: don't reinvent the wheel

Several community-maintained Docker images are specifically designed to run headless browsers. Playwright's official images include the browsers and their dependencies in locked versions. The images from BrowserStack and other providers offer pre-tested configurations.

The common mistake is to start from a minimal Ubuntu image and install Chrome manually. You end up solving dependency, sandbox and permission problems: problems already solved by the specialized images.

Start from an image that works. Add your fonts and your specific configuration. Don't build from scratch unless you have a compelling reason to.

The Dockerfile as living documentation

One of the underrated benefits of Docker for visual testing is documentation. Your Dockerfile is an exhaustive, executable description of your test environment. When a new member joins the team, they don't need to guess which fonts to install, which Chrome version to use, or how to configure fontconfig. They launch the container and get the same environment as everyone else.

It's also insurance against environment regressions. If a screenshot changes, you know the change comes from the application or the content, not from the environment. Because the environment is versioned, tagged, and immutable.

Dockerizing your visual testing setup: the key steps

Setting up a Docker environment for visual testing follows a logical progression. Each step strengthens the reliability and reproducibility of your tests.

Step 1: Pin the versions

Before touching Docker, list everything that takes part in rendering your pages. The browser and its exact version. The fonts used by your application. The browser's system dependencies. The target resolution and DPI.

This list is your environment specification. Each item must be pinned to a precise version. No "latest", no semantic range, no "whatever". In visual testing, "whatever" is a synonym for "false positives".

Step 2: Build the image

Your Dockerfile starts from a base image that already includes the browser in a fixed version. You add your fonts, your fontconfig configuration, and the tools needed to run your tests.

The key point is the order of the instructions in the Dockerfile. The layers that change least often (the operating system, the browser, the fonts) must be at the top. The layers that change frequently (your application code, your test files) must be at the bottom. This optimizes the build cache and speeds up your pipelines.

Step 3: Validate reproducibility

Build the image. Run your visual tests from the container. Build the image again. Rerun the tests. The results must be identical. If they aren't, something in your image isn't deterministic: probably a dependency installed through a package manager that fetched a more recent version.

Verify by building the image on two different machines (your workstation and the CI, for example) and comparing the results. It's the ultimate reproducibility test.

Step 4: Integrate into the CI/CD pipeline

Once the image is validated, integrate it into your CI/CD pipeline. Your visual tests run in the Docker container on CI, and the baselines are generated in the same container. No more "it passes on my machine but not on CI".

Push your Docker image to a registry (Docker Hub, GitHub Container Registry, GitLab Container Registry) and reference it in your CI configuration. When you update the image, update the tag and regenerate your baselines. It's a controlled, traceable process.

Step 5: Manage updates

Browsers release security updates regularly. You can't stay on the same version indefinitely. Establish an update rhythm (monthly, for example) and treat each update as a planned event.

The procedure is simple: update the browser version in the Dockerfile, rebuild the image, rerun the visual tests, review the differences, update the baselines for the expected differences (rendering changes tied to the new browser version), and investigate the unexpected ones.

Benefits beyond reproducibility

Docker brings other advantages to visual testing that deserve a mention.

Parallelization

A Docker container starts in a few seconds. You can launch 10, 20, 50 containers in parallel to test as many pages simultaneously. Your visual tests that took 30 minutes sequentially take 3 minutes in parallel. And each container is isolated, so the tests don't interfere with each other.

Test isolation

Each container starts from a clean state. No persistent browser cache, no leftover cookies, no user profile accumulating data between runs. Each test starts in a blank environment, which eliminates an entire category of false positives tied to browser state.

Where Delta-QA fits into this approach

Delta-QA considerably simplifies the Docker equation for visual testing.

Delta-QA is inherently less sensitive to rendering variations between environments. Where a pixel-by-pixel comparison tool flags every sub-pixel difference caused by font rendering, it simulates the human eye: it only flags what a person would notice (margins, paddings, dimensions, positioning) regardless of the rendering environment.

That doesn't mean Docker is useless with Delta-QA. A reproducible environment remains a good practice. But it does mean the tolerance to environment variations is incomparably higher. A different anti-aliasing doesn't generate a false positive in Delta-QA, because it goes beyond pixel-by-pixel and only retains what a human eye would notice.

For teams that can't (or don't want to) invest in building and maintaining a Docker image dedicated to visual testing, that's a decisive advantage. Delta-QA gives you reliable results even in imperfect environments. And if you add Docker on top, you get the best of both worlds: Delta-QA's precision in a perfectly reproducible environment.

Common mistakes to avoid with Docker and visual testing

Using "latest" as an image tag

This is the first cause of unstable tests in a Docker context. The "latest" tag points to a different image every week. If your Dockerfile starts with a "latest" image, your environment isn't reproducible. Pin a specific version and update it in a controlled way.

Forgetting the fonts

Your application uses Inter, Roboto and a custom font. Your Docker image includes none of them. The browser downloads them through Google Fonts, when the network allows. On a CI runner with no Internet access, or with a slow network, the fonts don't load and the browser uses the default system fonts. Your screenshots are unusable.

Ignoring the viewport size

The fact that your Dockerfile defines a 1920x1080 virtual screen doesn't mean the browser uses a 1920x1080 viewport. Scrollbars, address bars, window borders: all elements that reduce the effective viewport. Configure the viewport explicitly in your visual testing tool, not in the virtual screen's resolution.

Not versioning the image

Your Dockerfile is in the Git repository. Good. But the image built from that Dockerfile at a given moment can't be reconstructed if the installed packages were updated in the meantime. Push your images to a registry, tag them with a hash or a date, and reference the exact tag in your CI pipeline.

FAQ

Is Docker mandatory for visual testing?

No, but without Docker (or an equivalent reproducible-environment mechanism), you'll spend a considerable amount of time handling false positives tied to rendering differences between machines. Docker isn't mandatory, but it's practically indispensable if you want reliable results with pixel-by-pixel comparison.

Which base Docker image do you recommend for visual testing?

Playwright's official images (mcr.microsoft.com/playwright) are an excellent starting point. They include the browsers in pinned versions and the system dependencies, and are maintained by the Microsoft team. Add your fonts and your specific configuration.

Does Docker slow down visual tests?

Starting a Docker container adds a few seconds to the total execution time. In return, Docker enables massive parallelization: you can launch dozens of containers simultaneously, which reduces the total time of your test suite. The balance is almost always positive.

How do you handle Google Fonts in a Docker container?

Download the font files and install them locally in the container through your Dockerfile. Don't rely on on-the-fly downloads from Google's servers: the network may be slow, unavailable, or return a different version of the font. A local installation guarantees consistency.

Can you use Docker Desktop for visual testing locally?

Yes, and it's even recommended during the development phase. Docker Desktop lets you run the same container as the CI on your development machine. If your tests pass in the container locally, they'll pass on CI. It's the fundamental principle of reproducibility.

Does Delta-QA need Docker to work?

No. Delta-QA works without Docker: since it simulates the human eye, it is inherently less sensitive to rendering variations between environments. Docker remains a good practice to maximize reproducibility, but it isn't a prerequisite for getting reliable results with Delta-QA.

Try Delta-QA