Cypress guide

Visual regression testing with Cypress: plugins, setup and pitfalls

Add visual regression testing to Cypress with an image-diff plugin: setup, baselines, thresholds, flakiness fixes and when to choose a hosted service.

Updated October 1, 20267 minute readBy the VisualRunner team

Cypress can take screenshots but does not compare them out of the box. Visual regression testing is added through a plugin that stores baselines and diffs new screenshots, or through a hosted service that receives snapshots from your tests.

✓Plugin-based comparison
✓Baselines per spec
✓Threshold tuning
✓Hosted options for review
1

Pick a comparison plugin

Community plugins such as cypress-image-diff-js and cypress-visual-regression add a cy.compareSnapshot() command. They save a baseline on the first run and compare later screenshots against it. Hosted services like Percy, Applitools and Chromatic provide their own Cypress integrations with a web review UI instead.

2

A minimal snapshot test

After installing and registering the plugin in your Cypress config and support file, a visual check is one command at the point in the test where the page is stable.

describe('homepage', () => {
  it('matches the visual baseline', () => {
    cy.viewport(1280, 800);
    cy.visit('/');
    cy.get('[data-cy="cookie-accept"]').click();
    cy.get('h1').should('be.visible');
    cy.compareSnapshot('homepage');
  });
});
3

Make captures stable

Cypress screenshots are sensitive to timing. Assert on the content you expect before capturing, stub network data that changes, and run in the same browser and headless mode locally and in CI.

  • Wait on assertions, not fixed timeouts
  • Stub APIs that return changing data
  • Hide dynamic elements before capture
  • Use one browser and viewport per baseline
4

Know the limits

Plugin baselines live in your repository, reports are local files, and only the states your specs visit are covered. That is fine for a focused set of flows, harder for hundreds of pages and languages.

5

Or skip the test code entirely

Code-based visual tests only cover the pages and states someone wrote a test for, and only run when the pipeline runs. VisualRunner captures production pages from a sitemap, crawl or URL list, across languages and viewports, and monitors them on a schedule — so CMS edits, translations and third-party scripts are caught too. Engineers can still trigger a monitor from CI through the API.

Questions

Frequently asked questions

Does Cypress support visual testing natively?

Cypress takes screenshots natively; comparing them with baselines requires a plugin or a hosted visual testing service.

Why are my Cypress visual tests flaky?

Usually because the page is captured before it settles, or because data, fonts or browsers differ between runs. Stabilize those before raising the diff threshold.

Continue exploring

Related resources

Turn the checklist into a repeatable workflow

Discover your pages, capture the important states and keep a visual history of every meaningful change.

Start free trial