Listen to this blog
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.|