Testing tools and frameworks, as much as development tools, continue to evolve. As demands of Test automation continue to change, tools must and will continue to be developed to meet those demands.
Take the example of Selenium, a popular testing framework. It originated as a tool for testing web applications and was initially only used by employees at Thoughtworks, the company where programmer Jason Huggins worked and developed the framework. The tool became open-source by the end of year 2004.
Making Selenium an open-source tool not only increased its popularity because it could be used for free but also meant anyone could contribute to help expand its feature set.
Less than a year after it became open-source, developers envisioned adding features that would make Selenium much more than a tool for testing web applications. Cross-platform testing, testing framed applications and more were among the upgrades planned for Selenium.
Cypress
Cut to now and Cypress is a feature-rich, JavaScript-based tool for Test automation. It is a next-gen front-end testing tool built for modern web, addressing the main issues faced by QA engineers and developers while testing modern applications.
Cypress makes it possible to set up, write, run, and debug tests. The tool can be leveraged to write End-to-end tests, Integration tests and Unit tests, while it is capable of testing anything that runs on a browser. It is a developer-focused framework whose setup is seamless and comes with good documentation and an ever-growing community.
End-to-end testing tools (most, if not all) are Selenium-based: that is, they operate outside the browser. They execute remote commands through the network. It is also why all of them are fraught with the same issues.
Cypress works differently. It is executed in the run loop same as the application and executes as quick as a browser renders content. Users can see tests being executed in real-time while they develop applications. Such architectural enhancements provide the ability to perform test-driven development with complete End-to-end tests.
Cypress “ causing a shift in Test automation
Cypress boasts of several key, useful features which QA engineers and developers have desired in test automation tools for a long time. Let us take stock of those features one by one.
No asynchronization issues
One of the core features of Cypress is the retry-ability in helping test dynamic web applications. It enables tests to run every command as quickly as assertion passes ”assertion is one of two methods of calling in Cypress tests; command is the other one ”with no hard-coding delays.
Even if an application takes extra seconds or milliseconds to render a document object model (DOM) element, the test doesn’t need to change. Cypress automatically pauses for assets and commands before proceeding.
(The caveat here is the retry-ability feature of Cypress applies only to commands querying the document object model. Those commands that might alter the condition of the application under test (AUT) are not retried.)
Cypress commands such as cy.stub(), cy.spy() and cy.clock() help verify and manage the performance of timers, server responses and functions.
cy.stub() helps tweak a function. It enables users to take control of its behavior, such as when it has additional issues that need to be managed.
cy.spy(), as the name suggests, enables users to spy on functions. Users can thereby capture and ascertain whether a function was called with the defined arguments, whether a function was called a given number of times and so on.
cy.clock() is another useful command that helps control an application’s time and date to side-step slow tests or nullify its behavior.
No need for guesswork
With Cypress, users do not have to guess why their tests are failing. While it is possible that debugging the test script can be challenging, Cypress helps save time on debugging. Again, it is a feature unique of Cypress with no other automation tool offering solutions to fix bugs within the test script.
Readable error messages help debug the script faster. In addition, users are provided with access to the entire suite of browser development tools.
Control network traffic
The complete lifecycle of XHR tests within an application can be tested with the help of Cypress. The tool provides access directly to XHR objects, thereby helping users learn and understand its properties.
Within Cypress, users also have the option to choose if any response needs to be stubbed or allow it to reach the server. Testers can also change it up by alternating the requests they choose to stub and those they allow to reach the server.
Take shortcuts
That means testers no longer need to use the user interface to build up the state. Essentially, Cypress gives them the ability to log in programmatically without having to enter a login webpage, enter their login credentials such as username and password, and wait for the page to load (or, in some cases, redirect).
Testers also have the option to choose when they want to test as a user and also side-step any repetitive and slow parts of the process.
Snapshots at the time of running tests
No other automation tool except Cypress captures snapshots while the test is being run.
By taking snapshots of an application, Cypress enables users to revert to the state when commands run. By just hovering over the command, users can spot the changes (if any).
Closing thoughts
Cypress is a great tool that is fast to ramp up with and offers an excellent execution environment. The scripting is seamless as it is completely mochaJS/JavaScript-oriented with new application programming interfaces (APIs). The large set of APIs help leverage commands specific to the browser to set viewport, clear cookies and more. Once the Cypress tool is launched, it can be triggered to run with an embedded browser in-built with tools. For companies starting a new project, it would be a good idea to have a proof of concept (POC) with Cypress, which can turn out to be a good future solution.