DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 Scan×
Skip to content
World desk5 min

How to Write and Run Cypress Tests

A practical guide to installing Cypress, writing independent JavaScript specs, running them in open or headless mode, and setting up reliable CI runs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To write and run Cypress tests, install Cypress as a development dependency, choose end-to-end (E2E) or component testing in its first-run Launchpad, write independent specs, and use cypress open while developing and cypress run for terminal or CI runs. The two modes complement each other; you can use either or both in the same project.

Install Cypress in your JavaScript project

From the project root, use the package manager the project already uses. For npm:

npm install cypress --save-dev

Equivalent commands are:

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

Cypress normally downloads its matching binary during the package’s postinstall step. If lifecycle scripts are disabled or you deliberately defer the binary download, install it separately with cypress install. See the official installation guide and CLI reference.

Choose E2E or component testing and complete setup

Start the Launchpad from the project root:

npx cypress open

Use yarn cypress open, pnpm cypress open, or bunx cypress open if that fits your package manager. On first launch, the Launchpad guides you through selecting E2E or component testing, choosing a browser, and creating or configuring the initial project structure. Selecting one mode does not prevent adding the other later. Details are in the installation guide and opening the app guide.

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.

For a team-friendly repeatable command, add a descriptive script such as cy:open to package.json. Avoid naming the script cypress, which can conflict with Yarn command resolution.

Know where Cypress puts files

The generated defaults include cypress.config.js, a fixtures directory, and a support file: cypress/support/e2e.js for E2E or cypress/support/component.js for component testing. Cypress loads the relevant support file before the selected spec. Put genuinely global hooks and setup there; keep spec-specific or heavy imports in the spec that needs them. These are defaults, not requirements—the structure can be reconfigured. See Writing and organizing tests.

Write a focused, independent spec

Cypress specs are JavaScript test files. This generic example assumes the app’s base URL is configured so that / resolves to its home page:

describe('home page', () => {
  it('shows the main heading', () => {
    cy.visit('/')
    cy.get('h1').should('be.visible')
  })
})

Keep each test able to run by itself and in a different order. Cypress cautions that tests which depend on state left by another test can fail when reordered, skipped, or run alone. Set up needed state explicitly, and assert outcomes meaningful to a user. Prefer selectors that remain stable as presentation changes; choose a convention appropriate to your application.

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

Use the Cypress support file for shared setup, not as a place to make one spec depend on another. The Cypress organization guide explains spec structure and test independence.

Choose test data and network behavior deliberately

For known static data checked into the project, a fixture keeps the data separate from the spec. Fixtures can also provide deterministic network responses:

cy.intercept('GET', '/api/users', { fixture: 'users.json' })

Use cy.readFile() when a file can change or is created by the application. For large files or work that needs Node.js, use cy.task(). If generating tests from records, import the records statically so the it() cases exist when Cypress loads the spec. See the official guide.

Run tests interactively while you develop

Run npx cypress open to launch Cypress’s interactive browser workflow. Choose a spec to run; Cypress displays the browser and a Command Log with test-step history for inspecting what happened. It watches the active spec and reruns it after edits, which supports a tight authoring and debugging loop. More detail is available in Writing and organizing tests and Opening the app.

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

Run a suite from the terminal

Use cypress run to run tests to completion; it is headless by default:

npx cypress run

To run one spec, select it explicitly:

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

You can also select a browser with --browser or provide a configuration file with --config-file. A selected file must also match the project’s configured specPattern. The CLI reference documents the available options.

Goal Command Best fit
Author and debug with live feedback npx cypress open Interactive browser, Command Log, and reruns when the active spec changes
Run a suite to completion npx cypress run Terminal checks and CI; headless by default, with options for browser, spec, and configuration

These are complementary workflows: use open mode to build and debug tests, then run mode for repeatable checks.

Run Cypress reliably in CI

Install Cypress in the CI job, start the application, wait until its URL responds, and only then invoke Cypress. Starting the server and Cypress together without a readiness check creates a race: the browser may visit the app before the server is ready. Cypress’s CI guide says there is “no guarantee that your server has booted by the time cypress run executes.” Use a readiness utility or the official Cypress GitHub Action’s documented start and wait-on options rather than relying on an arbitrary sleep.

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

Keep credentials in your CI provider’s secret-management facility. Cypress warns that secrets passed as command-line arguments may appear in CI logs. Invoke cypress run through the job configuration for your CI provider; setup syntax varies by provider.

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

Troubleshoot common Cypress test problems

The app is unavailable when a test starts

Cause: Cypress began before the development or test server was listening. Fix: make the job wait for the app URL to respond before running Cypress; a fixed delay can still be too short or waste time.

A test fails when run alone or in a different order

Cause: it relies on browser or application state left by another test. Fix: make setup explicit in the test or shared setup, and verify the spec can run on its own.

The selected spec does not run

Cause: its path does not match the project’s configured specPattern. Fix: check the configured pattern and pass a matching path to --spec.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

A fixture does not reflect a changed file

Cause: fixtures are intended for static test data and Cypress caches them. Fix: use cy.readFile() for changing or application-created files.

Cypress’s binary is missing after package installation

Cause: install lifecycle scripts were blocked or binary installation was deferred. Fix: run cypress install as described in the CLI reference.

A secret appears in CI output

Cause: a sensitive value was supplied as a CLI argument or otherwise exposed in logs. Fix: source credentials from the CI provider’s secret facility and avoid printing them.

Or skip the browser setup

If your goal is to capture a webpage rather than test your own application’s behavior, ScreenshotNeo is a screenshot API and MCP server for developers. It is not a Cypress replacement: Cypress runs application tests, while ScreenshotNeo returns a page screenshot or PDF. One GET request can capture a URL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation. ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.

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

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.