Quiz: Visual testing
Why This Matters
A quick check that this module’s ideas hold up before you move on. Answer each question yourself before you open the answer.
Quiz
1. Visual tests pass on your Mac and fail in Linux CI with tiny differences everywhere. Best fix?
- A. Raise the threshold to 20%
- B. Make and compare baselines in the same environment, for example the Playwright Docker image
- C. Delete the baselines
- D. Run visual tests only locally
Show answer
B. Rendering differs per operating system. Baselines made where the comparison runs remove the noise without hiding real changes. A high threshold (A) hides real changes too.
Quiz
2. Which page is the weakest candidate for a visual test?
- A. A design-system button
- B. The checkout page
- C. A news page whose content changes every hour
- D. The login form
Show answer
C. Constantly changing content means constant false failures.
Quiz
3. Why does the example repository pin @playwright/test to exactly 1.65.1?
- A. Newer versions do not support TypeScript
- B. The Docker image tag must match the Playwright version, or baselines and CI drift apart
- C. npm requires exact versions for dev dependencies
- D. To make installs faster
Show answer
B. A different Playwright version ships different browser builds. Version, image tag and workflow tag move together, followed by new baselines that someone reviews.
Quiz
4. What does a mask do in toHaveScreenshot?
- A. Removes the element from the page
- B. Covers the element with a solid box in both screenshots, so it cannot cause a difference while the layout around it is still checked
- C. Blurs the whole screenshot
- D. Skips the comparison
Show answer
B. Mask what is not the point of the test (photos, prices, dates). If the masked element changes size or position, the comparison still notices.
Quiz
5. You run --update-snapshots after a design change. What must you do before committing?
- A. Nothing; the tests pass now
- B. Look at the new images, because the update accepts whatever the page looks like, bugs included
- C. Delete the old images by hand
- D. Raise the threshold
Show answer
B. An update turns the current state into the truth. Reviewing the new baselines is the only thing that stops a bug from becoming the baseline.
Quiz
6. On an Apple Silicon Mac, why add --platform linux/amd64 to the Docker command?
- A. arm64 images do not exist
- B. GitHub’s runners are amd64; rendering on the same architecture keeps local baselines identical to CI
- C. amd64 is faster under emulation
- D. Docker requires it on macOS
Show answer
B. The image exists for both architectures, and Docker on Apple Silicon picks arm64 by default. Same image, same version, same architecture: that is what makes a baseline reliable.