For almost 20 years, testers have had the Selenium automated testing framework at their disposal. Since then, QA engineers have fully appreciated all the disadvantages of conducting manual tests and focused on minimizing the time spent while leaving the quality of the processes at the proper level. Since its inception, this tool has been the most widely used product in the automatic testing of web programs for a decade. But in 2015, it had an alternative – the new Cypress tool.
Why do QA engineers compare these frameworks before starting to write tests? Can they interchange each other, or are they still used in different cases? In this article, we will try to clarify these matters.
Table of Contents
Cypress and Selenium: A Brief Overview
Both of the frameworks we are talking about today are tools used to automate the functional testing of web apps. Why did we decide to compare them, since there are other products? The thing is that many of them, e.g., Protractor, WebDriverIO, or Katalon Studio, are implemented based on Selenium; therefore, they have similar characteristics and disadvantages. And Cypress tool is an entirely independent, new solution with its pros and cons.
What they have in common is that both tools are used for end-to-end testing. And differences are in the supported languages, additional functionality, and features. But let’s talk about everything in order.
Selenium Advantages and Disadvantages
In addition to the fact that this AT has earned testers’ trust, it has other advantages that make you choose it:
It has open-source, i. e. it can be freely distributed free of charge, and developers can add their own unique extensions to improve the quality and speed of work.
Sustains popular operating systems Unix, Windows, Mac, and Linux.
It holds a Selenium WebDriver component which allows you to automate web browser actions both on local PCs and remotely.
It is a multilingual AT environment – among the supported programming languages are .net (c#), PHP, Python, Ruby, Java, and JS.
Supports many AT environments, including the current Behavior-driven development environments: JUnit, Behave, SpecFlow and others.
It is a multi-browser tool; it supports all popular web browsers and mobile platforms.
Uses the interactive JSON protocol, which allows you to execute a test case in 3 stages:
test commands are transformed into a URL;
the webserver passes them to browser drivers;
URLs are redirected as a request to the actual browser; all test script commands are executed automatically.
The latest version of Selenium 4 offers QA engineers additional components that greatly expand the list of available features:
Grid is a proxy server that makes parallel testing on multiple machines more accessible and also makes it possible to manage various modifications of web browsers centrally.
IDE is a plugin for Firefox and Chrome that performs several functions: recording, playback, debugging, and running tests.
Provides extensive user support thanks to a rich user experience – numerous official sources, forums, and other communities of QA specialists are available for information to testers.
Able to integrate with third-party resources to improve the testing quality.
Selenium 4 version is fully aligned with the World Wide Web Consortium (W3C).
But still, Selenium has some shortcomings that make testers look for an alternative to this test automation tool:
To start automating test processes, QA engineers must install the right software (drivers) on their PCs:
ChromeDriver;
GeckoDriver for Mozilla Firefox
Microsoft Edge WebDriver
OperaDriver;
Internet Explorer Driver;
SafariDriver;
Selenium language drivers.
Automatic creation of test results is not available due to the lack of a built-in command – you need to use additional tools (e.g., JUnit) to build reports.
Long duration of test case creation. So, in Selenium WebDriver, QA specialists have to write each task step by step.
Open-source code makes it impossible to maintain the product reliably. No one can guarantee the correct operation of new functions.
As you can see, despite the years of use, Selenium is not an ideal tool for writing test scripts and testing in general. And although it is quite common (according to the Selenium.dev, 61% of respondents use the framework), there are still other worthy AT tools.
Selenium Alternatives: Should Cypress be Considered?
Although Cypress is relatively new to the automated testing market, it has already managed to gain enviable popularity, having received 38.5k stars on GitHub. Such prevalence, broad functionality, and an extensive list of advantages attract the attention of more and more testers and encourage them to conduct a comparative analysis of tools.
Above, we have already talked about the benefits of Selenium, forcing QA engineers to choose favor of it. Now it’s time to talk about the advantages of Cypress:
Allows you to track the testing history step by step – the program creates screenshots. Subsequently, with just one click on a specific line in the command log, testers can call up an image and find out what happened at that particular moment.
Supports quick-launch capability.
Allows you to test the API.
Able to check software compatibility with different browsers.
Has wide integration capabilities, including GitLab, Circle CI, Bamboo, and other tools.
Contains commands used to control function behavior, server responses, and timers:
Stubs cy.stub() – used to change the functionality and pass it to the developer for verification. As a rule, you have to mute functions whose side effects prevent them from being controlled.
Spies cy.spy() – allow you to “spy” on a particular function to ensure it was called the right number of times, with the correct arguments, or in the proper context.
Clock cy.clock() – used to control the program, predict its operation, and speed up testing.
Speaking directly about Cypress Advantages over Selenium, there are also a few points here:
The tool executes commands online as the tester writes them, providing full reporting documentation.
To work with Cypress, no additional drivers installation is required; test cases run inside the browser.
With Cypress, the results obtained are more stable due to better control. So, this tool supports the Stubbing DOM APIs.
No need for protocols – this AT tool functions within the program.
There is no need to add explicit or implicit waits; Cypress automatically waits for commands and confirmations.
However, having so many apparent advantages doesn’t make Cypress the only framework of choice for automated testing. The reason is that, along with the benefits, it also has its flaws:
Not being able to manage multiple browsers in parallel.
Only JavaScript is supported. As a result, only the Mocha JS platform is available.
Small list of compatible browsers – does not support IE and Safari.
Cypress’ open-source code creates the same conveniences and challenges as Selenium, and the growing community provides decent user support despite the product’s relatively short history on the market.
Cypress vs. Selenium: Which is Better
To make it easier to choose between the two frameworks under consideration, we will compare them in several ways: ease of setup and installation, architecture, app areas, and supported features.
Ease of setup and installation.
The Cypress installation process is easier than Selenium. The recommended way is simply to download the framework through the npm package manager. As for Selenium, its installation consists of 3 stages:
installing the Java SDK (Software Development Kit for Java);
installing the Eclipse IDE;
installing Selenium WebDriver itself.
Before testing, in the case of Selenium, you will have to take care of downloading and configuring the necessary drivers as well. Cypress does not require additional installations.
Architecture.
To compare the architecture of the two tools, look at the way they interact with a web browser. Selenium works outside the browser. It uses the WebDriver component to communicate with its driver, which then interacts with the actual browser and provides the execution of commands.
Cypress works inside the browser online. On the one hand, this gives the tool access to all program objects and outside of it (e.g., it allows you to take screenshots during testing). On the other hand, this fact limits the ability to run tests in two browsers simultaneously and does not allow the use of multiple tabs.
Opportunities.
Cypress is limited to using only one JS programming language and the Mocha JS platform based on it. Selenium has more features — it supports all popular languages and platforms based on them.
Areas of use.
What is Cypress Used for:
end-to-end testing;
unit tests;
integration tests.
The list of apps for Selenium is somewhat longer. It is used for:
compatibility check;
performance testing;
integration testing;
system testing;
end-to-end testing;
regression testing;
Smoke and Sanity tests.
Summarizing
Cypress is the go-to solution for built-in drivers, easy installation, and in-browser functionality for JavaScript developers. On the other hand, Selenium provides more opportunities for automating different types of tests and supports more programming languages and other related features.
The choice of one of the leading frameworks for automation is up to users and depends on the needs of a particular project and QA engineer skills. For more detailed advice, please contact zapple.tech managers — we specialize in automated testing and will help you solve a problem of any complexity.