October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Run Cypress Tests in Headless Mode

Run Cypress tests headlessly with npx cypress run, then select a browser or spec and configure CI, screenshots, video, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

From your project root, run npx cypress run. Cypress runs the suite to completion in headless mode by default, so you do not need an extra headless flag. To choose Chrome, use npx cypress run --browser chrome; to run one spec, add --spec and its path.

Run Cypress headlessly from the command line

Use the package-manager command that matches your project. The examples below assume Cypress is installed in the project and that you run them from its root directory.

As an Amazon Associate I earn from qualifying purchases.

npx cypress run

This runs the configured test suite and exits when it finishes. Headless is the default for cypress run; there is no need to add a separate headless option.

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

Install Cypress if it is not already in the project

The Cypress CI setup documentation gives these installation commands:

  • npm install cypress --save-dev
  • yarn add cypress --dev
  • pnpm add cypress --save-dev
  • bun add cypress --dev

After installation, use the corresponding project-local runner or package-manager script in place of npx if that is how the project is configured.

Choose a browser or a specific spec

Select an installed browser

Pass a browser name with --browser when you want the run to use a particular browser:

npx cypress run --browser chrome
npx cypress run --browser firefox

Cypress detects supported browsers that are installed in the local environment. The browser must also be available in your CI image or container. Cypress lists Chrome-family browsers, Firefox, and experimental WebKit among its browser options; availability and installation details can vary by Cypress release, so check the browser reference for the version installed in your project. A browser name is not a way to install that browser.

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

Run one spec

npx cypress run --spec "cypress/e2e/my-spec.cy.js"

Replace the example path with the spec you want to run. The file must match the project’s configured specPattern; a spec outside that pattern will not be discovered as a test. Omit --spec to run the configured suite.

Use Cypress in CI reliably

In a continuous-integration job, make sure the application server is running and responding before Cypress starts. Starting the server and immediately invoking the test command can race: a test may visit the local app before it is ready. Cypress’s CI guidance explicitly warns that there is no guarantee the server has booted by the time cypress run executes.

  1. Install project dependencies and ensure the CI environment has the browser required by your run.
  2. Start the application using the project’s normal build or development command.
  3. Wait for the application URL to respond before running Cypress. Cypress’s official GitHub Action provides start and wait-on options for this workflow.
  4. Run npx cypress run, adding --browser or --spec only when needed.

Use the same app URL and environment configuration your tests expect. If CI reports navigation or connection failures, first verify that the server is reachable from the job and that the readiness check waits on the correct URL.

Headless and headed runs: what changes

cypress run is the run-to-completion command and launches browsers headlessly by default. Add --headed when you want to see the browser during that CLI run:

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.
npx cypress run --headed --browser chrome

cypress open is the interactive workflow: it opens Cypress and a headed browser for choosing and working with tests. Use it for interactive development; use cypress run for a run that completes through the CLI.

Headless viewport and pixel ratio

Cypress documents a default headless screen size of 1280 × 720 and a device pixel ratio (DPR) of 1. These rendering defaults can affect screenshot and video dimensions. Cypress documents changing browser launch behavior through the before:browser:launch event; consult the launch documentation for the configuration appropriate to your installed version.

Save screenshots and video for failures

Failure screenshots

During cypress run, Cypress automatically captures a screenshot when a test fails. The default directory is cypress/screenshots, and Cypress clears that folder before a run unless configured otherwise. To turn off automatic failure screenshots, set screenshotOnRunFailure: false in Cypress configuration.

Video recording

Video recording is disabled by default. Set video: true in Cypress configuration to record video for each spec during cypress run. The default directory is cypress/videos; Cypress clears it before a run unless configured otherwise. Configure artifact retention in CI if you need to inspect the files after the job ends.

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

Troubleshoot headless test failures

A test passes headed but fails headlessly

Cypress notes that a test can pass in one mode and fail in the other. Reproduce the run with the browser visible and keep Cypress open after the spec:

npx cypress run --headed --no-exit --browser chrome

Compare the visible run with the headless failure screenshots or enabled videos. A difference does not by itself prove a rendering problem; inspect the failing assertion, timing, browser, and application state as well.

The requested browser is not found

Install the requested browser in the local environment or use a CI image that supplies it. Confirm that the browser name is supported by the Cypress version in the project and that Cypress detects the installation.

The selected spec is not found

Check the spelling and path passed to --spec, then verify that the file matches the configured specPattern. Run without --spec if you intend to execute all discovered specs.

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

The app is unavailable when tests start

Do not rely on the server-start command finishing as proof that the site is ready. Add a readiness wait for the app’s actual URL, and check that the server is reachable from the same CI job or container running Cypress.

Screenshot or video artifacts are missing

For screenshots, confirm a test failed and that screenshotOnRunFailure has not been disabled. For video, confirm video: true is set. Also account for Cypress clearing the default artifact folders at the start of a run and ensure CI saves the files before cleanup.

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

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a Cypress runner: it captures a page but does not execute Cypress tests. If your separate task is to capture a page image or PDF without installing and managing a browser, this one-call request returns a screenshot. See the ScreenshotNeo API documentation for parameters.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include X-Page-Verdict and X-Billed headers.
  • An MCP server offers take_screenshot, get_page_info, and capture_pdf tools for AI agents.
  • The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and no card.

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

Frequently asked questions

Does headless mode mean Cypress runs tests in a different command?

No. The ordinary run command, cypress run, uses headless browser launching by default; headed mode is an explicit option.

Can I use headless Cypress to test a page without running my application?

Cypress tests still need the application or target environment their commands visit. Headless describes whether the browser window is displayed, not whether a site or server is needed.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
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.