What if you could capture the entire webpage perfectly with just one click?
Why Full-page screenshots in Cypress? - Purpose & Use Cases
Imagine you have a long webpage with lots of content, like a news article or a product catalog. You want to check if everything looks right from top to bottom. Manually scrolling and taking many small screenshots is tiring and easy to miss parts.
Taking screenshots piece by piece is slow and frustrating. You might forget to capture some sections or overlap images incorrectly. It's hard to keep track and compare changes over time. This manual way wastes time and causes mistakes.
Full-page screenshots automatically capture the entire webpage in one image, from top to bottom. This saves time and ensures no part is missed. It helps testers quickly see the whole page layout and spot visual bugs easily.
cy.screenshot('top-section') cy.scrollTo('bottom') cy.screenshot('bottom-section')
cy.screenshot({ capture: 'fullPage' })With full-page screenshots, you can instantly capture and review the entire webpage's appearance, making visual testing faster and more reliable.
A tester checks a shopping site's homepage after a redesign. Instead of many partial screenshots, they take one full-page screenshot to confirm all banners, menus, and product lists display correctly on all screen sizes.
Manual screenshots miss parts and waste time.
Full-page screenshots capture everything in one go.
This makes visual testing easier and more accurate.
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
