Visual testing with Percy on homepage
Preconditions (3)
✅ Expected Result: Percy snapshot named 'Homepage snapshot' is successfully created and uploaded for visual testing
/// <reference types="cypress" /> import '@percy/cypress'; describe('Percy integration basics', () => { it('should take a Percy snapshot of the homepage', () => { cy.visit('https://example.com'); // Wait for page to load fully cy.get('body').should('be.visible'); // Take Percy snapshot cy.percySnapshot('Homepage snapshot'); }); });
This test script uses Cypress with Percy integration.
First, it visits the homepage URL using cy.visit().
Then, it waits for the page body to be visible to ensure the page loaded.
Finally, it calls cy.percySnapshot('Homepage snapshot') to take a visual snapshot for Percy.
This snapshot will be uploaded to Percy for visual comparison.
We import @percy/cypress to enable the cy.percySnapshot() command.
Now add data-driven testing with 3 different URLs to take Percy snapshots
cy.percySnapshot('name') to capture snapshots.cy.percySnapshot('Homepage').describe('Visual test', () => {
it('checks homepage', () => {
cy.visit('/')
cy.percySnapshot('Homepage loaded')
cy.get('#login').click()
cy.percySnapshot('Login clicked')
})
})cy.percySnapshot() call captures one snapshot, so total is 2.it('checks page', () => {
cy.visit('/page')
cy.percySnapshot()
})cy.percySnapshot() command requires a name string argument to identify the snapshot.cy.percySnapshot() calls at correct steps.Pass the test and this pattern moves unknown