Cypress vs Selenium — Which Is Better?

Thimmaraju G
Version 1
Published in
7 min readJun 23, 2022

When it comes to automation testing tools, both Cypress and Selenium are powerful tools used by software testers. Both have their pros and cons, but which one is the best tool for your needs?

In this post, we will compare Cypress vs Selenium and explore which tool is better for your needs. Let us get started!

The following topics will be discussed:

  • What Is Cypress?
  • Reasons to Use Cypress
  • Advantages of Cypress
  • Disadvantages of Cypress
  • What Is Selenium?
  • Reasons to Use Selenium
  • Advantages of Selenium
  • Limitations of Selenium
  • Compare Cypress and Selenium
  • Who are the target audience for Cypress and Selenium?
  • Will Cypress replace Selenium
  • Conclusion

What is Cypress?

Cypress is a web-built test platform for the next generation. It was developed on Mocha and Chai and it is a JavaScript-based end-to-end Test Platform. Cypress is a web test automation framework, that helps developers and testers to create web automation scripts using JavaScript. Due to Cypress being JavaScript based, it is very popular in the Developer audience as well.

Cypress is generally compared with Selenium, but their architecture are different. Cypress doesn’t have as many restrictions in comparison to Selenium, which makes Cypress a faster and easier way to create automation web scripts. Using Cypress, anything can be tested when running on a Browser, following testing can be automated by Cypress

· Unit testing
· Integration testing
· End-to-end testing

Reasons to Use Cypress

  1. Cypress gives a fast and stable test execution compared to other automation tools because of its Architectural design.
  2. Cypress has a feature of screenshot capturing while test execution, it can also capture the video of test suite, if it is running from the command line Interface.
  3. In the Developer tools section, it gives debugging option which helps developers to debug fast and easily.
  4. Unlike other tools where wait and sleep are used to achieve synchronization in test runs, Cypress has inbuilt feature which waits by default until next actions and also waits before moving to the next step.
  5. In Cypress, we can see the response time of an activity, which is very useful from a unit testing perspective.
  6. Cypress can be used with CI tools [Continues Integration tools-Jenkins].
  7. With the help of the Viewport sizing feature, Cypress can check the responsiveness of a web page.
  8. Cypress provides test case status in a clear format, it displays the count of test cases which are passed or failed.
  9. Cypress has a good capability of error logging, which clearly describes the reason for any error or failure.
  10. Cypress has good documentation support, which helps developers and testers to write critical tests.

Advantages of Cypress

  1. Most end-to-end testing tools are Selenium-based, which is why they all share the same problems. To make Cypress different, it has built a new architecture from the ground up. Whereas Selenium executes remote commands through the network, Cypress runs in the same run-loop as your application.
  2. Cypress tests anything that runs in a web browser. All of the architecture surrounding Cypress is built to handle modern JavaScript frameworks especially well. We have hundreds of projects using the latest React, Angular, Vue, Elm, etc. frameworks. Cypress also works equally well on older server-rendered pages or applications.
  3. Using Cypress API testing can be done, which is not possible in other open-source web automation tools.
  4. Most testing tools operate by running outside of the browser and executing remote commands across the network. Cypress is the exact opposite. Cypress is executed in the same run loop as your application. Behind Cypress is a Node.js server process. Cypress and the Node.js process constantly communicate, synchronize, and perform tasks on behalf of each other. Having access to both parts (front and back) gives us the ability to respond to your application’s events in real-time, while at the same time working outside of the browser for tasks that require a higher privilege.

    Cypress also operates at the network layer by reading and altering web traffic on the fly. This enables Cypress to not only modify everything coming in and out of the browser but also to change code that may interfere with its ability to automate the browser.

    Cypress ultimately controls the entire automation process from top to bottom, which puts it in the unique position of being able to understand everything happening in and outside of the browser. This means Cypress is capable of delivering more consistent results than any other testing tool.

    Because Cypress is installed locally on your machine, it can additionally tap into the operating system itself for automation tasks. This makes performing tasks such as taking screenshots, recording videos, general file system operations and network operations possible.
  5. Cypress is a framework which can be used in Unit, Integration and end-to-end testing so it is the choice of both developers and testers.
  6. Writing code in Cypress is very easy, since it is completely in JavaScript, and its debugging capability is very strong.

