How Cypress Works | End to end and component testing tools (2024)

cy.get()

cy.find()

cy.debug()

cy.visit()

cy.mount()

cy.click()

cy.type()

cy.pause()

cy.within()

cy.contains()

cy.each()

cy.dblclick()

cy.get()

cy.find()

cy.debug()

cy.filter()

cy.eq()

cy.clearCookie()

cy.pause()

cy.end()

cy.within()

cy.contains()

cy.each()

cy.within()

cy.contains()

cy.eq()

cy.end()

cy.filter()

cy.clearCookie()

cy.visit()

cy.mount()

cy.click()

cy.type()

cy.within()

cy.contains()

cy.eq()

cy.end()

cy.each()

cy.dblclick()

cy.get()

cy.find()

cy.debug()

cy.each()

cy.dblclick()

cy.visit()

cy.mount()

cy.click()

cy.type()

cy.get()

cy.find()

cy.debug()

cy.filter()

cy.clearCookie()

cy.get()

cy.find()

cy.debug()

cy.within()

cy.mount()

cy.contains()

cy.visit()

cy.type()

cy.click()

cy.within()

cy.contains()

cy.visit()

cy.mount()

cy.click()

cy.type()

cy.filter()

cy.filter()

cy.clearCookie()

cy.pause()

cy.contains()

cy.filter()

cy.eq()

cy.end()

cy.eq()

cy.end()

cy.each()

cy.filter()

cy.dblclick()

cy.clearCookie()

cy.each()

cy.dblclick()

cy.eq()

cy.end()

cy.get()

cy.find()

cy.debug()

cy.pause()

cy.filter()

cy.clearCookie()

cy.pause()

cy.eq()

cy.end()

Testing has been broken for too long—so we decided to fix it. Cypress makes setting up, writing, running and debugging tests easy for developers.

Start testing today

How Cypress Works | End to end and component testing tools (1)

How do I run a test?

Choose a framework

Mocha, Jasmine, QUnit, Karma

Configure

Selenium, Playwright

Choose a Selenium wrapper

Nightwatch, Webdriver

Choose an assertion library

Chai, Expect.js

Add additional libraries

Sinon, TestDouble

Install Cypress

An all-in-one testing framework, assertion library, with mocking and stubbing.

Testimonials

Can't say enough about @Cypress_io! Makes testing modern and legacy code a snap. The GUI tools are amazing and the CLI just works.

How Cypress Works | End to end and component testing tools (2)

Nick DeNardis, Sr. Dir of Digital, Wayne State University

7 ways Cypress is different

Since its introduction, Cypress has quickly become the most developer-loved automated testing framework for modern web applications.

Cypress does not use Selenium.

Most end-to-end testing tools are Selenium-based, which is why they all share the same problems. To make Cypress different, we built a new architecture from the ground up. Whereas Selenium executes remote commands through the network, Cypress runs in the same run-loop as your application.

Cypress focuses on doing end-to-end testing REALLY well.

Cypress is not a general automation framework, nor is it a unit testing framework for your back end services. There are already great tools out there that do that. Rather, we specialize in one thing - creating a great experience while you write end to end tests for your web applications.

Cypress works on any front-end framework or website.

Cypress tests anything that runs in a web browser. All of the architecture surrounding Cypress is built to handle modern JavaScript frameworks especially well. We have hundreds of projects using the latest React, Angular, Vue, Elm, etc. frameworks. Cypress also works equally well on older server rendered pages or applications.

Cypress tests are only written in JavaScript.

While you can compile down to JavaScript from any other language, ultimately the test code is executed inside the browser itself. There are no language or driver bindings - there is and will only ever be just JavaScript.

Cypress is all in one.

Writing end-to-end tests takes a lot of different tools to work together. With Cypress you get multiple tools in one. There is no need to install 10 separate tools and libraries (ie: Mocha, Jasmine, QUnit, Karmato, Protractor, Nightwatch, Webdriver, Selenium, Chai, Expect.js, Sinon, TestDouble) to get your test suite set up. We have taken some of the best-in-class tools you are likely already familiar with and made them all work together seamlessly.

Cypress is for developers and QA engineers.

One of our goals was to make test-driven development a reality for end-to-end testing. Cypress is at its best when you use it as you build your application. We give you the power to code as fast as possible.

Cypress runs much, much faster.

These architectural improvements unlock the ability to do TDD with full end-to-end tests for the very first time. Cypress has been built so that testing and development can happen simultaneously. You can develop faster while driving the entire dev process with tests because: you can see your application; you still have access to the developer tools; and changes are reflected in real time. The end result is that you will have developed more, your code will be better, and it will be completely tested. If you use Cypress Cloud, parallelization and automated load balancing will further supercharge your test speeds.

Key difference

for those wanting to understand a bit more...

The architecture is completely different.

Most testing tools operate by running outside of the browser and executing remote commands across the network. Cypress is the exact opposite. Cypress is executed in the same run loop as your application. Behind Cypress is a Node.js server process. Cypress and the Node.js process constantly communicate, synchronize, and perform tasks on behalf of each other. Having access to both parts (front and back) gives us the ability to respond to your application’s events in real time, while at the same time work outside of the browser for tasks that require a higher privilege.

