For a long-time Selenium was the only open-source automation tool that could compete well enough with the bigger, commercial tools, however, over the past few years there has been a lot of movement in the open-source market with Cypress one of the new tools that have grown rapidly in the test automation space.
Cypress was essentially architected to rectify some of the limitations of Selenium and to take advantage of some of the newer web architecture trends in the world. The tool is built on node.js and comes with packages as an npm module rather than an independent application that runs on a machine.
This is different as whereas most automation tools are separate applications that run outside of an application or browsers to execute remote commands, Cypress operates inside the browser and is able to alter different aspects of the website more directly, making it significantly easier to stub or mock your tests as it manipulates the DOM directly on the fly. This allows for greater test coverage and speeds up the execution of the automated tests, though because it operates inside the browser, it cannot do parallel execution as well and would need multiple instances of the browsers to operate in parallel. Another benefit of Cypress running as an npm module is that different versions of the tool can operate across different repos – depending on what is needed.
It is also bundled with jQuery (Javascript Library) and inherits many of jQuery methods for UI components identification and simplifies HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax, making it easier to mimic the behaviour of node.js-based web sites.
Whereas Selenium followed a very modular architecture that offered multiple benefits for extensibility, Cypress is designed as an all-in-one testing framework to try and reduce the complexity of the overall test framework. It also provides built-in reporting (though arguably this feature is still quite limited) and is designed with asynchronous operation in mind and provides better operation against asynchronous operations than Selenium.
Below are some of the benefits of using Cypress:
Easy to update: With it not relying on other modules to operate, it can be updated as one package without needing to consider compatibility with other modules. It can run completely isolated without additional libraries.
Easy to use: Cypress has a simple and intuitive API, making it easy to get started with end-to-end testing, even for users with little or no programming experience. While Cypress does still require a good programming mind to work with, the majority of automation can be done with pre-packaged cypress commands which are easy to understand.
Fast and reliable: Cypress is built on top of the browser and runs the tests in the same environment as the application, which makes tests faster and more reliable.
Easy mocking and stubbing: Thanks to its ability to directly manipulate objects through the DOM, it is easy to be able to mock and stub tests that would’ve otherwise been tricky or time-consuming to automate using other tools.
Automatic waiting: Cypress automatically waits for elements to be loaded before interacting with them, which eliminates the need for sleep commands and timeouts. It also reduces the number of async issues that you are likely to pick up as a result.
Built-in debugging: Cypress provides built-in debugging tools that allow developers to easily debug their tests and fix any issues. It takes snapshots as your tests run. We can hover over each command in the Command Log to accurately see what happened at each step. You can also view videos of the execution of your entire test run when using the Cypress dashboard.
Real-time reloading: Cypress automatically reloads the browser when the tests or application code changes, which speeds up the development process.
No tool is perfect and the architecture approach of Cypress also leads to a few drawbacks when using the tool:
Limited cross-browser support: Cypress currently supports only Chrome and Edge, and it doesn't support other browsers like Safari and IE, though these features could be developed in future updates.
Lack of parallel testing support: Being based directly on the website itself, Cypress cannot execute tests in parallel on the same browser, though it can handle multiple browsers at the same time through different VMs. This however makes it slightly more expensive for the CI architecture to do so adequately.
Limited support for mobile testing: Cypress currently has limited support for testing mobile applications.
Limited integration with other tools: Cypress has limited integration with other testing tools, which may limit its flexibility in certain scenarios.
When to select Cypress:
If your application-under-test is primarily web and node-JS based
You need your automation scripts to operate directly within the CI/CD pipelines
If you are clear on your mocking and stubbing requirements to greatly improve execution speed
Things like traceability to your requirements or manual tests are not critical to you
In summary, Cypress is a user-friendly and powerful end-to-end testing framework that is specifically designed for web applications. Its usefulness in being able to mock situations has allowed developers to control the coverage of their test automation scripts greater than what other tools have offered before. But, as with all tools, there are downsides that need to be considered too.
For a DevOps-centric organization, though that requires high coverage and throughput in its test automation package, Cypress is certainly worth considering.