Capture full-page screenshot of the homepage
Preconditions (2)
✅ Expected Result: A full-page screenshot image file is saved in the Cypress screenshots folder capturing the entire homepage content
describe('Full-page screenshot test', () => { it('should capture a full-page screenshot of the homepage', () => { cy.visit('https://example.cypress.io'); // Cypress automatically waits for page load cy.screenshot('homepage-fullpage', { capture: 'fullPage' }); }); });
This test opens the homepage URL using cy.visit(). Cypress waits automatically for the page to load fully before proceeding. Then, cy.screenshot() is called with the option { capture: 'fullPage' } to capture the entire page, not just the visible viewport. The screenshot is saved with the name homepage-fullpage in the default Cypress screenshots folder.
This approach avoids hardcoded waits and uses Cypress best practices for reliable and maintainable tests.
Now add data-driven testing to capture full-page screenshots of three different URLs
cy.screenshot({ capture: 'fullPage' }) do in Cypress testing?capture option in cy.screenshot()capture option controls what part of the page is captured. Setting it to 'fullPage' means the entire page, not just the visible viewport.cy.screenshot() captures only the visible part. 'fullPage' extends this to the whole page including scrollable areas.cy.screenshot() command accepts an options object where capture: 'fullPage' is the correct way to specify full-page capture.cy.fullPageScreenshot(), or trying to chain .capture('fullPage') are not valid Cypress syntax for full-page screenshots.cy.visit('https://example.com')
cy.screenshot({ capture: 'fullPage' })cy.screenshot() runs immediately after cy.visit(), the page might still be loading.cy.visit('https://example.com')
cy.screenshot({ capture: 'fullpage' })cy.get('#dynamic-section').should('be.visible') waits until the dynamic section is visible, ensuring content is loaded..then(() => cy.screenshot({ capture: 'fullPage' })) ensures the screenshot runs only after the wait condition passes.Pass the test and this pattern moves unknown