Cypress Testing Guide (2025): Setup, Examples & Best Practices

March 04, 2026 · 15 min read · Tool Comparison

Blog / Insights /
Cypress Testing Guide (2025): Setup, Examples & amp; Best Practices

Cypress Testing Guide (2025): Setup, Examples & amp; Best Practices

Contributors Updated on

Learn with AI

Linkedin

Facebook

X (Twitter)

Mail

Learn with AI

If you ’ ve ever struggled with the complexities of traditional testing model like Selenium—setting up drivers, dealing with flakey tests, and waiting forever for thing to load—Cypress will feel like a lifesaver. & nbsp;

Why? Because Cypress simplifies your testing summons in means that save both time and get-up-and-go. Imagine being capable to test your web app in existent clip, automatically waiting for elements to load, and having a robust puppet that mix seamlessly with modern JavaScript frameworks like React and Angular. It ’ s fast, authentic, and nonsuch for today ’ s agile development workflows. & nbsp;

In this usher, we 'll show you how to do Cypress testing - everything! From the installation to advanced Cypress quiz techniques.

1. What is Cypress?

Technically speaking, Cypress is a mod JavaScript-based end-to-end testing framework contrive to run in the browser using Node.js. It was make specifically for testing web coating, with features orient to frontend developer ' needs. But, let ’ s step out of the tech vernacular for a moment. & nbsp;

In simple terms, Cypress helps you see your website through the eyes of your users. It interacts with your app the way a existent person would—by clicking push, fill out form, and navigating Page. Whether you 're test how your login form handles incorrect passwords or how fast your shopping cart oodles, Cypress is designed to mimic these real-world scenarios​.

And the good constituent? It ’ s all done in real-time, do the process super interactive.

2. Key Features of Cypress

Let ’ s nosedive into what makes Cypress such a potent tool:

  • JavaScript-Based Framework: Cypress is built using JavaScript, which imply it ’ s perfect for developers act in modern web stacks. Most web apps today run on JavaScript, so why not test them in the like language? This eliminates the hassle of dealing with different programme words or configurations. It ’ s but JavaScript all the way​.
  • Automatic Waiting: This is where Cypress truly shines. Say goodbye to those frustrating moments when your tryout fails because the component you ’ re test to interact with hasn ’ t laden yet. Cypress mechanically waits for elements, animations, and API ring to complete before moving on to the succeeding step in your test​.
  • Real-Time Reloading & amp; Time Travel: With Cypress ’ s Time Travel feature, you can hover over each step of your test and see exactly what pass. Pair that with real-time reloading, where alteration to your test file automatically reload the browser, and debug becomes unbelievably intuitive.

3. Setting Up Cypress

Setting up Cypress is surprisingly easy, especially compared to older testing frameworks like Selenium, where multiple configurations are necessary. With Cypress, you can be up and running in just a few steps—no more fumbling around with drivers or complex apparatus. Let ’ s break it down.

Step 1: Installing Cypress as a Dev Dependency

Installing Cypress as a dev dependency ensures it ’ s only utilize in the development environment and not bundled into your production codification. This keeps your product build lightweight and focalize on delivering your app ’ s core functionality, while Cypress stays in your development environment to handle testing.

To do this, open your terminal and get sure you ’ re in the radical directory of the projection you want to test. You can do this with thecd command.

cd /path-to-your-project

Now that you ’ re in your projection directory, install Cypress by go the following command:

 
npm install cypress -- save-dev
 

This command narrate npm to download Cypress and install it as a dev dependency. The-- save-devflag is critical hither because it narrate npm to add Cypress to thedevDependenciessection of yourpackage.jsonfile. This ensures that Cypress is only victimised during growing, create it a best practice in modern web development​.

After installation, affirm that Cypress is establish by checking thenode_modulesdirectory and ensuring thecypressfolder is present. You can also look for Cypress in yourpackage.json underdevDependencies.

Step 2: Launching Cypress

Once Cypress is establish, you can launch it using a simple bid. Run the following command to launch the Cypress Test Runner:

npx cypress exposed

Using npxensures you ’ re running the Cypress executable immediately from yournode_modulesdirectory without needing to install it globally. This is the preferred method because it avoids global dependencies that could conflict with other projects. & nbsp;

Upon running the command, the Cypress Test Runner will launch in a freestanding window. The Test Runner is a optical interface where you can manage, write, and execute your tests in real-time. Think of it as your dictation center for go tests and analyzing their results.

What Happens When You First Open Cypress?

Cypress will automatically create a nonpayment folder structure in your labor, include the following directory:

  • /integration/: This is where your literal trial files go.
  • /fixtures/: Here, you store inactive data used in your tests (like mock API responses).
  • /support/: Contains support files that are automatically include before each test (e.g., custom commands).
  • /plugins/: If you need custom-made plugins or want to extend Cypress ’ s functionality, this is the spot for that.

This directory structure is crucial for organizing your tests, fixtures (bemock datum), and support file. It ’ s designed to keep your tests modular and easy to maintain.

Step 3: Running Your First Test

To help you get started, Cypress includes several example tests right out of the box.

1. Locate Example Tests: Navigate to the/cypress/integration/folder, and you ’ ll find example test file already set up for you. These example tests are a great way to get familiar with Cypress ’ s API and the character of commands you ’ ll be using oftentimes.

2. Run a Test: Simply click on one of the example test files within the Cypress Test Runner, and vigil as Cypress opens a browser and executes the test. You ’ ll see the test steps play out in the browser itself, with each step log in real-time in the Test Runner ’ s bid log.

4. Writing Test in Cypress

Every Cypress test follows a standard structure that includes two core components:describeblocks, which group related tests, anditblocks, which define individual test cases.

Let ’ s face at a light and concise example:

describe ('My First Test ', () = & gt; {it ('Visits a website and checks the title ', () = & gt; {cy.visit ('https: //example.com ') cy.title () .should ('include ', 'Example Domain ')})})

What this code snippet signify:

  • describe (): This is expend to group together multiple related examination example. It ’ s a simple way of logically organise trial, particularly when you have multiple tests cover different features of your application.
  • it(): This defines an individual test cause. Inside each & nbsp;it()block, you line a specific activity or conduct that you want to test. The first argument is the gens of the test, and the second argumentation is a function check the existent test steps.
  • cy.visit (): This command open the specified URL in a browser. Here, we ’ re apply Cypress to visit the & nbsp;https: //example.compage. This is a core Cypress function that ’ s essential for any test that involves pilot to a web page.
  • cy.title () .should (): This is where the real test happens. & nbsp;cy.title ()grabs the title of the current page, and & nbsp;.should()is used to get an assertion. In this case, we ’ re checking that the title of the page includes the text & nbsp;`` Example Domain ''. Assertions like this verify that your app behaves as expect.

Of trend, we recommend that you read throughCypress corroborationto gain deeper sympathy of Cypress syntax. & nbsp;

5. Cypress Testing Best Practices

1. Use Test Isolation & amp; Clean Up State Between Tests

  • Why: Cypress keep the browser ’ s province across trial by nonremittal, meaning that cookies, local storage, and session prevail between test cases. This can do one test 's province to interfere with the adjacent, leading to flaky tests.
  • Best Practice: Each trial should run independently to avoid side effects from prior tests. Use thebeforeEach ()hook to reset the coating state or clear any unrelenting data. Consider resetting the database or test environment between trial if involve, especially for complex applications.
beforeEach (() = & gt; {cy.clearCookies (); cy.clearLocalStorage (); cy.reload ();});

