Skip to content

test: set up Cypress visual diff smoke tests#2707

Open
contolini wants to merge 1 commit intomasterfrom
5269-visual-smoke
Open

test: set up Cypress visual diff smoke tests#2707
contolini wants to merge 1 commit intomasterfrom
5269-visual-smoke

Conversation

@contolini
Copy link
Copy Markdown
Member

Adds a global afterEach hook that runs after every test and takes a screenshot of the app's current state. Baseline screenshots are generated with yarn test-visual:baseline and comparisons against the baseline are made with yarn test-visual.

Changes

Testing

  1. Run yarn test-visual:baseline to generate baseline screenshots.
  2. Change some aspect of the app.
  3. Run yarn test-visual to take new screenshots and compare against the baselines. It should fail if you changed something and pass if you didn't.

Notes

  • I gitignored the entire screenshots directory. Normally you'd only ignore the actual subdirectory and check the base subdirectory into git. Because this is a new thing and all our environments are a little different, I decided to ignore everything for now.


xhr.open('HEAD', url)
xhr.send()
})
Copy link
Copy Markdown
Member Author

@contolini contolini Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function wasn't working as expected with the Cypress global afterEach hook so I replaced it with Cypress' native request method.

Copy link
Copy Markdown
Contributor

@billhimmelsbach billhimmelsbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! 🎉 One comment about how the screenshots are taken, but otherwise super excited to use this in some bug squashing!

Comment on lines +28 to +31
// Every page (I think?) has a #mainWrapper div that contains the content
const hasMainWrapper = body.find('#mainWrapper').length > 0
const screenshotWrapper = hasMainWrapper ? '#mainWrapper' : 'body'
const screenshotElement = body.find(screenshotWrapper).first()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heyo! This method gets some great, clean screenshots of the main wrapper, but does misses out screenshots in the initial navigation.spec.js of the FAQ + FIG over on the documentation side that I think only has a hashed class called mainWrapper_z2l0 currently. It's not useful for local testing where the documentation side isn't always loaded up, but it would be nice when testing against staging, etc.

We could either make exceptions for these / use a wildcard query selector like '[class*="mainWrapper"], [id*="mainWrapper"]), or we could stick with just capturing the full page first, then maybe removing the parts we don't want like the footer and header before the screenshot instead?

Just a thought about including only the parts we want (cleaner) versus excluding the parts we don't want (maybe more flexible). Let me know what ya think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants