Home Guide Cypress vs Selenium: Key Differences

Cypress vs Selenium: Key Differences

By Jash Unadkat, Technical Content Writer at BrowserStack -

Let’s begin with the most fundamental question.

Why compare Cypress and Selenium?

Cypress and Selenium are test automation tools used for functional testing of web applications by automating browser actions. Selenium has been a widely-used tool for years, whereas Cypress is a recently introduced tool in the test community.

In spite of Cypress being recently introduced, it has gained significant traction with 22k+ Github stars and 530k+ downloads on a weekly basis. With such significant growth in the adoption of Cypress, it’s natural for testers to compare the two before choosing the ideal tool for test automation.

So, the question is, how does Cypress compare to Selenium? Is Cypress a better alternative to Selenium?

An easy way to answer these questions is to evaluate the advantages and limitations of each tool.

Cypress

Cypress vs Selenium

Cypress is a purely JavaScript-based front end testing tool built for the modern web. It aims to address the pain points developers or QA engineers face while testing an application. Cypress is a more developer-friendly tool that uses a unique DOM manipulation technique and operates directly in the browser. Cypress also provides a unique interactive test runner in which it executes all commands.

The official documentation states that Cypress differs fundamentally and architecturally as compared to Selenium.

Using Cypress, QAs or developers can create:

  1. Unit tests
  2. Integration tests
  3. End to End tests

Following the agile methodology, front end developers have started creating their own test cases. JavaScript is a widely used language among the front end developers. 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.

The architectural improvements in Cypress empower testers with the ability to perform Test-Driven Development (TDD) with complete end to end testing. Cypress is developed with the intent to make development and testing a parallel process.

Note: Cypress scripts cannot be executed outside the browser like in Selenium. All Cypress test scripts are executed within the browser. For example, to click on a specific button, Cypress doesn’t send the command to the browser using a specific driver. Instead, it uses the DOM events to send the click command to the button. This results in a much faster execution of test results.

Advantages of Cypress

  1. Cypress captures snapshots at the time of test execution. This allows QAs or developers to hover over a specific command in the Command Log to see exactly what happened at that particular step.
  2. One doesn’t need to add explicit or implicit wait commands in test scripts, unlike Selenium. Cypress waits automatically for commands and assertions.
  3. Developers or QAs can use Spies, Stubs, and Clocks to verify and control the behavior of server responses, functions, or timers.
  4. The automatic scrolling operation ensures that an element is in view before performing any action (for example Clicking on a button)
  5. Earlier Cypress supported only Chrome testing. However, with recent updates, Cypress now provides support for Firefox and Edge browsers.
  6. As the programmer writes commands, Cypress executes them in real-time, providing visual feedback as they run.
    Cypress carries excellent documentation.

Try Cypress Testing Now!

Limitations of Cypress

  1. One cannot use Cypress to drive two browsers at the same time
  2. It doesn’t provide support for multi-tabs
  3. Cypress only supports JavaScript for creating test cases
  4. Cypress doesn’t provide support for browsers like Safari and IE at the moment.
  5. Limited support for iFrames

Now, let’s explore Selenium.

Selenium

Cypress vs SeleniumAs mentioned earlier, Selenium is a popular test automation tool that automates web-browsers. This open-source tool has been a leading choice for testers for over a decade now.

It allows QAs to automate test cases for the desired browser by using the Selenium WebDriver library along with a language-specific framework. Download the browser-specific driver before getting started with browser automation.

Developers and QAs also have the flexibility to choose the programming language of their choice. Selenium developers have developed language bindings for multiple languages like Ruby, Python, Java, etc.

WebDriver uses the JSON wire protocol for executing test cases. At a high level, execution involves three main steps:

  1. Test commands are translated into a URL
  2. Browser Drivers receive these URLs using the HTTP server
  3. The URLs are forwarded as a request to the actual browsers, and all commands in the test scripts are executed.

Refer to this detailed explanation of Selenium WebDriver’s architecture for a better understanding of this operation.

Key Advantages of Selenium:

  1. Compatible with multiple OS like Windows, Linux, Unix, Mac
  2. Provides QAs the flexibility to select the programming language of their choice like Java, Ruby, Python, etc.
  3. Compatible with modern browsers like Safari, Chrome, Firefox, etc.
  4. Provides Concise APIs

Get started with Selenium Testing

Limitations of Selenium:

  1. No built-in command for automatic generation of test results
  2. Handling page load or element load is difficult
  3. Limited support for testing images
  4. Creating test cases is time-consuming
  5. Difficult to set up test environment as compared to Cypress

Cypress vs Selenium: Key Differences

CypressSelenium
Languages SupportedJavaScript OnlySupports all popular languages like Java, Python, Ruby, C#, Php, etc.
Browsers SupportedChrome, Edge, Firefox(beta), ElectronChrome, IE, Safari, Edge, Firefox, Opera
Frameworks SupportedSupports only Mocha JS Supports multiple frameworks based on specific programming languages. (For e.g: JUnit for Java, Cucumber for JavaScript, etc.) 
Setup ComplexitySetup is simple. No dependencies or additional downloads requiredSetup is a bit challenging as it requires downloading browser-specific drivers and setting up the test environment
Documentation & Community SupportVery intuitive documentation along with  rapidly growing communityWell established documentation and firm community support from users across the globe

Although Selenium and Cypress are both designed to automate browsers for testing purposes, they differ considerably in terms of architecture and performance. A key difference is that Cypress as a tool is ideal for introducing developers to test automation rather than just a replacement for Selenium. This is why Cypress is among the fastest-growing automation tools in the world. On the other hand, Selenium is a more general-purpose tool targeted at a broader audience.

Needless to say, prior to choosing an automation tool, one must weigh the pros and cons of every option. Spend some time automating a few test cases on a cloud-based platform like BrowserStack that offers integration with both Cypress and Selenium.
This will help evaluate which tool works best to serve the team and organization in the long term.

BrowserStack Logo Run Cypress Tests on 30+ Browser Versions Get Started Free