2. Use cy.intercept ()for Network Stubbing

  • Why: Cypress let you to bemock and stub HTTP requests, which speeds up test by avoid unnecessary reliance on actual network responses.
  • Best Practice: Use cy.intercept ()to stub API responses, making tests more stable and faster. You can mock successful reaction or even simulate failure cases. You can screen different scenarios like timeouts, 500 errors, and slow responses applycy.intercept (). This allow you cover various network conditions in a controlled way.
cy.intercept ('GET ', '/api/users ', {fixture: 'users.json '}) .as ('getUsers '); cy.visit ('/users '); cy.wait (' @ getUsers ');

3. Leverage Custom Commands

  • Why: Custom commands help reduce repetition and make tests more readable. They allow you to abstract complex activity into reusable functions.
  • Best Practice: Define usance commands for commonly repeated tasks like login, form entry, or navigating through your app. Group touch custom commands in freestanding files under thesupport/commands.jsdirectory for better organization, and ensure they ’ re well-documented.
Cypress.Commands.add ('login ', (username, password) = & gt; {cy.visit ('/login '); cy.get ('input [name=username] ') .type (username); cy.get ('input [name=password] ') .type (password); cy.get ('button [type=submit] ') .click ();});

4. Utilize Cypress ' Built-In Retry-Ability

  • Why: Cypress automatically retries commands if an averment or activeness fails, ensuring that test don ’ t fail unnecessarily due to temporary conditions like slow UI constituent.
  • Best Practice: Trust Cypress ’ s built-in retry mechanism instead of adding manualcy.wait()commands. Use assertions that leverage this retry power. Minimize the use ofcy.wait(), and if it ’ s necessary, use dynamic waits based on UI changes rather of hardcoded waits. For exemplar, wait for a specific network call to cease usingcy.intercept ()instead of usingcy.wait (5000).
cy.get ('button ') .should ('be.visible ') .click (); cy.url () .should ('include ', '/dashboard ');

5. Run Tests in Parallel and Leverage CI Pipelines

  • Why: Running tests sequentially can be slow, especially in large exam suite. Cypress supports parallel test execution, which speeds up your CI/CD grapevine.
  • Best Practice: Set up parallelization in your CI pipeline using Cypress 's Dashboard Service or third-party CI tools. Configure your CI to dispense tests across multiple machines. Optimize test splitting in your CI grapevine to balance the consignment across parallel instances, and make sure to run high-priority or critical tests in a dedicated suite.
cypress run -- record -- parallel -- group & lt; group-name & gt;

6. Avoid Hardcoding Selectors

  • Why: Hardcoded selectors based on grade names or IDs are prone to breaking if the UI modification. Cypress recommends using data attributes (data-*) for more stable and predictable selectors.
  • Best Practice: Use data-*attributes in your HTML elements specifically for testing. You can create a consistent chooser strategy across your project (e.g., all test-related selectors use thedata-cyprefix). This make tests more maintainable, and ensures that update to the UI don ’ t accidentally break your tests. Let 's say your HTML code for the button is& lt; button & gt; Submit & lt; /button & gt;. Your code can be:
cy.get (' [data-cy=submit-button] ') .click ();

6. Debugging in Cypress

Cypress take the guesswork out of debugging by integrating seamlessly with Chrome DevTools. When a tryout neglect, you don ’ t have to search through endless logs or re-run the exam multiple times to figure out what went wrong. Instead, Cypress gives you real-time feedback, making it easy to pinpoint the exact issue. You can use:

  • Time Travel: Cypress takes snapshots at each step of the test performance. You can hover over each command in the Command Log to see what your app look like at that specific moment.
  • Chrome DevTools Integration: Cypress allows you to directly interact with Chrome DevTools while tests are pass. You can hesitate the test execution, inspect elements, prospect network petition, and footstep through the code.

