One of the biggest challenges agile software development helps you solve is deliver reliable and modern applications faster. Continuous integration (CI) and continuous delivery (CD) make this possible through a combination of carefully designed release pipelines. Therefore, this article aims to outline why to consider using the Cypress testing tool for boosting your release pipelines.
What is a release pipeline?
A release pipeline helps your team continuously deliver software to your customers at a faster pace and with lower risk because it utilizes automated testing and delivery of your software in multiple stages to production. A release pipeline consists of several phases, including continuous integration, continuous delivery, and continuous deployment, with the last closing the circle of a completely automated process. All this means a release pipeline helps you continuously deploy your product to production by continuously integrating ready pieces of code and delivering them without interruptions or manually executed steps along the way to the end-user.
Performing automated testing as part of the release pipeline is a great way of detecting unexpected changes. Therefore, this topic discusses why to use Cypress to run end-to-end testing during a continuous deployment.
What is Cypress?
It is very easy to set up, you need to install NodeJS on your machine, navigate to the desired folder, execute “npm install cypress –save-dev” and done, in a minute or two Cypress will be installed locally. To run Cypress just type in “cypress open” in your terminal. Cypress also creates a project structure for you if it does not find one in the project’s folder.
As easy it is to install and run locally as to install and run it in a pipeline. The only difference is you need to run Cypress, not to open it, respectively the command to use is “cypress run”. The command is different because in a release pipeline you do not need the graphic interface provided to you by Cypress in an Electron application.
Benefits of Cypress Testing Tool
Most of the testing tools like Selenium, for example, operate by running outside of the browser and executing remote commands across the network. The Cypress testing tool is the exact opposite. It is executed in the same run loop as your application. Behind Cypress is a Node server process. Cypress and the Node process constantly communicate, synchronize, and perform tasks on behalf of each other. Having access to both parts (front-end and back-end) gives you the ability to respond to your application’s events in real-time while working outside of the browser for tasks that require a higher privilege.
Cypress also operates at the network layer by reading and altering web traffic on the fly. This enables Cypress to not only modify everything coming in and out of the browser, but also to change code that may interfere with its ability to automate the browser. The Cypress testing tool ultimately controls the entire automation process from top to bottom, which puts it in the unique position of being able to understand everything happening in and outside of the browser.
Cypress Retry ability
Cypress is a true gem. It helps reduce test flakiness quite a lot. The retry ability simply said retries the last command in each step if it fails and at the same time allows the tests to complete each command as soon as the assertion passes, without hard-coding waits. You can say goodbye to the StaleElementException for good! And you do not have to deal with those implicit and explicit waits anymore.
This is another feature that you do not have to deal with. In the Agile world, time is one of the most important resources. Continuous integration and continuous delivery help you time to market tremendously but what makes the difference is test parallelization. You only need to set up multiple machines in your CI environment and you only need to provide the “–parallel” key when running Cypress. From there the Dashboard service takes care of everything as it orchestrates the execution evenly across all the machines.
5 Good Reasons Why You need a DevOps Toolchain
You only need to install the browser on your local machine or in the CI setup, and from there, again it is a matter of providing the key “–browser” and the desired browser after it when you execute the tests. Cypress support Chrome, Firefox, Microsoft Edge and Electron browsers, one exception dough, you don’t need Electron installed to run your tests on it.
When it comes down to reporting, Cypress truly shines as an out-of-the box tool. It supports different reporters, you can configure the location reports to be stored, the reporting tool and the report filename with 3 lines in the configuration file. It is not the only thing, taking screenshots and videos is a matter of yes or no. If you do not want to get your hands dirty setting the parameter “screenshots” to true in the configuration file works out-of-the-box, just do not forget to point the folder where you want them stored, same goes for videos of the whole execution until failure.
To sum up
Cypress is faster than most of the alternative tools. At the same time, it reduces test flakiness to a minimum if not completely. The Cypress testing tool caters for the entire process, so you do not need to install additional libraries and use built-in tools. Reporting and screen capture is a matter of simple configuration, just point the folder and you will have them generated for you after each run. If it does not find an element or an assertion fails it retires until time out to make sure your test fails and by this reduces the false positive tests in your run. It is hard to measure how much time and effort you will save in your project using Cypress until you try it for yourselves but given the key benefits you can see it will pay off.