Cypress Web Testing Framework: Getting Started

On This Page What is Cypress Framework?Features of the Cypre

February 16, 2026 · 15 min read · Tool Comparison

Cypress Web Testing Framework: Getting Started

Modern web apps are dynamic, tight, and user-focused. Testing them demand to be just as agile. Cypress is establish to meet this motivation with a testing experience that mirrors existent user interactions in the browser.

Overview

What is Cypress?

Cypress is a fast, reliable end-to-end quiz framework that scat directly in the browser.

Why is Cypress important?

It offers real-time reloading, flake-free examination execution, and powerful debugging. all tailored for modern JavaScript frameworks. Its developer-friendly architecture simplifies test creation and boosts productivity.

How to Run Cypress Tests

  1. Install Cypress using npm install cypress.
  2. Launch Cypress with npx cypress open.
  3. Create your test cases in the cypress/e2e folder.
  4. Run exam in the Cypress Test Runner UI or headless mode.
  5. View results and debug with screenshots, logs, and picture playback.

This article covershow Cypress works, its nucleus welfare, and a practical guide to part essay modern web applications effectively.

What is Cypress Framework?

is a JavaScript framework meant to make web easy. Developers and QA engineers can indite automated trial that interact directly with the application code and browser in real clip.

This approach makes Cypress faster and more stable than conventional based tools.

Cypress is unique because it runsinside the browser, not outside like most automation tools. This gives itdirect access to the, network requests, local store, and browser APIs, simply like a real exploiter, without relying on external protocols.

Also Read:

Features of the Cypress Framework

Cypress has a racy feature set project to enhance test stability, performance, and developer experience.

Some of its best feature are:

  • Same Run-Loop Execution:Tests run inside the browser alongside your app, giving unmediated access to the DOM, biscuit, storage, and network without proxies.
  • Automatic Waiting:No need for manual postponement, Cypress handles DOM change and assertions mechanically, reducing flakiness.
  • Real-Time Reloading: Save a test file, and Cypress reloads instantly, speeding up growth.
  • Time Travel:View UI snapshots at each exam step for easy debugging.
  • Clear Error Messages:Failures show clear errors and stack traces with entire context.
  • Built-In Debugging:Use .debug () or .pause () to audit app state with DevTools.
  • Network Control:Modify or block API calls using cy.intercept () to test various scenarios.
  • Test Isolation:Each test run severally with clean state, ascertain consistent results.
  • Cross-Browser Support:Works with Chrome, Firefox, Edge, and Electron.
  • Visual :The UI shows exactly what each test do, tread by step.

Also Read:

Why Cypress For Automation Testing

Old-school automation tools such as Selenium have been working their magic for years. However, new web apps arrive with different testing requirements.

Cypress addresses several of the issues that developers and QA team take with nowadays.

  • Fast & amp; Developer-Friendly:Runs directly in the browser for near-instant feedback and no web delays.
  • Flake-Free Testing:Auto-waiting, retries, and test isolation ensure stable, CI-friendly test runs.
  • Effortless Debugging:Get clip travel, screenshots, dev tools access, and elaborate logarithm, all in one view.
  • Front-End Ready:Optimized for React, Angular, Vue, Svelte, and supports component-level testing.
  • Unified Testing Tool:One fabric for,,, and (experimental).
  • Network Control:Easily intercept and stub HTTP postulation to screen real-world scenarios and edge cases.
  • Live Reload:Instant feedback with auto-reloading tests on code changes, which is stark for.
  • Thriving Ecosystem:Backed by a strong community and plugins for CI, reporting, and reportage.

Components of the Cypress Framework

Cypress is more than but a test runner. It has amodular architecturethat include multiple ingredient working together to create, run, and debug expeditiously.

  1. Test Runner (Cypress App): A graphic UI that displays executed commands, screenshots, console logarithm, and network activity, enabling real-time test debug with pause and DOM review capabilities.
  2. Cypress CLI: A command-line puppet to open the Test Runner, run tryout in, and configure runs for.
  3. Cypress Configuration (cypress.config.js): Controls test behavior by setting base URLs, file locations, timeouts, environment variables, viewport sizes, and reporting option.
  4. : Use Mocha and Chai syntax to write tests with.cy.js or .spec.js file extensions.
  5. Fixtures: Stable test data files stored in the cypress/fixtures folder, habituate to mock APIs or provide stimulus information in formats like JSON or images.
  6. Support Folder: Contains shared usefulness like commands.js where reusable custom commands are defined to keep scripts clean and maintainable.
  7. Plugins:Extend Cypress with custom-made tasks like file downloads and reporting viacypress/plugins/index.js, using plugins like cypress-axe or image-snapshot.

