Full-page screenshots help you capture the entire webpage in one image. This is useful to check the page layout and design visually.
Full-page screenshots in Cypress
cy.screenshot({ capture: 'fullPage' })The capture: 'fullPage' option tells Cypress to take a screenshot of the entire page, not just the visible part.
You can add a name like cy.screenshot('homepage', { capture: 'fullPage' }) to save the screenshot with a custom file name.
cy.screenshot({ capture: 'fullPage' })cy.screenshot('login-page', { capture: 'fullPage' })
cy.visit('https://example.com') cy.screenshot('example-full', { capture: 'fullPage' })
This test visits the Cypress example page and takes a full-page screenshot named 'full-page-example.png'.
describe('Full-page screenshot test', () => { it('captures the entire page', () => { cy.visit('https://example.cypress.io') cy.screenshot('full-page-example', { capture: 'fullPage' }) }) })
Full-page screenshots may take longer to capture than visible area screenshots.
Make sure the page is fully loaded before taking the screenshot to avoid missing content.
Full-page screenshots work best on desktop viewports; mobile views may crop differently.
Use cy.screenshot({ capture: 'fullPage' }) to capture the entire webpage.
Full-page screenshots help catch layout and design issues beyond the visible screen.
Always wait for the page to load fully before taking screenshots for best results.
Practice
cy.screenshot({ capture: 'fullPage' }) do in Cypress testing?Solution
Step 1: Understand the
Thecaptureoption incy.screenshot()captureoption controls what part of the page is captured. Setting it to 'fullPage' means the entire page, not just the visible viewport.Step 2: Compare with other options
By default,cy.screenshot()captures only the visible part. 'fullPage' extends this to the whole page including scrollable areas.Final Answer:
Takes a screenshot of the entire webpage, including parts not visible on screen -> Option BQuick Check:
Full-page screenshot = entire webpage [OK]
- Thinking it captures only visible viewport
- Confusing screenshot with video recording
- Assuming it clears previous screenshots
Solution
Step 1: Recall the correct method signature
Thecy.screenshot()command accepts an options object wherecapture: 'fullPage'is the correct way to specify full-page capture.Step 2: Eliminate incorrect syntax
Passing 'fullPage' as a string argument directly, using non-existent commands likecy.fullPageScreenshot(), or trying to chain.capture('fullPage')are not valid Cypress syntax for full-page screenshots.Final Answer:
cy.screenshot({ capture: 'fullPage' }) -> Option CQuick Check:
Correct syntax uses options object with capture key [OK]
- Passing 'fullPage' as a string argument directly
- Using non-existent commands like cy.fullPageScreenshot()
- Trying to chain .capture() method
cy.visit('https://example.com')
cy.screenshot({ capture: 'fullPage' })What will happen if the page is still loading when the screenshot is taken?
Solution
Step 1: Understand Cypress behavior on page load
Cypress does not automatically wait for all page content to load unless explicitly told. Ifcy.screenshot()runs immediately aftercy.visit(), the page might still be loading.Step 2: Effect on screenshot
If the page is not fully loaded, the screenshot will capture whatever is visible at that moment, possibly incomplete content.Final Answer:
The screenshot may capture an incomplete or partially loaded page -> Option DQuick Check:
Screenshot timing affects completeness [OK]
- Assuming Cypress waits automatically for full load
- Expecting error if page not loaded
- Thinking screenshot always captures full content
cy.visit('https://example.com')
cy.screenshot({ capture: 'fullpage' })Why does the full-page screenshot not work as expected?
Solution
Step 1: Check the option value spelling and case
The correct option value is 'fullPage' with capital P. 'fullpage' is invalid and ignored.Step 2: Understand Cypress option sensitivity
Cypress options are case-sensitive. Using wrong case causes fallback to default behavior (visible viewport only).Final Answer:
The option value 'fullpage' is case-sensitive and should be 'fullPage' -> Option AQuick Check:
Option values are case-sensitive in Cypress [OK]
- Ignoring case sensitivity in option values
- Using non-existent commands
- Assuming wait fixes option errors
Solution
Step 1: Wait for dynamic content visibility
Usingcy.get('#dynamic-section').should('be.visible')waits until the dynamic section is visible, ensuring content is loaded.Step 2: Take full-page screenshot after wait
Chaining.then(() => cy.screenshot({ capture: 'fullPage' }))ensures the screenshot runs only after the wait condition passes.Final Answer:
cy.get('#dynamic-section').should('be.visible') .then(() => cy.screenshot({ capture: 'fullPage' })) -> Option AQuick Check:
Wait for content visible, then screenshot [OK]
- Taking screenshot before waiting for content
- Using fixed wait times instead of element checks
- Clicking element unnecessarily before screenshot
Ready to prove it?
Pass the test and this pattern moves unknown