Cypress also operates at the network layer by reading and altering web traffic on the fly. This enables Cypress to not only modify everything coming in and out of the browser, but also to change code that may interfere with its ability to automate the browser.

Cypress ultimately controls the entire automation process from top to bottom, which puts it in the unique position of being able to understand everything happening in and outside of the browser. This means Cypress is capable of delivering more consistent results than any other testing tool.

Because Cypress is installed locally on your machine, it can additionally tap into the operating system itself for automation tasks. This makes performing tasks such as taking screenshots, recording videos, general file system operations and network operations possible.

Cypress has native access to everything.

Because Cypress operates within your application, that means it has native access to every single object. Whether it is the window, the document, a DOM element, your application instance, a function, a timer, a service worker, or anything else - you have access to it in Cypress. There is no object serialization, there is no over-the-wire protocol - you have access to everything at your fingertips.

A whole new kind of testing is possible.

Having ultimate control over your application, the network traffic, and native access to every host object unlocks a new way of testing that has never been possible before. Instead of being ‘locked out’ of your application and not being able to easily control it - Cypress instead lets you alter any aspect of how your application works. Instead of incredibly slow and expensive tests such as creating the state required for a given situation - you can simply create these states artificially like you do in an unit test. For instance you can:

  • Stub the browser or your applications functions and force them to behave as needed in your test case.
  • Expose data stores (like in Redux) so you can programmatically alter the state of your application directly from your test code.
  • Test edge cases like ‘empty views’ by forcing your server to send empty responses.
  • Test how your application responds to errors on your server by modifying response status codes to be 500.
  • Modify DOM elements directly - like forcing hidden elements to be shown.
  • Use 3rd party plugins programmatically. Instead of fussing with complex UI widgets like multi selects, autocompletes, drop downs, tree views or calendars, just call methods directly from your test code to control them.
  • Prevent Google Analytics from loading before any of your application code executes when testing.
  • Get synchronous notifications whenever your application transitions to a new page or when it begins to unload.
  • Control time by moving forward or backward so that timers or polls automatically fire without having to wait for the required time in your tests.
  • Add your own event listeners to respond to your application. You could update your application code to behave differently when under tests in Cypress. You can control websocket messages from within Cypress, conditionally load 3rd party scripts, or call functions directly on your application.
You can programmatically take shortcuts.

Trying to test hard to reach areas of your application? Don’t like the side effects an action creates? Tired of repeating the same repetitive and slow actions over and over again? You can simply skip them all. Cypress prevents you from being forced to always ‘act like a user’ to generate the state of a given situation. With Cypress you can programmatically interact and control your application. You no longer have to use your UI to build up state!

That means you no longer have to visit a login page, type in a username and password and wait for the page to load and/or redirect. Cypress gives you the ability to take shortcuts and programmatically log in. With commands like cy.request(), you can send HTTP requests directly, yet have those requests synchronized with the browser. Cookies are automatically sent and applied back. Worried about CORS? Don’t be, it’s completely bypassed. The power to choose when to test like a user and when to skip slow and repetitive parts is yours.

Cypress is not flaky.

Cypress knows and understands everything that happens in your application synchronously. It’s notified the moment the page loads, the moment the page unloads. It’s impossible for Cypress to miss elements when it fires events. Cypress even knows how fast an element is animating and will wait for it to stop! Additionally, it automatically waits for elements to become visible, to become enabled, and to stop being covered. When pages begin to transition, Cypress will pause command execution until the following page is fully loaded. You can even tell Cypress to wait on specific network requests to finish.

Cypress executes the vast majority of its commands inside the browser, so there is no network lag. Commands execute and drive your application as fast as its capable of rendering. To deal with modern JavaScript frameworks with complex UI’s, you use assertions to tell Cypress what the desired state of your application is. Cypress will automatically wait for your application to reach this state before moving on. You are completely insulated from fussing with manual waits or retries. Cypress automatically waits for elements to exist and will never yield you stale elements that have been detached from the DOM.

Debuggability is first class.

Above all else Cypress has been built for usability. There are hundreds of custom error messages describing the exact reason Cypress failed your test. There is a rich UI which visually shows you the command execution, assertions, network requests, spies, stubs, page loads, or URL changes. Cypress takes snapshots of your application and enables you to time travel back to the state it was in when commands ran. You can use the Dev Tools while your tests run, you can see every console message, every network request. You can inspect elements, and you can even use debugger statements in your spec code or your application code. There is no fidelity loss - you can use all the tools you’re already comfortable with. This enables you to test and develop all at the same time. If you’re using Cypress Cloud, you have access to even more detailed insights on your tests’ performance, helping you to optimize your runs, and ship faster with more confidence.

Didn't find what you're looking for?

Check out Learn Cypress, search our docs, or browse the FAQs.

