Cypress vs Selenium
Tags: cypress, selenium, automation, testing
Published: 2020-08-03 12:12:42

From the vast list of automation testing tools available in the market, we will contend the two most promising tools that are contemplated as game-changers.

So here’s the million-dollar question: Whether Cypress is better than or a substitute for the most preferred web automation tool – Selenium?

This article will do an in-depth comparison to show how both tools serve the purpose of automation testing and which tool has the upper hand in different circumstances.

Let’s look at a few points that will help you make the call:

In a Nutshell

Cypress (latest release 4.11.0) is a next-generation front-end testing tool built for the web. It is a JavaScript-based end-to-end testing framework built on top of Mocha and Chai.

Selenium (latest release 4.0.0 Alpha 5) is an open-source tool used for automating the tests on web browsers. The Selenium WebDriver drives a browser natively; either locally or on remote machines and it is used for UI automation testing. Similarly, all the other components have a specific role to perform in terms of making the product more reliable and robust.

How does it work?

Cypress executes in the same run loop as application. Behind Cypress is a Node.js server process. Cypress and the Node.js process constantly communicate, synchronize, and perform tasks for each other. Cypress also operates at the network layer by reading and altering web traffic during processing. This enables Cypress to not only modify everything that emerges from the browser but also to change code that may interfere with its ability to automate the browser.

In Selenium, once we run the automation script in Selenium then the Selenium client library will communicate with Selenium API that will send the command taken from language level binding to browser driver with the help of JSON wire protocol. The browser driver will use the HTTP server for getting the HTTP request and the HTTP Server filter out all the commands that require execution. After that, the commands in your Selenium script executes on the browser and HTTP server sends the response back to the automation test script.

Based on their internal working architecture, we can say that Selenium executes remote commands through the network whereas Cypress runs in the same run-loop as your application.

Installation

In Cypress there’s no configuration, just need to install the .exe and all the drivers and dependencies get automatically installed and configured. This allows automation to be set up to get running in minutes. One of the design principles of Cypress was to be able to package and bundle everything together to make the entire end-to-end testing experience pleasant and simple for developers.
To use Selenium in your automation project you need to install the language binding’s libraries for your language of choice. Besides, you will need WebDriver binaries for the browsers you want to automate and run tests on.

So if we take installation time and complexity into consideration then Cypress has the upper hand as compared to Selenium.

Languages Supported

Cypress only supports JavaScript. No other languages support provided, which sometimes forces the user to learn a particular scripting language.

On the other hand, Selenium supports wide range language: Java, C#, Python, Ruby, R, Dart, Objective-C, Haskell, PHP, and JavaScript.

Due to the support of many languages, Selenium comes handy and gives users the privilege to decide the language they want to use to develop an automation framework.

Cross-browser Support

Cypress supports Canary, Chrome, Chromium, Edge, Edge Beta, Edge Canary, Edge Dev, Electron, Firefox (Beta support), Firefox Developer Edition (Beta support), Firefox Nightly (Beta support).
Selenium supports almost all major browsers in the market, which is an added advantage for Selenium. Below is the list of supported browsers:

Chrome(All versions), Firefox(54 and newer), Internet Explorer(6 and newer), Opera(10.5 and newer), Safari(10 and newer)

Selenium has better cross-browser support as compared to Cypress because Selenium gives support to almost all available browsers available in the market whereas Cypress you can’t test on Safari.

Parallel Execution of Test Automation Suite

Cypress falls behind when compared to Selenium in parallel testing.

Selenium has many options to perform parallel execution which is quite important for automation testing. Selenium component Grid is used widely for parallel execution in the QA community with TestNG. And it can be easily integrated with Docker containerization.

Performance

Cypress doesn’t have as many layers of architecture as Selenium. It operates on the same process in the browser. That is why we see a remarkable improvement in the pace of test execution compared to Selenium.

Selenium is relatively slow compared to Cypress as it has several layers of code running between the test and the browser.

Integration of Automation with CI/CD

Cypress: Possible but with restrictions. Only one option is available and that is by using the command line and the npm library – Mocha. The CI service has to support npm and test recording on the CI server is a paid option for most of the recordings.

Selenium: Possible to perform integration of CI/CD. We can use any testing library, test reports, and execution patterns and can easily adjust it to the needs.

Licensing

Cypress is also released as open-source under the MIT license. But if we compare it to Selenium then all the features provided by Cypress are not free, e.g. the dashboard in Cypress is free for Seed but paid for Sprout, Tree, and Forest. (https://www.cypress.io/pricing)

Selenium is licensed under the Apache 2.0 license, with the Software Freedom Conservancy as the copyright holder

OS Support

Cypress: Windows, Mac, Linux
Selenium: Windows, Linux, Mac, Android, iOS

BDD and DataDrivenTesting Support

Selenium supports BDD and data-driven by using external libraries, but as of now which is quite not possible to do in Cypress.

Locators for Object Identification

Cypress supports only CSS and Xpath.

Support all types of locators for a normal web application like ID, Name, XPath, CSS selectors, link text, partial link text, etc.

Execution Report

Selenium: Allure, Extent, and all other dashboards can be integrated into automation suites.

Cypress: Only Cypress Native Dashboard.

The Verdict

Selenium targets more towards the test automation engineer while Cypress is more developer-centric and aims to improve TDD development.

Selenium was developed in 2004 so it has better community support then Cypress which was developed in 2015 and still in the growing phase. In-fact when we work with the browser using Selenium it is possible to manipulate many options like Cookie, Local Storage, Screen, Sizes, Extensions, Command-line options but Cypress can only help to manipulate Network options.

However, some of the selling points, which Cypress claims, are:

•	It can take snapshots of the application when the tests are running. Then as a test developer, we can hover over each command in the Test Runner panel to see what happened at each step.
•	With Cypress, there is no need to put explicit waits or sleeps to your tests. It automatically waits for commands and assertions before proceeding.
•	Similar to unit test cases, you can verify and control the behavior of functions, server responses, or timers at run time using the spies and stubs provided by Cypress. Using Cypress, you can stub network traffic as you like and customize the response of your API calls as per your need.

Hope the above points will help to decide which tool to use for automation testing and on that note keep exploring. If you have any questions or suggestions email us at info@cloudqa.io or visit Cloud QA website.