This article shows you the differences between Selenium library and Cypress framework. Cypress is a modern end to end testing library – a competitor of Selenium. I recommend you to get familiar with the general description of Cypress and description of Selenium problems. I wrote about it earlier (http://www.diwebsity.com/2019/07/16/why-choose-cypress/).
Below is a table with a comparison between these two approaches (libraries) line by line for each category. I tried to be as objective as possible. This table is intended to be a help for your decision process.
Cypress vs Selenium – Comparision
|Type||It is simply one purpose library with a strong community and additional packages.||Complete framework using many front end test libraries.|
By text and text fragments
By text and text fragments
|Selecting a unique element||There is a problem with uniqueness. When there are many elements matching a particular selector, then the first one will be returned without any notice.||Trying to select a single element with not a unique selector will result in an error. This is good because it gives instant feedback about the test inaccuracy.|
|Browsers Multiple browser tests||Chrome|
Support of mobile browsers testing and testing on the browsers grind in the cloud (e.g. Browserstack or Appium)
|Debugging||Depends on language:|
C#, Java tests are executed in a synchronous way, so it is easy to debug code the same as regular programming code.
|Very good with time travel option in UI. Tests are executed in special chrome browser version with test steps explorer and preview window. It allows to select a particular step in the test case and see the state of a page at the time of executing this step.|
|Waiting for async operations||With additional libraries.|
Selenium doesn’t wait for any actions. It doesn’t have knowledge about any async operations.
However, there exist support libraries to handle all kind of waiting for popular frontend frameworks.
Cypress is run under the same browser process, so it knows when Java Script code is working. In that way it can automatically wait for finishing all front-end processing before going on with test execution.
All web page operations have a small delay due to the driver working as a proxy between test instructions and browser.
It operates on the same process in the browser.
|Cross application testing||Yes|
You can freely navigate from one application to any other URL
You can test only a single domain and any number of subdomain inside one domain.
|Integration with CI||Possible|
You can use any testing library, test reports, and execution patterns. You can easily adjust it to your needs.
Using command line and
This is the only one option.
The CI service has to support
Test recording on the CI server is a paid option for a high number of recordings.
|Parallelization||Yes, easily||Yes, from version 3.1.0|
|Test confidence level||High|
Selenium stimulates the same actions as a user.
Let more actions than a user can perform. Especially it let to perform all actions (also disabled in UI) using
We have to manage it manually. We can take screenshots, detailed error information or call stacks.
Cypress offer UI to debug tests with the time travel option (the ability to choose particular test instruction and see, how the tested page looks before this line execution). It also supports test recording and taking screenshots.
Base documentation is medium, but there are plenty of learning resources on the internet
|Work with custom elements||Need custom code|
There exist multiple additional libraries to work with custom controls
|Need custom code|
We can do anything on the page and get elements in that way.
JS code is written as a string.
JS code can be written as code using a window object as a
On many places
|Manipulate browser options||Cookie|
Can be automated
Need manual installation
|General purpose||End to end testing|
For both: developers and QA team
|End to end testing|
Mostly for developers
But there is an open issue for this.
|Test case architecture||Custom, but very flexible. You can do whatever you need.||Hard|
It is hard to create layered architecture to support test case readability (like in BDD test cases). That’s because selected elements are not persistent. We can’t select element and operate on it multiple times later in code.
The code below will not work correctly:
|Other||The most important advantage of Selenium is a great community which results in a huge number of resources to learn and resolve any problems.|
Additionally, there exists a lot of libraries for Selenium. It is related with the fact that Selenium is only a simple purpose library, that cannot work without additional libraries (like for test execution).
|Cypress have additional features: |
– the ability to mock API calls
– the ability to control network traffic speed
This is relatively young framework and we should keep an eye on its growth. It has a great potential, but also has some serious problems/blockers for some applications.
I hope this comparison will help you to your own assessment of the end to end test approach. Remember to fit the testing approach to your and your organization needs (skills in the team, team structure, type of applications you create, test cases inside applications), not only following the hype. Cypress is a very promising library, but still, it has some blockers which can be problematic for your need (like single domain constraint or lack of