Back to Resources

Blog

Posted April 8, 2021

Comparing the Selenium and Cypress Testing Frameworks

Author Chris Tozzi reviews the Selenium and Cypress test frameworks and provides tips for why you might want to select one or the other – or even use both at the same time.

quote

Automated testing for web apps has been around for well over a decade. For much of that time, Selenium has reigned supreme as the go-to testing framework for virtually any type of testing need that involves a browser-based app.

But as the world of test automation continues to evolve, newer tools have emerged. Chief among them is Cypress, a testing framework that is becoming an increasingly popular alternative to Selenium.

Is Selenium or Cypress a better choice for your automated testing needs? Keep reading for a comparison of these two frameworks, along with tips on why you might want to select one or the other – or even use both at the same time.

What Is Selenium Testing?

Selenium is a test automation framework that uses a protocol known as WebDriver to automate software tests within a Web browser. With Selenium, you can inject commands into an application and record the application’s response.

By writing scripts to send commands automatically, developers are able to run automated tests to identify performance and reliability issues in software they write. Because Selenium (like most test automation frameworks) can emulate user interactions with an application, it’s a great tool for testing software before it is deployed into production. In other words, frameworks like Selenium help developers identify problems without having to wait for feedback from real-user monitoring tools.

Selenium supports all major web browsers, although each browser has a separate automation driver (which means you have to configure different test environments for different browsers, which increases the effort required to set up Selenium). Selenium also supports most of the major programming languages used for the web today, including Python, Java, C#, JavaScript, Ruby, PHP, and Perl.

Selenium is the oldest test automation framework that is still in widespread use today. Its roots date to 2004, when Jason Huggins developed the first version of Selenium (which was based on JavaScript) to help automate software tests at ThoughtWorks. The modern version of Selenium, which relies on the WebDriver protocol, appeared several years later.

What Is Cypress Testing?

Cypress is a newer testing framework that uses web and browser APIs to drive test automation.

Like Selenium, Cypress can be used to inject commands into Web applications and evaluate how the applications respond. However, the way Cypress works is different from Selenium in several important respects.

For one, instead of using a software library like WebDriver, Cypress relies just on the native Web and browser APIs to interact with Web apps. This makes Cypress easier to set up, with the tradeoff that it only supports testing apps written in JavaScript. It can’t send commands to applications written in a wide variety of languages, as Selenium can.

Cypress also supports only certain browsers. Originally, it worked only with Chrome. It added Firefox and Edge support with the Cypress 4.0 release in 2020.

Another important difference between Cypress and Selenium is that Cypress provides only limited support for testing mobile apps: it works only with apps developed with Ionic. In contrast, Selenium can test virtually any type of mobile app via Appium, an Android and iOS testing framework.

From an historical perspective, Cypress is considerably newer than Selenium. Development on the Cypress testing framework began about six years ago, and the framework achieved its 1.0 release in 2017. 

Selenium Testing vs. Cypress Testing: How to Decide

Selenium and Cypress are both reliable, feature-rich test automation frameworks. They also both happen to be open source.

So, why would you choose one or the other?

Reasons to Use Selenium

Selenium is the obvious choice for the following use cases:

  • Testing apps written in languages other than JavaScript

  • Testing applications across a wide selection of browsers (including browsers like Safari, which Selenium supports but Cypress currently does not)

  • Testing mobile applications that aren’t supported by Cypress

Reasons to Use Cypress

Cypress is a better choice when the following considerations are priorities:

  • The ability to write tests quickly

  • Avoiding the need to configure each type of browser separately

  • Taking screenshots as part of the testing process in order to see what the user would see when the app is handling a specific command. Cypress can do this easily via browser APIs. It’s possible to take screenshots in Selenium, too, but it requires more effort to set up

Developer-Oriented Testing vs. QA-Oriented Testing

Another way to think about the differences between Cypress and Selenium is to consider the types of groups that each one caters to.

In general, Cypress is designed first and foremost for front-end developers who want to write tests for the programming language that they are most likely to use – JavaScript – without the complex setup and overhead of Selenium.

Selenium, in contrast, is geared more toward QA professionals who are willing to invest time in learning the ins and outs of the Selenium platform as well as in configuring complex testing environments.

This is certainly not to say that Cypress is only for developers and Selenium is only for QA teams. Both frameworks can be used by either group. But if you’d like to get your developers more involved in software testing, Cypress may be a better tool, whereas Selenium is a better fit for more traditional teams that aren’t trying to integrate development and QA roles.

Use Selenium and Cypress Together

Keep in mind, too, that there’s nothing stopping you from using both Selenium and Cypress. You could rely on Cypress for fast and easy JavaScript tests, while turning to Selenium to fill in the gaps that Cypress doesn’t address.

Conclusion

Cypress and Selenium are both excellent test automation frameworks. Whether one is better than the other depends on which group is doing the tests (developers or the QA team), as well as which types of browsers and applications you need to test.

=======

Chris Tozzi has worked as a journalist and Linux systems administrator. He has particular interests in open source, agile infrastructure, and networking. He is Senior Editor of content and a DevOps Analyst at Fixate IO. His latest book, For Fun and Profit: A History of the Free and Open Source Software Revolution, was published in 2017.

Published:
Apr 8, 2021
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.