Visual regression testing compares screenshots of a user interface with approved reference images, called baselines, to flag unexpected changes in appearance. It can catch changes in spacing, layout, typography, and component states after a code update.
How does visual regression testing work?
- Choose a state and approve a baseline. Capture an intentionally rendered page or component at a specific viewport, with representative content.
- Keep the capture environment stable. Use consistent browser, operating system, fonts, viewport, and test data. Control animations and other changing content where practical.
- Review the differences. Inspect the baseline, new screenshot, and diff. Fix unintended changes and update the baseline only after approving the new appearance.
Example: A booking-change dialog on mobile
Capture the open dialog at a mobile viewport with a long fare description and both action buttons visible. A change to a shared spacing token pushes the confirmation button below the visible area. The diff flags the layout shift. The reviewer opens the preview to check whether the action remains reachable and whether the new layout is acceptable.
What should you test alongside screenshots?
Use interaction tests to check whether the dialog opens, the right button submits, and focus returns to the trigger when it closes. A screenshot can show the dialog at one moment. Keyboard and assistive technology checks cover behavior a screenshot cannot capture.