Percy helps you catch visual changes in your app by taking screenshots during tests. It makes sure your app looks right after updates.
Percy integration basics in Cypress
cy.percySnapshot('snapshot-name')Use cy.percySnapshot() inside your Cypress test to take a visual snapshot.
The snapshot name helps you identify the screenshot in Percy dashboard.
cy.visit('https://example.com') cy.percySnapshot('Homepage')
cy.get('button').click() cy.percySnapshot('After button click')
This test visits the homepage and takes a Percy snapshot named 'Homepage'. Percy will compare this snapshot with previous ones to find visual differences.
describe('Visual test with Percy', () => { it('checks homepage appearance', () => { cy.visit('https://example.com') cy.percySnapshot('Homepage') }) })
Make sure Percy is installed and configured in your Cypress project before using cy.percySnapshot().
Snapshots are uploaded to Percy service, so you need internet connection during test runs.
Use meaningful snapshot names to easily track visual changes in Percy dashboard.
Percy integration lets you catch visual bugs by taking screenshots during Cypress tests.
Use cy.percySnapshot('name') to capture snapshots at any test step.
Review visual changes in Percy dashboard to keep your app looking great.
Practice
Solution
Step 1: Understand Percy's role in testing
Percy is used to capture screenshots during tests to detect visual changes.Step 2: Compare options with Percy's purpose
Only To catch visual bugs by taking screenshots during tests matches Percy's function of catching visual bugs via screenshots.Final Answer:
To catch visual bugs by taking screenshots during tests -> Option BQuick Check:
Percy purpose = Visual bug detection [OK]
- Thinking Percy speeds up tests
- Confusing Percy with test data tools
- Assuming Percy writes backend tests
Solution
Step 1: Recall Percy snapshot command syntax
The correct command iscy.percySnapshot('name')to capture snapshots.Step 2: Match options with correct syntax
Only cy.percySnapshot('Homepage') matches the exact syntaxcy.percySnapshot('Homepage').Final Answer:
cy.percySnapshot('Homepage') -> Option CQuick Check:
Correct Percy command = cy.percySnapshot() [OK]
- Swapping method and object order
- Adding extra words like 'take'
- Using wrong method names
describe('Visual test', () => {
it('checks homepage', () => {
cy.visit('/')
cy.percySnapshot('Homepage loaded')
cy.get('#login').click()
cy.percySnapshot('Login clicked')
})
})How many Percy snapshots will be captured during this test run?
Solution
Step 1: Count cy.percySnapshot calls in the test
There are two calls: one after visiting homepage, one after clicking login.Step 2: Confirm each call triggers a snapshot
Eachcy.percySnapshot()call captures one snapshot, so total is 2.Final Answer:
2 -> Option DQuick Check:
Number of snapshots = 2 [OK]
- Counting only one snapshot
- Assuming snapshots auto-capture without calls
- Confusing clicks with snapshots
it('checks page', () => {
cy.visit('/page')
cy.percySnapshot()
})But Percy dashboard shows no snapshots. What is the likely problem?
Solution
Step 1: Check cy.percySnapshot usage
Thecy.percySnapshot()command requires a name string argument to identify the snapshot.Step 2: Identify missing argument issue
Since no name is given, Percy does not capture or upload the snapshot.Final Answer:
Missing snapshot name argument in cy.percySnapshot() -> Option AQuick Check:
Snapshot name required = true [OK]
- Thinking visit order matters
- Believing Percy only works on mobile
- Assuming multiple snapshots are mandatory
Solution
Step 1: Identify required Percy snapshots
Snapshots needed at three steps: before filling, after filling, after submission.Step 2: Check which snippet has all three snapshots with names
Only cy.visit('/form') cy.percySnapshot('Before filling') cy.get('#input').type('data') cy.percySnapshot('After filling') cy.get('#submit').click() cy.percySnapshot('After submission') has three namedcy.percySnapshot()calls at correct steps.Final Answer:
Code snippet with three named Percy snapshots at correct steps -> Option AQuick Check:
Three named snapshots = cy.visit('/form') cy.percySnapshot('Before filling') cy.get('#input').type('data') cy.percySnapshot('After filling') cy.get('#submit').click() cy.percySnapshot('After submission') [OK]
- Omitting snapshot names
- Missing snapshots at required steps
- Calling snapshots before visit
Ready to prove it?
Pass the test and this pattern moves unknown