Cypress Web Testing Framework Workflow

Cypress follows a streamlined and intuitive workflow that enable testers and developers to compose, run, and maintain rich end-to-end tests.

Here ’ s a virtual breakdown of how Cypress act from setup to execution.

Step 1:Install Cypress in your JavaScript project using npm install cypress, see seamless integration with modern frameworks.

Step 2:Launch the Cypress graphic interface utilise npx cypress unfastened to select browsers, run tryout files, and scene real-time trial execution.

Step 3:Write tryout use Mocha-style syntax with inside the cypress/e2e/ directory.

Step 4:Run exam in headed mode via the Test Runner or headless mode habituate npx cypress run for CLI executing.

Step 5:Store static data in cypress/fixtures and define reusable logic in cypress/support to streamline test development.

Example fixture (user.json):

{'' email '': `` test @ example.com '', '' password '': `` pass1234 ''}

Example custom command (cypress/support/commands.js):

Cypress.Commands.add ('login ', (email, password) = & gt; {cy.get (' # email ') .type (email) cy.get (' # watchword ') .type (password) cy.get ('button [type=submit] ') .click ()})

Step 6:Access video (if enabled), failure screenshots, detailed bid logs, and time-travel snapshots for efficient debugging.

Step 7:Seamlessly connect Cypress with Jenkins, GitHub Actions, GitLab, CircleCI, and other for fast, stable.

Also Read:

Getting Started with Cypress Testing (With Example)

Cypress simplifies end-to-end testing with nonrational commands and built-in affirmation.

This subdivision continue essential method you ’ ll use day-to-day, with practical representative and syntax explanations.

1. Visiting a Page

cy.visit ('https: //example.com ')
  • Loads the given URL in the exam browser.
  • Starts the test from the outlined page.

2. Selecting Elements

By ID:

cy.get (' # login-button ')

By Class:

cy.get ('.menu-item ')

By Attribute:

cy.get (' [data-testid= '' submit-btn ''] ')

Read More:

3. Typing into Fields

cy.get ('input [name= '' email ''] ') .type ('user @ example.com ')
  • .type () simulates type.
  • Works on inputs, textareas, or contenteditable elements.

4. Clicking Elements

cy.get ('button [type= '' submit ''] ') .click ()
  • Triggers a click case.
  • Can include {force: true} to override visibility checks.

Must Read:

5. Assertions with .should ()

Cypress uses Chai for assertions.

cy.get ('h1 ') .should ('contain.text ', 'Welcome ') cy.url () .should ('include ', '/dashboard ') cy.get ('input ') .should ('have.value ', 'admin ')

Must Read:

6. Chaining Commands

Cypress use a chainable API. Every command postponement for the previous one to complete.

cy.get ('form ') .find ('input [name= '' email ''] ') .type ('test @ example.com ') .should ('have.value ', 'test @ example.com ')

7. Waiting (Implicit & amp; Explicit)

Cypress mechanically wait for DOM elements. But you can too look manually:

cy.wait (1000) // waits 1 2nd

For dynamical content:

cy.get ('.loader ', {timeout: 10000}) .should ('not.exist ')

Also Read:

8. Custom Commands (Reusable)

Inside cypress/support/commands.js, define:

Cypress.Commands.add ('login ', (email, parole) = & gt; {cy.get (' # email ') .type (e-mail) cy.get (' # password ') .type (password) cy.get (' # login ') .click ()})

Use in your tryout:

cy.login ('user @ example.com ', '123456 ')

9. Test Hooks (Before/After)

Set up or tear down given:

before (() = & gt; {cy.visit ('/login ')}) after (() = & gt; {cy.clearCookies ()})

Use beforeEach to run before every exam:

beforeEach (() = & gt; {cy.visit ('/ ')})

10. Grouping Tests

