Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

Puppeteer Screenshot Testing with Jest: A Basic Setup

A practical Jest and Puppeteer setup: install the preset, capture a page or element, manage browser readiness, and troubleshoot common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a minimal Jest screenshot test, use the jest-puppeteer preset, navigate its provided page to the URL under test, save a screenshot with page.screenshot(), and let the preset manage the browser lifecycle. The example below creates its output directory, waits for navigation, writes a PNG, and closes the browser through the preset.

Choose the preset for a basic setup

Jest’s documented integration uses jest-puppeteer for the compact setup: install it as a development dependency, set the preset in Jest configuration, then use the preset-provided page and browser globals. This is the simplest route when you do not need to customize how the browser is launched or connected. See the Jest Puppeteer integration guide.

Install the packages

In an existing Node project, install Jest, Puppeteer, and the preset as development dependencies:

npm install --save-dev jest jest-puppeteer puppeteer

Puppeteer’s current system-requirements documentation specifies Node.js 22.12 or newer. It lists Chrome for Testing support on Windows x64, macOS x64/arm64, Debian/Ubuntu Linux x64/arm64, and openSUSE/Fedora Linux; Linux system packages may also be required. Check the Puppeteer system requirements for the CI image and operating system you use, since requirements can change. The documentation does not establish a universally compatible package-version matrix for every project, so use versions compatible with your project’s lockfile.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Configure Jest

Add a Jest configuration that selects the preset. For a project using package.json, add or merge this property:

{
  "jest": {
    "preset": "jest-puppeteer"
  }
}

If your project keeps Jest configuration in a separate file, use the equivalent configuration there:

module.exports = {
  preset: 'jest-puppeteer',
};

Write a test that captures the page

Create a test file such as home.test.js. This example makes the output directory if needed, visits a page, checks its title, writes a screenshot, and runs asynchronously:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
const fs = require('node:fs/promises');
const path = require('node:path');

describe('home page', () => {
  beforeAll(async () => {
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });
  });

  it('has a title and saves a screenshot', async () => {
    expect(await page.title()).toBe('Example Domain');

    const outputDir = path.join(process.cwd(), 'artifacts');
    await fs.mkdir(outputDir, { recursive: true });
    await page.screenshot({ path: path.join(outputDir, 'home.png') });
  });
});

Run the test with:

npx jest home.test.js

On success, Jest reports a passing test and the PNG appears at artifacts/home.png under the current working directory. Puppeteer’s screenshot API saves to the supplied path when path is set; without a path, page.screenshot() returns image bytes as a Uint8Array by default, or a base64 string when base64 encoding is configured. See Puppeteer’s Page.screenshot() API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pick a readiness condition that matches the site

networkidle2 is the wait condition used in a Puppeteer navigation example, not a universal definition of “ready.” Pages with polling, streaming, analytics, or other ongoing requests may not settle as expected; a page can also finish network requests before its important UI has rendered. Choose a readiness condition that fits the application, such as waiting for a known selector after navigation:

await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-testid="page-ready"]');

Replace the example selector with an element that reliably indicates the page state you need to capture. Puppeteer documents page and element screenshots in its screenshot guide.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Capture one element instead of the whole page

When the test concerns a particular component, select it and use ElementHandle.screenshot() rather than capturing the whole viewport:

const card = await page.$('[data-testid="product-card"]');
if (!card) throw new Error('Product card was not found');
await card.screenshot({ path: 'artifacts/product-card.png' });

The explicit missing-element check makes the failure clearer than attempting to capture a nonexistent handle. The screenshot guide documents element capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a custom browser lifecycle is needed

Use a custom integration if the preset does not provide the launch, connection, environment, or teardown control your project needs. Jest’s documented pattern uses globalSetup to launch Puppeteer and publish its WebSocket endpoint, a custom test environment to connect to that endpoint, and globalTeardown to close the browser and remove temporary state. This assigns browser ownership explicitly: setup launches, the environment connects, and teardown closes and cleans up. The lifecycle is more involved than the preset; follow the current implementation guidance in the Jest integration guide rather than mixing preset-managed and separately managed browser instances.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

What screenshot tests do—and do not—cover

A saved screenshot is useful as a visual artifact, but the sample above does not compare it against a baseline or decide whether its pixels are correct. Add an explicit image comparison or review workflow if you need visual regression detection. The jest-puppeteer project README points to Argos as an option for tracking changes introduced by pull requests: jest-puppeteer README.

Also distinguish browser assertions from Jest coverage. Jest’s integration guide warns that functions executed through page.$eval, page.$$eval, or page.evaluate run outside Jest’s scope in the described setup, so Jest cannot generate coverage for that page-side code. Use these methods for browser interaction or assertions, but do not treat them as coverage of the code running inside the page.

Troubleshoot common setup failures

  • Jest cannot find the preset: confirm jest-puppeteer is installed in the package where Jest runs, and that the active Jest configuration includes preset: 'jest-puppeteer'.
  • Browser launch fails in CI: verify the runner meets Puppeteer’s current Node and platform requirements, and install any Linux system packages needed by its distribution. Check the system requirements for the actual CI image.
  • The screenshot path fails: create the parent directory before calling page.screenshot(). The example uses fs.mkdir(..., { recursive: true }) to handle a missing directory.
  • Navigation hangs or captures too early: the site may have ongoing network activity, or the chosen wait condition may not match when the page is visually ready. Use an application-specific readiness signal such as waitForSelector.
  • An element screenshot fails: check that the selector matches the loaded page and handle a missing element before calling screenshot().
  • Jest reports missing coverage for page code: browser-side code invoked with evaluate, $eval, or $$eval is outside Jest’s coverage scope as described in the integration guide; test that code through an appropriate in-page or unit-testing approach.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot artifact without maintaining a Puppeteer/Jest browser lifecycle, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its capture options include removing cookie/consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. The MCP server provides take_screenshot, get_page_info, and capture_pdf tools.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, save a screenshot of your own page with cURL:

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for the request options. ScreenshotNeo includes 1,000 screenshots a month on its free plan with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card.

Frequently Asked Questions

Does the Jest screenshot example compare images automatically?

No. It saves a screenshot and runs the test assertions shown; pixel comparison or baseline review requires a separate visual-testing workflow.

Can I use a screenshot without writing it to disk?

Yes. Puppeteer’s page.screenshot() returns image bytes by default, or a base64 string when base64 encoding is configured.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.