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 such a 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? Like Selenium, Cypress is also an open-source test automation framework for testing web applications. And that’s where the big Cypress vs Selenium fight begins!
Point of Difference | Selenium | Cypress |
---|---|---|
Language Supported | Supports all popular languages like JavaScript, Java, Python, Ruby, C#, Php, etc. | Support JavaScript Only |
Browsers Supported | Chrome, IE, Safari, Edge, Firefox, Opera | Chrome, Edge, Firefox, Electron, Brave. In Version 10.8.0 Safari browser support is added using Playwright-Webkit. |
Framework Supported | PyUnit, JUnit, TestNG, JBehave, Behave, Gauge, Specflow, NUnit, Robot, Mocha and more. | Supports only Mocha JS |
Setup Complexity | Setup is a bit challenging as it requires downloading browser-specific drivers and setting up the test environment. Selenium Grid Server and browser drivers have to be installed in the test machine. Even, setup is different for a cloud-based Selenium Grid where only browser drivers have to be installed on the test machine. | Setup is simple. No dependencies or additional downloads required. Node JS, Mocha JS, and Cypress have to be installed on the test machine. |
Integration with Other tools | Wide range of integration options – CI/CD tools, reporting tools, and more. | Limited integration support with CI/CD tools when compared to Selenium. |
Driver Dependencies | Appropriate browser driver has to be installed so that the test script can talk to the corresponding web browser. | No driver dependency |
Multiple Tabs | Supported | Not Supported - Workaround present |
Multiple Browser Instances or Domains | Supported | Not Supported - Workaround present |
iFrame | Supported | Not Supported - workaround present |
Execution Speed | Slow | Fast |
Automatic Waiting | Not Supported | No requirement to add waits or sleep in the tests. Cypress automatically waits for commands and assertions before moving to the next instruction. |
Default Screenshots and Videos | Not Supported, write code for support | Supported by default |
Network traffic Control | Not Supported - Workaround present | No network lag as tests are executed within the browser. You can control, stub, and test edge cases without any involvement of the server. |
Access to elements outside the DOM | Access only to the elements in the DOM | A unique DOM manipulation technique helps Cypress in getting access DOM elements, timers, service workers, and more. |
Documentation & Community Support | Well established documentation and firm community support from users across the globe | Very intuitive documentation along with rapidly growing community |
Remote Execution | Supported. Cloud-based Selenium Grid from LambdaTest can be used to expedite cross browser testing and automation testing. | Not Supported |
Mock Server, Spies, stubs, and clocks | Not Available | Cypress has built-in facilities for mocking server responses, facilities that are crucial for their target audience: frontend developers. Cypress lets you control the behavior of functions, timers, and server responses with ease. |
Mobile Testing | Mobile Testing with Appium | Not Supported |
Test Flakiness | Tests can be flaky | With Cypress, tests are expected to be non-flaky. Because the tests on it are executed frontend only, with a mocking of all server responses, the test runs very fast. And the faster a browser test runs, the less flaky it is. |
Time Travel | Not Supported | Supported. Once the test ends, you can click on each command in the side panel, and you can see a screenshot of how the page looked like when the command was executing. This is called Time traveling. |
Real Time reloads | Not supported | Tests are reloaded when any change is made in the test implementation. |
Asynchronous | No | Yes, cypress commands are asynchronous |
Although Selenium and Cypress are both designed to automate browsers for testing purposes, they differ considerably in terms of architecture and performance.
If your web application is built using modern JavaScript frameworks like React or Angular or any other JavaScript framework. and cross browser testing is not of high priority, Cypress might suit the best. When it comes to cross browser testing, Selenium is still the de-facto framework used by many users.
There is no clear winner in the Cypress vs Selenium debate. A better approach would be evaluating both the tools and seeing how Selenium and Cypress can be used to improve test coverage for your project.
Needless to say, prior to choosing an automation tool, one must weigh the pros and cons of every option.