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.
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 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.
Selenium works by performing outside the browser and running remote commands over the network.
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.
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.
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.
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.
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.
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.
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.
There are many unique features that make Cypress one of the most adaptable web automation solutions out there. There are a few of them:
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.
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.
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.