Cypress too surpass in how it handles test failures. When a exam fails, Cypress doesn ’ t just leave you with a generic error message. It provides a full vestige of the failure, including a elaborated account of the error, a screenshot of the browser at the moment of failure, and even a video of the trial performance if video recording is enabled.

  • Screenshots on Failure: By default, Cypress captures a screenshot whenever a test fails. This screenshot is automatically saved, countenance you to visually inspect the province of the application at the time of failure. This characteristic is particularly useful when diagnose issues in headless test runs, where you don ’ t have a browser window open.
  • Video Recording: In gain to screenshots, Cypress can also record videos of your entire tryout suite execution. If a test betray, you can replay the picture to see exactly what happened.

7. Cypress vs Selenium vs Playwright

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Here 's a quick comparison of Cypress vs other open-source frameworks for you:

Criteria

Cypress

Selenium

Playwright

Primary Language

JavaScript (Node.js)

Multiple (Java, Python, C #, Ruby, JavaScript)

JavaScript, Python, C #, Java

Supported Browsers

Chrome, Firefox, Edge, Electron

Chrome, Firefox, Edge, Safari, IE

Chrome, Firefox, Edge, WebKit

Cross-browser Support

Limited (no Safari or IE)

Full support for all major browser

Full support, including WebKit (for Safari-like behavior)

Setup Complexity

Easy, quick to install with NPM

Moderate, requires WebDriver apparatus

Easy, built-in browser binaries for faster apparatus

Speed

Fast due to direct execution in the browser

Slower due to WebDriver architecture (server-client model)

Fast, like Cypress, due to aboriginal browser control

Test Reliability

High (minimal daftness, automatic waits)

Lower (prone to flakiness, requires explicit waits)

High (robotlike waiting, handle flakiness good)

Parallel Execution

Built-in support through dashboard (paid)

Requires configuration (grid setup)

Built-in support for parallel testing

API Testing

Supports both frontend and API testing within same fabric

Not built-in, expect additional libraries

Supports API essay aboard web testing

Architecture

Runs directly in the browser with Node.js

Uses WebDriver to interact with browser via browser drivers

Direct browser control like Cypress

Debugging Capabilities

Excellent (real-time reloading, time travel, elaborated logs)

Good (browser developer tools, log analysis)

Excellent (tracing, screenshots, network action)

Flakiness

Low, due to contain over browser and machinelike waits

Higher, requires more manual manipulation of waits

Low, automatic handling of delay and retries

Community & amp; Ecosystem

Growing, but small compared to Selenium

Very large, mature, and wide employ

Growing rapidly, strong backing by Microsoft

Peregrine Testing Support

No unmediated support

Supports peregrine testing via Appium

No direct support, but can emulate mobile browsers

Multiple Tabs/Windows

Limited (no multi-tab support)

Full support for multiple tabs

Full support for multiple tabs and browser contexts

Headless Mode

Yes, supports headless way for Chrome, Firefox, Edge

Yes, via drivers

Yes, supports headless mode for all indorse browsers

Integration with CI/CD

Easy integration with Jenkins, GitHub Actions, etc.

Requires more setup

Easy desegregation, built-in tools for CI/CD

Open Source/License

Open-source, with paid features (Dashboard)

Fully open-source

Fully open-source

8. Explore No-code and Low-code Options

Cypress is an amazing model, no doubt. However, you cognize the struggle. & nbsp; We ’ ve all been there—running a test suite that work perfectly one day, only to have it enigmatically fail the next. Flaky tests are those unreliable one that randomly pass or fail, often due to timing issues, async calls, or dependencies on third-party services. They leave you scratching your mind, wondering, “ Did the codification break, or is the test just acting up? ”

Then comes the setup cephalalgia. Cypress is among the easier ones to set up. Some testing fabric require luxuriant setup process with intricate dependencies, browser drivers, and configuration, such as Selenium, precisely getting your surroundings up and running can find like more of a coding project than your actual app ontogeny.

And so when tests miscarry, sometimes you ’ re leave staring at cryptic error logs or labor through endless console messages. Figuring out what went wrong can conduct longer than compose the literal test.

The answer? No-code/low-code testing instrument.

It 's no cant. No-code/low-code testing creature simplify your testing living in so many ways.

1. Faster Test Creation

Traditional code-based testing can be dim, requiring developers to pen test scripts for each scenario. On the former script, Katalon Studio offers up to 3 essay modes for maximum flexibility:

  • No-code: With the Record-and-Playbackfeature, tester can easy record their manual on-screen actions, which are then automatically converted into an executable trial script. This allows testers to replay these recorded activity as frequently as they need, turning manual testing measure into automated tests without writing any code.
  • Low-code:Katalon offers a library ofBuilt-in Keywords, which are essentially pre-written code blocks with customizable parameters. These keywords are designed to execute specific actions, such as the “ Click ” keyword, which contains the internal logic demand to locate an factor (like a button) and accomplish the click action. Testers only take to specify the constituent they want to interact with, without worrying about the rudimentary implementation details.
  • Full-code:For more flexibility, testers can switch toScripting Mode, let them to write test script manually if needed. The beaut of Katalon is that testers can toggle between no-code, low-code, and full-code choice at any point. This multi-mode flexibility entail that testers can bask the convenience of record-and-playback while besides diving into the handwriting when more complex logic is needed. Ultimately, this hybrid approach countenance teams to focalise onwhatto test rather thanhowto pen the test, boosting overall productivity.

2. Low-toned Technical Barrier

No-code/low-code puppet empowernon-technical squad appendagelike QA engineer, job analysts, or yet stakeholders to participate in testing. These tools reduce dependency on the growth team for creating or maintaining tests, making testing more collaborative.

3. Maintenance Made Easy

As codebases evolve, traditional test scripts often interrupt due to changing elements or workflows, leading to eminent test care costs. No-code tools simplify this by profferself-healing tests, where the instrument mechanically adapts to minor modification in the coating ’ s UI or logic.

4. Scalability Without Complexity

No-code tools make it leisurely to scale test reportage without the complexity of writing more codification. You can rapidly make new test by cloning or modifying existing workflows and scale test across multiple surround with minimal effort. In Katalon, you can test across a wide scope of browsers, devices, and operating systems within one place.

 


 

Explain

|

FAQs on Cypress Testing

What is Cypress, and what kind of testing is it primarily built for?

+

Cypress is amodernistic JavaScript (Node.js) -based end-to-end web testing fabricthat runs in the browser and simulates real user actions like clicking, typing, and navigating. & nbsp;

Which common Selenium-style pain point does Cypress specifically try to eradicate?

+

It reduce the hassle ofdriver setup, tackles flaky tests with automatonlike waiting/retry-ability, and speeds feedback by running testsin real clipwith an interactive runner. & nbsp;

How do you instal and launch Cypress, and what project structure execute it create?

+

You install it as a dev dependency withnpm install cypress -- save-dev, so open the runner withnpx cypress open. Cypress generates brochure like/integration (tests), /fixtures(test data),/support(helpers/commands), and/plugins(extensions). & nbsp;

What does a basic Cypress test look like, and which core commands/assertions are highlighted?

+

Tests are organized withdescribe () and it(), habituate commands likecy.visit ()and assertions like.should()(e.g., ensure a page title or URL). & nbsp;

What best practices and debugging features are emphasized for reliable Cypress examination?

+

Best practices includetest isolation (beforeEach), network stubbing withcy.intercept (), custom bid, avoiding hard waits (trust retry-ability), parallel trial in CI, and apply *data-selector (e.g.,data-cy) * *. Debugging highlight includeTime Travel, Chrome DevTools integration, plus automatic screenshots and video tapeon failure.

Contributors
The Katalon Team is composed of a various group of dedicated professionals, include dependent thing experts with deep domain knowledge, experienced technical writers skilled, and QA specialists who wreak a virtual, real-world view. Together, they contribute to the Katalon Blog, delivering high-quality, insightful articles that empower users to do the most of Katalon ’ s tools and stick updated on the latest trends in test automation and software quality.

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