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

To test authenticated pages with BackstopJS, provide the browser with a valid session before the scenario loads, wait for the authenticated view to render, and compare its screenshot with an approved reference. BackstopJS documents three ways to prepare that state: import cookies with cookiePath, set it in an onBeforeScript, or use Playwright’s engineOptions.storageState for cookies and local storage. Which method works depends on how your application stores and refreshes its login state.

How BackstopJS tests an authenticated page

BackstopJS captures screenshots for scenarios and compares a new test capture with a reference image. The reference is the visual state your team has accepted; it is not simply whatever the page looked like on the last run.

  1. Configure a scenario for the URL and viewport you want to test, along with a way to establish authentication.
  2. Run backstop test. BackstopJS captures the page and reports visual differences from the reference.
  3. Inspect the report. If the change is intentional, run backstop approve to update the reference; if it is not, fix the application or test setup.

The project documentation recommends integrating the CLI into a build process or running it before deployment. A failed layout test returns a nonzero status, so a CI job can treat visual regressions as a failing check.

Choose how to provide the login state

These are alternative setup patterns, not interchangeable guarantees. A cookie file is suitable when cookies alone represent the session. If authentication also depends on local storage, Playwright storage state may fit better. If state must be established dynamically, use a custom setup or an application-specific login flow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Method Use it when Important detail
cookiePath A valid session can be represented by a JSON cookie file. BackstopJS’s default onBefore script imports the file. Its path is relative to the current working directory.
onBeforeScript You need scenario-specific setup or another app-specific preparation step. The script runs before each scenario and receives the page and scenario. Use APIs appropriate to the configured browser engine.
Playwright storageState The session state includes cookies and local storage and you are using the Playwright engine. Set engine to playwright and configure engineOptions.storageState with the state JSON file.

BackstopJS documents Puppeteer as its default engine and Playwright as an engine option. Its documentation describes Playwright browser choices including Chromium, Firefox, and WebKit. Do not pass Playwright-specific storageState settings to the Puppeteer engine; the engines have distinct configuration options.

Import cookies with cookiePath

If you already have a suitable JSON cookie file, add cookiePath to the scenario. The configured path is interpreted relative to the directory where you run BackstopJS. A minimal scenario shape is:

{
  "scenarios": [
    {
      "label": "Account overview",
      "url": "https://example.com/account",
      "cookiePath": "auth/account-cookies.json",
      "readySelector": "[data-testid='account-overview']"
    }
  ]
}

This shows the relevant scenario fields, not a complete BackstopJS configuration file. The cookie file must contain a format the configured engine can import, and its session must still be valid when the test runs. A cookie file does not guarantee that every login flow can be reproduced: applications may require additional browser state, refreshed tokens, or an identity-provider step.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Prepare state with an on-before script

Use a custom onBeforeScript when cookie import is insufficient or setup needs to vary by scenario. BackstopJS runs this hook before each scenario and makes the browser page and scenario available. Script paths can be placed under the configured paths.engine_scripts; the project recommends pointing that setting to a project directory.

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

The repository also documents a custom onBefore handler that receives page, scenario, viewport, isReference, Engine, and config. Select the hook style and browser APIs supported by your installed BackstopJS version and engine. For example, a Puppeteer-based setup can load cookies through Puppeteer’s page APIs before capture; that does not make Playwright configuration valid for Puppeteer. Puppeteer is a browser automation library with page interaction and screenshot capabilities, as described in Google Chrome for Developers’ overview.

Keep credentials and active session files out of public examples and source control. Load sensitive state from an appropriate private location in your local or CI environment rather than committing real tokens.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Load Playwright storage state

For an application whose browser state includes local storage as well as cookies, configure the Playwright engine and point engineOptions.storageState at a Playwright state JSON file. BackstopJS documents this as a way to set cookies and local storage before an authenticated capture. The state file must be generated and maintained in a secure environment, and it can expire just like a session.

{
  "engine": "playwright",
  "engineOptions": {
    "storageState": "auth/playwright-state.json"
  },
  "scenarios": [
    {
      "label": "Account overview",
      "url": "https://example.com/account",
      "readySelector": "[data-testid='account-overview']"
    }
  ]
}

