Cypress has been gaining popularity in the testing community despite Selenium still being the favorite choice. During the initial days, Cypress had features only for Unit testing, and it was also supported only by a few browsers. However, Cypress has now extended its capabilities for End-to-end Testing, Integration Testing, and Unit Testing. So choosing between these two options isn’t as easy as it once was. So in this blog article, we will be pitting Selenium vs Cypress and list out the key differences between the two to find out which will be better for your needs.
Cypress is not an open-source tool only its test runner is open-source. Many modern test automation frameworks are built on top of Selenium. Whereas Cypress has its own architecture to interact with browsers. Selenium performs the actions on a browser through the browser API. Cypress has a node process that runs behind the scenes and controls the web application to perform the set of scenarios we have listed below.
- Stub the functions of your browser or application to force them to behave as per the requirements in your test case.
- It enables us to programmatically alter the state of your application directly from your test code by exposing data stores (Like in Redux).
- You can force your server to send empty responses and test edge cases like ‘empty views’.
- You have the option to test how your application responds to errors on your server by modifying the response status codes to be 500.
- Direct modification of DOM elements like forcing hidden elements to be shown can be done.
- It is possible to prevent Google Analytics from loading before any of your application code is executed while testing.
- Stay in the loop with the synchronous notifications you get whenever your application transitions to a new page or when it begins to unload.
- Move forward or backward to control time and allow the timers or polls to automatically fire without having to wait for the required time in your tests.
- You can also add your own event listeners for responding to your application. You could also update your application code so that it behaves differently when under tests in Cypress.
Source – Cypress Documentation
Selenium WebDriver can be used to control your browser either locally or remotely.
Local – First up, the client binding sends the WebDriver commands to the driver. Following this, the driver sends the command to the browser. Once a command is executed on the browser, the outcome of the command execution will be sent back from the same channel.
Remote – Let’s say you have the automation codebase in Windows, but want to run your scripts on the Chrome & Linux combination. You can start the Selenium Remote WebDriver on the Linux machine. After which, the client binding from Windows will send the commands to the remote WebDriver. From there the remote WebDriver sends the commands to Chrome Driver, and finally, the commands reach the browser via the Chrome Driver.
Advantages of Selenium
As stated earlier, Selenium is the crowd favorite. So let’s take a look at the advantages that make Selenium so popular.
- Selenium WebDriver supports multiple programming languages.
- Selenium can be integrated into any test automation framework.
- It supports multiple browsers.
- In Selenium 4, you can get the DevTools instance using CDP.
- Selenium also has a strong online community.
We have seen a glimpse of both Cypress and Selenium separately. Now let’s take the Selenium vs Cypress a notch higher and compare both on a point-to-point basis to see which one will be useful for you.
Selenium vs Cypress Comparison
|2||Pricing||Free||Free for up to 3 users & 75 USD per month for 10 users|
|3||Browsers Supported||Chrome Edge IE Firefox Safari Opera Headless||Edge Chrome Firefox Electron|
|4||Video Recording||Selenium is a web browser automation tool. You can bring execution recording using your test automation framework, but not using Selenium.||Cypress has an in-built feature for video recording.|
|5||Screenshots||Page-level and element-level screenshots can be captured using the TakeScreenshot method.||By default, screenshots are taken for failures and embedded into test results. If you want to take inside the script at any point, you can use cy.screenshot() command.|
|6||Jira & Slack Integration||No. You need to write your own utilities to integrate Jira & Slack.||Yes|
|8||Reporting||Selenium does not have in-built reporting libraries. You need to integrate some external reporting tools like ReportPortal or Allure Reporting.||Cypress has a comprehensive reporting dashboard that can make the test results visible to the entire team.|
|9||Open-source/Freeware/Commerical||Open-source||Cypress Dashboard is a commercial tool. Test Runner is open-source|
|10||Load Balancing||No||Cypress will automatically balance your spec files across the available machines in your CI provider.|