Learn Cypress Level up your testing knowledge in our all-new program focusing on the most practical elements of testing.Documentation Our super thorough docs show you how to use and troubleshoot Cypress, step by step.FAQs Not finding what you need in our docs? We may have answered your question in our FAQs.

Ready to try Cypress?

Fast, easy and reliable testing for anything that runs in a browser.
Install Cypress in seconds and take the pain out of front-end testing.

How Cypress Works | End to end and component testing tools (2024)

FAQs

How Cypress Works | End to end and component testing tools? ›

Cypress runs end-to-end tests the same way users interact with your app by using a real browser, visiting URLs, viewing content, clicking on links and buttons, etc. Testing this way helps ensure your tests and the user's experience are the same.

How does Cypress component testing work? ›

Cypress Component Testing works out of the box with Create React App, Next. js, Vite, and a custom Webpack config. Cypress will automatically detect one of these frameworks during setup and configure them properly. The examples below are for reference purposes.

What is the difference between end to end and component testing in Cypress? ›

End-to-end tests are more comprehensive, slower, and more prone to flakiness than component tests. Component tests are specialized, quick, and reliable. Because of the scope, end-to-end testing often requires a complex set-up phase. No complicated configurations are needed for component tests.

How does the Cypress framework work? ›

It is an all-in-one testing framework that unifies the whole testing process within a single tool in order to make it easier for developers and QA analysts to work. This means that Cypress allows you to write, configure, run, and debug tests with less effort.

What is the difference between component testing and unit testing in Cypress? ›

Benefits of Cypress Unit Testing

In End-to-End testing, the Cypress test flow usually tests the application's overall performance from the front end to the back end, along with the middle operating layers. On the contrary, component testing mounts and test a single component attached to an application.

What is the execution flow of Cypress? ›

As we told in advance, every Cypress command is asynchronous by default. That means that Cypress executes the test code twice: the first time Cypress executes the test code to read and queue all the commands it needs to execute. then Cypress loads the page, and executes, one by one, all the command previously queued.

How does end to end testing work? ›

End-to-end testing is a software testing technique that verifies the functionality and performance of an entire software application from start to finish by simulating real-world user scenarios and replicating live data.

Is Cypress good for end to end testing? ›

End-to-End (E2E) testing is designed to ensure that all components of a software application are working together correctly and that the system as a whole meets the desired functionality, performance, and reliability requirements. Cypress is a popular open-source end-to-end testing framework for web applications.

Which is better for E2E testing Selenium or Cypress? ›

Selenium is more established and has a wider range of capabilities, making it a good choice for large-scale testing projects. Cypress is newer and easier to use, making it a good choice for smaller teams or projects that only require a little cross-browser testing.

What language is used in Cypress testing? ›

The fact that Cypress is purely based on JavaScript indicates how this tool is designed to meet the needs of front-end developers in particular. Naturally, one needs to be proficient in JavaScript before getting started with Cypress testing.

How to login programmatically in Cypress? ›

Programmatic Login​

The loginByAuth0Api command will execute the following steps: Use the /oauth/token endpoint to perform the programmatic login. Finally the auth0Cypress localStorage item is set with the access token , id_token and user profile.

How does Cypress run tests? ›

Most end-to-end testing tools are Selenium-based, which is why they all share the same problems. To make Cypress different, we built a new architecture from the ground up. Whereas Selenium executes remote commands through the network, Cypress runs in the same run-loop as your application.

How to explain Cypress framework in interview? ›

Cypress is a modern digital front-end testing tool that is fully based on JavaScript. Its purpose is to make it easier for developers and QA engineers to test an application. Cypress is a more developer-friendly tool that works directly in the browser and employs a novel DOM modification method.

How to use Cypress component testing? ›

How to perform Component Testing using Cypress
  1. Step 1: Create a sample react application.
  2. Step 2: Install the required dependencies.
  3. Step 3: Install the Cypress test automation tool for component testing.
  4. Step 4: Open the Cypress.
  5. Step 5: Configure Component Testing in Cypress.
  6. Step 6: Create a Sample React Component.
Oct 3, 2022

How does Cypress handle promises? ›

Cypress is promise aware so if you return a promise from inside of commands like . then() , Cypress will not continue until those promises resolve.

What is the difference between component testing and unit testing? ›

Component testing: It involves analyzing multiple functions and code modules before they form software. It is a black box testing technique that evaluates the application without considering the code information. Unit testing: Developers perform Unit testing to ensure all the smaller code units function correctly.

How to do component testing? ›

Component Testing Process
  1. Step1: Requirement Analysis. ...
  2. Step2: Test Planning. ...
  3. Step3: Test Specification. ...
  4. Step4: Test Implementation. ...
  5. Step5: Test Recording. ...
  6. Step6: Test Verification. ...
  7. Step7: Completion.

What kind of testing does Cypress do? ›

Cypress is an automation web testing tool that's fast, easy, and reliable for testing the things (web components) that run in a browser. It's an open-source test automation framework for testing JavaScript web and enables you to perform unit, integration, and end-to-end tests.

Top Articles
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5997

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.