Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Take Full Page Screenshots with Percy

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Percy is a visual testing tool that captures screenshots of your web pages and compares them across builds to catch unintended UI changes. By default, Percy captures the viewport, but you can configure it to take full-page screenshots that include content below the fold. This guide walks you through setting up full-page screenshots in Percy for both JavaScript (Cypress, Playwright, Puppeteer) and non-JavaScript (Ruby, Python) projects.

What You'll Need

  • A Percy account and a project created in the Percy dashboard (you'll get a PERCY_TOKEN).
  • An existing test suite (e.g., Cypress, Playwright, Puppeteer, or a CI setup) where you already run Percy snapshots.
  • The Percy SDK installed for your testing framework (e.g., @percy/cypress, @percy/playwright, @percy/puppeteer, or the language-specific SDK).
  • Basic familiarity with your testing framework's configuration files.

Step-by-Step

  1. Install or update the Percy SDK. Ensure you have the latest version of the SDK for your framework. For example, in a Cypress project, run npm install -D @percy/cypress. For Playwright, npm install -D @percy/playwright. For Puppeteer, npm install -D @percy/puppeteer. If you're using Ruby or Python, install the corresponding gem or pip package.
  2. Set the PERCY_TOKEN environment variable. This token is unique to your Percy project. You can find it in the Percy dashboard under Project Settings. Export it in your terminal or CI environment: export PERCY_TOKEN=your_token_here. Without it, Percy CLI commands will fail.
  3. Configure full-page capture in your test. The method depends on your framework:
    • Cypress: Use the fullPage option in the cy.percySnapshot() command. Example: cy.percySnapshot('Homepage', { fullPage: true });
    • Playwright: Use the fullPage option in the page.percySnapshot() method. Example: await page.percySnapshot('Homepage', { fullPage: true });
    • Puppeteer: Use the fullPage option in the page.percySnapshot() method. Example: await page.percySnapshot('Homepage', { fullPage: true });
    • Ruby (Capybara): Use the full_page: true option. Example: page.percy_snapshot('Homepage', full_page: true)
    • Python (Selenium): Use the full_page=True option. Example: page.percy_snapshot('Homepage', full_page=True)
  4. Set a minimum height (if needed). Some pages have dynamic content that extends as you scroll. Percy captures the full page by scrolling and stitching screenshots. If your page has lazy-loaded images or infinite scroll, you may need to set a specific height. In the options object, you can pass minHeight (in pixels) to ensure the capture area is tall enough. For example: { fullPage: true, minHeight: 2000 }.
  5. Run your tests with Percy. Instead of running your test runner alone, prefix the command with percy exec --. For example, for Cypress: percy exec -- cypress run. For Playwright: percy exec -- playwright test. This wraps your test run and sends snapshots to Percy.
  6. Verify in the Percy dashboard. After the run completes, open the Percy dashboard. You should see a new build with your snapshot. Click on the snapshot to expand it. If full-page capture worked, you'll see the entire page, including content below the fold, in the screenshot.
  7. Adjust for sticky elements. If your page has a sticky header or footer, Percy may capture it multiple times during scrolling. To avoid this, you can use the stickyHeaderOffset or stickyFooterOffset options (available in some SDKs). For example, in Cypress: { fullPage: true, stickyHeaderOffset: 60 }.

Common Mistakes

  • Forgetting to set fullPage: true. Without it, Percy captures only the viewport. Double-check your snapshot call.
  • Using the wrong SDK version. Full-page support was added in specific versions. For example, @percy/cypress requires at least version 2.0.0. Check the Percy changelog for your SDK.
  • Not running tests under percy exec . If you run tests without the Percy CLI wrapper, snapshots are not uploaded. The command must be .
  • Ignoring dynamic content. If your page loads content on scroll (lazy loading), the stitched screenshot may miss it. Use minHeight to force a taller capture area, or ensure content is loaded before the snapshot.
  • Sticky elements causing visual duplication. A sticky header appears at the top of each stitched segment, resulting in a repeated header in the final image. Use the offset options to exclude it.

Tips

  • Name snapshots clearly. Use descriptive names like 'Homepage full page' to make it easy to identify in the dashboard.
  • Set a reasonable minHeight. If your page is known to be 3000px tall, set minHeight: 3000 to avoid extra scrolling and stitching artifacts.
  • Use responsive widths. Test full-page screenshots at multiple viewport widths to catch layout issues at different breakpoints. You can set widths in the snapshot options, e.g., { widths: [375, 768, 1280] }.
  • Combine with auto-snapshot. If you use Percy's auto-snapshot feature (e.g., in Cypress), you can still override with fullPage in individual snapshots.
  • Keep an eye on performance. Full-page screenshots take longer to capture and may increase build time. Use them for critical pages, not every snapshot.

Troubleshooting

  • Snapshot appears as viewport only. Check that you passed fullPage: true and that your SDK version supports it. Update the SDK to the latest.
  • Build fails with 'No snapshots found'. Ensure your test actually runs the snapshot command and that you're using percy exec. Also verify PERCY_TOKEN is set correctly.
  • Stitched image has blank areas. This can happen if the page height changes during scrolling (e.g., images loading). Try increasing minHeight or waiting for all resources to load before the snapshot.
  • Sticky header appears multiple times. Use the stickyHeaderOffset option with the height of your header. If your SDK doesn't support it, consider hiding the header via CSS before the snapshot.
  • Full-page capture works locally but not in CI. CI environments often have different viewport sizes or slower network. Set explicit minHeight and widths in your snapshot options to ensure consistency.

Frequently Asked Questions

Does Percy support full-page screenshots for all frameworks?

Most official SDKs (Cypress, Playwright, Puppeteer, Selenium, Capybara) support full-page capture. Check the SDK documentation for the exact option name.

Can I set full-page capture globally for all snapshots?

Yes, in some SDKs you can set defaults. For example, in Cypress you can override cy.percySnapshot defaults in a support file, or use the percy.config.js file to set global options.

Why is my full-page screenshot missing the bottom of the page?

This usually happens when the page height changes after the initial capture. Set a minHeight that is larger than the expected page height to force the capture area to include the bottom.

Does full-page capture work with single-page applications (SPAs)?

Yes, but ensure that all dynamic content is rendered before the snapshot. You might need to wait for network requests or use a small delay before calling the snapshot.

Can I exclude certain elements from the full-page screenshot?

Yes, you can use CSS to hide elements via the percyCSS option in the snapshot call. For example, { fullPage: true, percyCSS: '.ad-banner { display: none; }' }.

How do I compare full-page screenshots across different browsers?

Percy automatically captures across the browsers you configure in your project settings. Full-page screenshots are captured in each browser, and you can compare them side-by-side in the dashboard.