Test Overview
This test opens a webpage, clicks a button, and captures a screenshot to verify the page state visually.
This test opens a webpage, clicks a button, and captures a screenshot to verify the page state visually.
describe('Screenshot capture test', () => { it('should capture screenshot after button click', () => { cy.visit('https://example.cypress.io') cy.get('a[href="/commands/actions"]').click() cy.screenshot('after-click') cy.get('.action-email').should('be.visible') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io' | Example Cypress homepage loaded | Page loaded successfully | PASS |
| 3 | Finds link with href '/commands/actions' and clicks it | Navigated to Actions commands page | Link found and clicked | PASS |
| 4 | Captures screenshot named 'after-click' | Screenshot saved in Cypress screenshots folder | Screenshot file created | PASS |
| 5 | Finds input with class '.action-email' and checks visibility | Input field visible on page | Input field is visible | PASS |
cy.screenshot() in Cypress tests?cy.screenshot()cy.screenshot('filename').cy.get('button.submit').click();
cy.screenshot('after-click');cy.screenshot('after-click') to take a screenshot with that name.cy.screenshot()cy.screenshot('login-page', { capture: 'viewport' });capture option valuescapture. 'viewport' is valid.cy.screenshot does not require chaining after cy.get(). So these are not issues.capture option 'viewport' is valid; the problem is elsewhere. -> Option B.profile-pic and save it as 'profile.png'. Which code snippet correctly does this?cy.get(), then call .screenshot() on that element. The argument is the file name without extension.cy.screenshot does not accept selector as first argument. cy.get('.profile-pic').screenshot('profile'); correctly selects element and calls .screenshot('profile'). cy.screenshot('profile.png', { element: '.profile-pic' }); uses invalid options.Pass the test and this pattern moves unknown