Cypress framework as an alternative for Selenium: a comprehensive comparison

Anton Bravin
Updated on
Apr 22, 2024
reading time
Try now

Cypress is one of the fastest-growing automation tools in the world today. It has made a splash in the world of functional test automation since its introduction in 2014. Whereas Selenium is an open-source tool that has been the best choice for test automation engineers for over fifteen years now.

This is the big question: should you choose Cypress & can it replace Selenium? Let's compare these two powerful tools standing out from the large list of test automation frameworks available on the market.

Introducing Cypress and Selenium

Cypress is a new-generation front-end testing tool designed for contemporary web applications. It represents a JavaScript-based end-to-end testing framework built on top of Mocha & Chai. It is a relatively young tool, but it brings new concepts and solutions to the way automation & testing is done. The key feature of Cypress is that it runs inside the browser itself. It also signifies that Cypress always monitors when any kind of events are triggered in the browser and never misses any manipulations with page elements, which greatly reduces the likelihood of flaky tests. Cypress can be used to automate all kinds of tests, including unit, functional, component, and end-to-end tests.

Selenium is a general-purpose testing framework used to automate the web browser.  Selenium is supported by almost all possible platforms and browsers. The list of supported languages ​​is impressive, there is even the old Perl, Ruby, not to mention C#, Python, Java and, of course, JS. In addition to standard Windows and Linux, supports Mac OS and even Solaris.

Cypress vs. Selenium: major differences

Architecture

Cypress operates in a single application run cycle. Node server process stands behind Cypress. The Cypress and Node.js processes are consistently interacting, synching, and implementing tasks together. Access to front-end & back-end enables responding to the app's requests in real-time, and at the same time performing job outside the browser on priority tasks. Cypress can read & modify web traffic instantly. This lets us not only amend everything that goes in and out of the browser but also modify code that could intervene with its ability to automate the browser.

Test execution architecture of Cypress

Selenium works by performing outside the browser and running remote commands over the network.

Test execution architecture of Selenium

There are huge differences in architecture between Cypress and Selenium. Cypress does not have many restrictions, which makes it faster and easier when it comes to automation scripts.

Performance

Selenium was developed in 2004 when web applications were quite simple, and this is where its major constraint stems from. Modern apps are becoming more & more complex. They have sophisticated functionality & dynamic rendering for better UX. Selenium has difficulties in processing current dynamic web elements, which considerably lowers the performance of test execution, leads to unstable test execution & the occurrence of flaky tests.

Cypress is famous for its incredibly fast test execution — most responses will be sent back in less than 20ms. Cypress identifies auto-await, where it waits for DOM elements to terminate loading or any animation to finish rendering, and only then it searches for a web element. In Selenium there is a necessity to define implicit and explicit wait for the page to finish loading. Wait & sleep commands can be applied in Selenium, but this will significantly influence on the performance of test execution.

Installation complexity

Cypress setup is quite easy. You can install it without any dependencies simply using npm or Yarn. As soon as the framework is installed, you can teach any engineer to execute their tests in a very short amount of time.

In Selenium, you have to choose all the necessary dependencies and libraries before testing. Certainly, today Selenium already has frameworks that can be installed with one command and a couple of choices. But what speaks in favor of the first is that you do not even need to set up a browser, since it already comes out of the box. 

Supported languages 

Cypress supports only JavaScript automation. There is no support for other languages, which sometimes forces the user to learn a particular scripting language. You will not be able to write Cypress tests in statically typed languages ​​like C# and Java.

As far as Selenium is concerned, it supports almost all known languages including JavaScript, Python, Perl, PHP, Ruby, C#. This means that almost every junior engineer can work with it completing the courses.

Supported browsers

Using Cypress you can verify your app on the following browsers: Chrome, Edge, Electron, and Firefox.

In addition to the above-mentioned browsers, Selenium can boast support for Internet Explorer & Safari.

Supported OS

Cypress supports the following operating systems: Windows, Mac, and Linux.

Including the above-stated OS Selenium can be used for automated testing of web apps on a huge range of Android & iOS devices. 

Licensing

Selenium is licensed under the Apache 2.0, it is fully open-source and all its features can be used 100%.  It can be easily adapted to the project & scaled according to the needs.

Cypress is also open-source, however available under the MIT license. In comparison to Selenium, not all Cypress functionality is free. For example, debugging features (video playback & screenshots) or flake management are not included in a free plan.

Documentation & community support

Selenium is the industry standard with a wide range of online resources and a huge community to rely on.

Cypress community is young but it constantly expands so there will be more and more resources available. 

What makes Cypress attractive to users

There are many unique features that make Cypress one of the most adaptable web automation solutions out there. There are a few of them:

  • User-friendly architecture. Thanks to this the platform provides fast and stable test execution compared to other automation tools.
  • Clear API. The API provided by Cypress is simple and straightforward. All commands are combined into chains, which makes it easier to read code and write tests.
  • Time travel. Takes snapshots when running tests.
  • Auto-await. Cypress automatically waits for elements to appear before performing any action on them. This makes the code more robust and easier to write.
  • Debuggability. Cypress allows you to debug tests using familiar tools such as Developer Tools. Readable errors and stack traces make debugging very convenient.
  • Screenshots and Videos. There is a paid feature to capture screenshots when performing tests, as well as a video of the entire test suite; launched from the command line.
  • Stubs and Network Traffic Control. Capability to test edge test cases by simulating a server response (network requests).

In addition to all of the above, Cypress has changed the perception of how the development of a test automation system took place. This is very clearly seen in the figure below.

End-to-end testing

Cypress weaknesses

Despite the numerous advantages, there are also drawbacks, more related to the fact that Cypress is a specialized tool, not a general-purpose tool as it is said on Cypress official website.

  • Since Cypress runs inside the browser, there is no support for external functionality such as popups, tabs, and so on.
  • There is no possibility to use Cypress to drive two browsers simultaneously as well as there is no support for numerous browser tabs.
  • Testing mobile versions of browsers or native applications — cannot be automated in Cypress.
  • Cross-browser testing — there are no such wide possibilities as in Selenium (which is the benchmark from this point of view).

Key findings

It is incorrect to conclude which tool is better based only on the comparison criteria. It is more reasonable to determine the degree of importance of each of the points for your particular project and, based on this, make a choice. 

For example, if the project has a lot of unit testing, integration and E2E testing, then Cypress is better. Or let's say your project is a marketplace with big traffic. In this case, the issue of cross-browser compatibility will be the highest priority for you and the choice may shift towards Selenium especially if your staff has experienced developers & test automation engineers who can deal with Selenium.

Cypress is great for front-end integration testing by developers, while Selenium can be an excellent choice to automate the browser, as part of your product, rather than test automation. Everything depends on your project, its objectives and resources. 

About the author

Anton Bravin

Product Marketing Manager

8 years on a mission to bridge the gap between cutting-edge products and the audiences who need them most. Anton speaks the languages of developers and customers, allowing him to craft compelling narratives showcasing true value.