Use this pattern only with the Playwright engine. Check the README for the BackstopJS version installed in your project if your configuration behaves differently from the current repository documentation.

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

Wait for the authenticated view, not just the login request

A valid session does not prove that the page is ready to capture. The application may still be redirecting, rendering client-side content, or loading data after the browser has accepted the session. Configure a readiness condition that corresponds to the actual view under test.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • readySelector waits for a chosen selector to exist, such as a stable account-page marker.
  • readyEvent waits for the application to log a chosen string, when the app exposes a useful readiness message.
  • delay adds a fixed pause; use it when needed, but a selector or explicit app event is generally more closely tied to the intended state.
  • readyTimeout sets the wait limit for readiness. If it expires, check whether the session redirected or the selector/event is wrong before simply extending the timeout.

BackstopJS also supports onReadyScript for actions after readiness, plus scenario interactions such as clicks, hovers, and key presses. Use them when the interaction is part of the view being tested—for example, opening a menu that should appear in the reference—not as a substitute for establishing authentication.

Choose capture scope intentionally. A scenario can capture the full page or selected CSS selectors. By default, BackstopJS captures the first match for a selector. Use selectorExpansion to capture all matches, and expect when you need to assert how many selected items should be present.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make the result repeatable in CI

Visual comparisons are sensitive to differences in rendering environments and to changing page content. Run reference and test captures in a consistent environment, and inspect the report before approving a new baseline. BackstopJS documents Docker as one option for reducing environment variation; it is a reproducibility aid, not a guarantee that all differences disappear.

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.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • Use the same browser engine and comparable runtime environment for reference and test runs.
  • Choose readiness conditions based on a real application marker rather than relying on a long arbitrary delay.
  • Control application data and other dynamic content where your test environment permits it.
  • Use CI reporting, including the documented JUnit output option, when your pipeline consumes test reports.
  • Keep the authentication state refreshable and private. How it is renewed depends on your application and identity provider; BackstopJS does not define those policies.

Run the same command locally and in CI when diagnosing a mismatch. A nonzero backstop test result indicates the visual test failed; use the generated report to determine whether the page is genuinely different or the capture setup is unstable.

Troubleshoot common authentication and capture failures

Symptom Likely cause What to check
The screenshot shows a login page or redirect. The session is missing, expired, or not accepted for that URL. Confirm the cookie file path is relative to the working directory, validate the session in the same environment, and check whether the app requires local storage or a scripted flow.
The scenario fails waiting for readiness. The selector or event does not occur, or the page never reached the intended authenticated view. Inspect the captured page and redirects; verify the selector/event spelling and that it is present after login. Adjust readyTimeout only if the page is legitimately slower.
Playwright storage settings have no effect. The project is running a different engine or the option path does not match the installed version. Confirm "engine": "playwright", the engineOptions.storageState path, and the README for your installed BackstopJS version.
Local and CI screenshots differ unexpectedly. Browser/runtime rendering or page content differs between environments. Use a consistent environment, consider Docker, and control changing content where practical. Compare the report before approving a new baseline.
A selector captures only one of several repeated elements. BackstopJS selects the first match by default. Use selectorExpansion to capture all matches and expect to check the expected count.

Or skip the browser setup

If you need a screenshot of a page but do not need BackstopJS’s reference-image regression workflow, ScreenshotNeo can return a screenshot or PDF with one GET request. It accepts cookie and authorization options, but this is not a replacement for BackstopJS’s baseline comparison and test-report workflow.

See the ScreenshotNeo API documentation for request options. Example cURL request:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/account -o shot.webp

Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com/account"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com/account' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free.

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

Frequently Asked Questions

Can BackstopJS use a saved login session?

Yes. A cookie file or Playwright storage-state file can carry browser session state, provided it is valid and includes what the application needs.

Does a successful login guarantee a stable visual test?

No. The scenario still needs a readiness condition tied to the authenticated view, and dynamic content can affect the image.

Which browsers can BackstopJS use for authenticated captures?

The repository documents Puppeteer as the default engine and Playwright options including Chromium, Firefox, and WebKit; confirm details against your installed version.

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.

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