Cypress includes the following features:

7. Time travel: Cypress takes snapshots as your tests run.

8. Debugging: Readable errors and stack traces make debugging easier.

9. Automatic waiting: Automatically waits for commands and assertions before moving on.

10. Spies, stubs, and clocks: Verify and control the behaviour of functions, server responses, or timers.

11. Network Traffic Control: Control, stub, and test edge cases without involving the server

12. Screenshots and videos: View screenshots taken automatically on failure, or videos of your entire test suite when run from the CLI

13. Cross-browser Testing: Run tests within Firefox and Chrome-family browsers (including Edge and Electron) locally.

Disadvantages of Cypress

1. Since Cypress is made in JavaScript and it only supports JavaScript for test automation, it becomes a restriction, one should have good knowledge of JavaScript because no other language is supported by this.

2. Cross-browser testing is limited as compared to other tools like Selenium.

3. Mobile browser testing or native applications cannot be automated by Cypress.

What Is Selenium

Selenium is an open-source testing framework, used for web application testing and supported by different platforms and browsers. Many programming languages are supported by selenium like c#, java, python, ruby, Perl. Platforms supported by Selenium are Windows, Linux, Mac OS and Solaris.

Reasons to Use Selenium

1. There are multiple reasons for using Selenium the most significant reason being that it is an open-source.

2. It can be run on almost every browser and is supported by maximum platforms.

3. Using this tool we can write an automation script in a language of our own choice.

4. We don’t need to be stuck or dependent on a tool-specific language.

Selenium Architecture

Advantages of Selenium

  1. Selenium supports multiple programming languages like C#, Java, Python, Perl, Ruby etc.
  2. Selenium supports multiple platforms like Windows, Linux, iOS.
  3. Selenium supports parallel or simultaneous execution of automation scripts.
  4. Selenium has record and play [IDE], which makes automation easy, the user can export this recording script into his own choice of language.
  5. Selenium is open source and has huge community support.
  6. Selenium is helpful in DevOps and continues integration, it can easily be integrated with Jenkins, Maven etc.
  7. Selenium with Appium helps in Mobile testing, which is very rare with other open testing tools.
  8. Selenium supports headless browser testing.

Limitations of Selenium

  1. It works only on web-based applications. Windows automation can’t be done by Selenium.
  2. The reporting feature is not good in Selenium, it has a dependency on TestNG or Cucumber.
  3. Selenium is not very accurate in finding Dynamic web elements.
  4. Captcha and barcode cannot be automated by Selenium.
  5. Selenium is not strong in handling page load and sync issues. Also, it is not able to handle popup windows very accurately.
  6. Capturing of Screen is supported by Selenium but still testing of Images, video and Audio cannot be done by Selenium
  7. Strong programming knowledge is required to use this tool.
  8. Selenium only helps in application UI testing, and can’t help in Unit testing, Integration testing and database testing.

Compare Cypress and Selenium

Selenium and Cypress both are open-source web test automation frameworks, but both have some differences. Following are the key difference between the two.

Who is the target audience for Cypress and Selenium

Target audiences are based on the objective of the test automation, if the objective is to automate Unit, Integration and End to end testing then Cypress is the only choice, and both Developers are QA are the audience for Cypress.

But on the other hand, if the objective is just to test the application UI and Functionality on the web browser then Selenium is the best choice.

The only drawback of using a Cypress is it is purely based on JavaScript, which may be difficult for testing people because in general, testing people know programming language but not a Scripting language.

Conclusion

Cypress is used with the objective of automating Unit/Integration and End to end testing as a parallel process if developers and testing folks both have strong knowledge of JavaScript. Whereas Selenium is purely testing folks' choice.

About the Author
Thimmaraju is a QA Automation Engineer here at Version 1.

--

--