describe ('Login Tests ', () = & gt; {it ('logs in successfully ', () = & gt; {// tryout}) it ('shows error on invalid login ', () = & gt; {// test})})

Organise related tests under a individual suite.

Installing the Cypress Web Testing Framework

Installing Cypress is simple, but setting it up aright ensures stability and easygoing maintenance.

Below is a step-by-step guide for installing Cypress in a real-world project.

1. Prerequisites:Before installation, create certain the following are install:

  • (v12 or high recommended)
  • npm or yarn
  • A undertaking folder (already format with npm init -y)

Verify:

node -v npm -v

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

2. Install Cypress via npm:Navigate to your task root folder and run:

npm install Cypress -- save-dev

This command adds Cypress as a dev dependency, installs it in node_modules, and enables CLI commands.

If using Yarn:

yarn add Cypress -- dev

3. Exposed Cypress for the Initiative Timeto initialize the Cypress folder structure.

npx Cypress open

This creates a cypress folder with the following structure:

cypress/ ├── e2e/ ├── fixtures/ ├── support/ cypress.config.js

The first runalso give sample exam files under cypress/e2e to help you get started.

4. Folder Structure Breakdown

Folder/FilePurpose
e2e/Store your test specification file
fixtures/JSON or former static test data
support/Custom dictation, reclaimable logic, and hooks
cypress.config.jsCypress form file for base URL, timeouts, etc.

5. Cypress Configuration (Optional Setup)

Update cypress.config.js to include project-specific settings:

const {defineConfig} = require ('cypress ') module.exports = defineConfig ({e2e: {baseUrl: 'http: //localhost:3000 ', defaultCommandTimeout: 7000, viewportWidth: 1280, viewportHeight: 800,}})

6. Add Cypress Script to package.json

You can simplify commands by append a script:

`` scripts '': {'' cypress: open '': `` npx cypress unfastened '', '' cypress: run '': `` npx cypress run ''}

Run with:

npm run cypress: open

7. Launch the Test Runnerwith npx cypress unfastened, select a browser and test file, then watch the tests run step-by-step in the browser.

Now, Cypress is installed, configure, and ready to run. You can start create test event in the e2e pamphlet.

Steps to run your first Cypress Test

Once Cypress is installed, running your first test is easy. This section walks you through creating a basic test hand that visits a webpage and performs a simple check.

Step 1: Exposed Cypress Test Runner

In your terminal, run:

npx Cypress open

Cypress open in a browser window. You ’ ll see the projection dashboard and sample examination files in the /cypress/e2e folder.

Step 2: Create a New Test File

Navigate to the /cypress/e2e/ directory. Create a file named firstTest.cy.js.

Inside it, glue this codification:

describe ('My First Test ', () = & gt; {it ('Visits the Example Page and chit content ', () = & gt; {cy.visit ('https: //example.cypress.io ') cy.contains ('type ') .click () // Check if the new URL includes '/commands/actions' cy.url () .should ('include ', '/commands/actions ') // Get an input, type into it and control the value cy.get ('.action-email ') .type ('test @ example.com ') .should ('have.value ', 'test @ example.com ')})})

Step 3: Run the Test

  • Return to the Cypress Test Runner.
  • Click on firstTest.cy.js.
  • Cypress establish the selected browser (nonremittal: Electron or Chrome) and executes the trial with visual step tracking.

Step 4: View Test Output

You ’ ll see:

  • A green checkmark for each passed command.
  • Visual DOM snap after each command.
  • URL change tracking.
  • Input value verification.

Terminal log (for headless run):

Running: firstTest.cy.js My First Test ✓ Visits the Example Page and checks content (1.2s) 1 passing (1.2s)

Folder Structure of Cypress Framework

Once you launch Cypress using npx cypress open, it automatically generates a standard leaflet structure to aid you organize tests efficiently.

Default Folder Structure

/cypress /e2e /fixtures /support /downloads (optional, generate after some tests) /node_modules /cypress.config.js /package.json

Here ’ s a breakdown of each booklet:

1. /cypress/e2e – Test Specifications

This is where your test file go. Each .cy.js, .cy.ts, or .cy.jsx file defines a rooms of test cases.

// /cypress/e2e/loginTest.cy.js describe ('Login Page Test ', () = & gt; {it ('should display login signifier ', () = & gt; {cy.visit ('/login ') cy.get ('form ') .should ('exist ')})})

2. /cypress/fixtures – Mock Test Data

Store (usually in .json formatting) for use across test cases.

Example: userData.json

{'' e-mail '': `` test @ example.com '', '' countersign '': `` test1234 ''}

Use in a test file:

cy.fixture ('userData ') .then ((exploiter) = & gt; {cy.get (' # email ') .type (user.email) cy.get (' # password ') .type (user.password)})

3. /cypress/support – Reclaimable Code

  • commands.js: Define customs Cypress commands here.
  • e2e.js: Globose setup codification, runs before every tryout file.

Example from commands.js:

Cypress.Commands.add ('login ', (e-mail, password) = & gt; {cy.get (' # e-mail ') .type (e-mail) cy.get (' # password ') .type (password) cy.get ('button [type= '' submit ''] ') .click ()})

Use in test:

cy.login ('user @ example.com ', 'securePass ')

4. /cypress.config.js – Cypress Configuration

Primal config file to set bag URL, test timeouts, folder paths, etc.

Example:

const {defineConfig} = require ('cypress ') module.exports = defineConfig ({e2e: {baseUrl: 'https: //example.com ', defaultCommandTimeout: 10000}})

5. /downloads – Optional Folder

Cypress generates this when your test include file downloads. It stores downloaded files during test test.

6. /node_modules and /package.json

Standard Node.js folders:

  • node_modules: Contains all installed dependencies, include Cypress.
  • package.json:Lists your dev dependencies and scripts.

Create Test File in Cypress

Here are the detailed steps on how to make test file in Cypress:

Step 1: Go to the /e2e Folder

Open the /cypress/e2e folder inside your Cypress labor. This is where all test files survive.

Use the command line or your code editor to make a new file.

For example:

touch loginTest.cy.js

Or in VS Code, right-click → New File → loginTest.cy.js.

Step 2: Write Your Test Code

Paste this into loginTest.cy.js:

describe ('Login Page Tests ', () = & gt; {it ('should exhibit login form on visit ', () = & gt; {cy.visit ('https: //example.com/login ') cy.get ('form ') .should ('exist ')}) it ('should allow user to login with valid credentials ', () = & gt; {cy.get (' # email ') .type ('user @ example.com ') cy.get (' # password ') .type ('securePass123 ') cy.get ('button [type= '' submit ''] ') .click () cy.url () .should ('include ', '/dashboard ')})})

Step 3: Run the Test

Use this command in your terminal:

npx Cypress open

Then click on loginTest.cy.js in the Cypress Test Runner. Cypress will open your browser and begin executing your exam case.

Step 4: Output Verification

You ’ ll see:

  • Each activity visualized in real-time.
  • Green checkmarks next to successful steps.
  • Detailed error logs (if any test fails).

Example terminal output (if run in headless mode):

Running: loginTest.cy.js Login Page Tests ✓ should exhibit a login form on visit ✓ should allow the exploiter to login with valid credentials 2 passing (2.1s)

Executing Cypress Test Cases Locally

Running Cypress tests on your local machine is quick and demand minimal setup. Cypress proffer two local execution modes:headed and headless.

You can choose free-base on your need to watch the browser UI or not.

1. Open Cypress in Interactive Mode (Headed)

This mode opens the Cypress Test Runner GUI, where you can run tests manually on a real browser.

Command:

npx Cypress open

What It Does:

  • Opens the Cypress Test Runner window.
  • Lists all test files inside /cypress/e2e.
  • Lets you select a browser (Chrome, Edge, Firefox, or Electron).
  • Runs test with real-time visual feedback.

Output:

  • Unripe ticks for passed tests.
  • Red X for failed measure.
  • Live DOM snapshot and network logarithm.

Also Read:

2. Run Tests in Headless Mode (Without UI)

Use this for faster execution or when integrating into CI pipelines. Tests run in the terminal without opening a browser UI.

Command:

npx cypress run

Optional Flags:

npx cypress run -- spec `` cypress/e2e/loginTest.cy.js '' npx Cypress run -- browser chrome

What It Does:

  • Launches Electron by nonpayment unless you specify another browser.
  • Executes all specs or the one you specify.
  • Prints results in the terminal.

Cypress Testing on Real Browsers with BrowserStack

While local Cypress testing works during early growing, it fails to replicate.

span the gap by offering seamless cloud-based screen on existent browsers and device.

Why BrowserStack Automate for Cypress:

  • Real Device & amp; Browser Coverage:Run Cypress tests on actual Windows, macOS, iOS, and Android devices, extend critical browser version, screen size, and platform.
  • Parallel Execution:with parallel runs, cut test time without compromising coverage.
  • Casual Integration:Set up in minutes using BrowserStack ’ s CLI and mere config file. Tests run on the cloud with real-time logs, video, and screenshots for easy debugging.
  • Secure Testing:Test staging or internal chassis via secure tunneling without need to expose your app to the public web.

Also Read:

Advantages of Cypress Web Testing

Cypress differentiates itself from early automation tools by addressing distinctive developer hurting point with innovative architecture and an easy setup.

Here are some key vantage:

  • Fast, Real-Time Execution:Runs in the browser with no network delays, volunteer instant feedback during ontogeny and CI.
  • Auto-Wait and Retry:Automatically waits for elements and retries neglect assertions, reducing flaky tests.
  • Simple Setup:Install with one command. No complex configs or extra dependencies postulate.
  • Powerful Debugging:Get clear errors, step-by-step timelines, and live app state for faster issue resolution.
  • Consistent Test Results:Runs inside the browser for stable, repeatable test across all environments.
  • CI-Friendly Dashboard:Works with popular CI tool and offers insights via logarithm, videos, and test history.

Disadvantages of Cypress Web Testing

Although Cypress has a number of advantages, it has its restrictions as well.

  • Limited Browser Support:Works only with Chrome, Edge, and Firefox. No support for Safari or Internet Explorer.
  • No Multi-Tab/Window Support:Can & # 8217; t manage pop-ups, new tabs, or OAuth flows involve multiple window.
  • JavaScript-Only:Tests must be written in JavaScript or TypeScript, confine non-JS teams.
  • Cross-Origin Restrictions:Limited support for apps cross multiple domains or iframes.
  • No :Supports only web apps. Native mobile testing want separate tools like.
  • Advanced Features Require Expertise:Features like stubbing and tradition commands have a steeper learning curve.
  • High Local Resource Usage:Running Cypress locally can slow machines, especially with large trial suites. CI setups are recommended.

Best Practices for Cypress Web Testing

These best practices enhance test stability, minimize care, and enable long-term scalability.

  • Keep Tests Independent:Avoid test dependencies. Each test should run in isolation to assure dependableness.
  • Use Fixtures for Data:Store test datum in external JSON file to keep tests clean and reusable.
  • Avoid Hardcoded Waits: Rely on Cypress ’ s built-in wait and retries instead of apply arbitrary timeouts.
  • Organise with describe (): Group relate tests and use clear, descriptive titles for better structure.
  • Reset State Before Tests:Use beforeEach () to commence with a clean state by clear storage or reloading pages.
  • Stub APIs with cy.intercept ():Mock external calls for speed and control over edge lawsuit.
  • Create Custom Commands:Use Cypress.Commands.add () for reiterate actions like login to forfend duplicate.
  • Run in Both Modes:Use headless mode for CI and headed way for debugging during growth.
  • Use Cypress Dashboard:Track test history, videos, and eccentric tests across leg and teams.
  • Maintain :Review and refactor tests regularly to adjust with app changes.

Talk to an Expert

Conclusion

Cypress is a robust tool for quick, predictable front-end testing. Its developer-oriented features, live debugging, and out-of-the-box CI desegregation give it an edge as a accomplished instrument for today & # 8217; s web applications.

For JavaScript-based app ontogenesis teams, Cypress is a viable and scalable solution for confidently keeping test reportage high. In improver, BrowserStack enables you to test on existent devices to ensure your app performs as expected.

Frequently Asked Questions

1. What is Cypress apply for?

Cypress is a front-end testing framework for testing web covering on the modernistic web. It assists developers and QA teams with end-to-end, integration, and UI testing. It too has debugging puppet and escape directly in the browser.

2. Which one is better: Cypress vs Selenium?

Both Cypress and Selenium are powerful, but they serve different needs. Cypress is useful for JavaScript applications and real-time browser trial. Selenium is more suited for testing against multiple devices and browser, and your squad work on various programming speech, such as Java, Python, or C #.

Utile Resources for Cypress

Understanding Cypress

Use Cases

Tool Comparisons

Tags
25,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free