Top 5 Mistakes Every Cypress Automation Tester Should Avoid
We all are aware of the fact that to reap the benefits of a test automation tool successfully, it is essential that one must avoid committing mistakes while using the tools. The Cypress test automation tool is designed to execute tests faster. However, if the test scripts are not written as per the required standards, it can lead to a delay in test execution. This is why it becomes necessary to avoid mistakes while writing test scripts.
This article will highlights the top 5 mistakes that Cypress automation testers should avoid which can help to make your scripts easier and faster. So, without further ado, let’s begin!
- Use of numbers in cy.wait
In Cypress, we have a great in-built functionality of automatic wait. Cypress scripts automatically wait for commands and assertions before moving on to the next step. In such situations calling the wait command for a specific duration can be futile as it causes unnecessary delay and so Cypress also provides the functionality to wait explicitly for an aliased route as shown in the below images. Using aliases can help you save time as the script moves on to the next step, once the alias condition is satisfied. In the below example, we can see that command cy.wait(100000) waits for 100000 milliseconds before moving on to the next step.
2. Not setting up a base URL
Setting up a baseURL is one of the primary steps when we start testing using Cypress.
By setting the baseUrl, Cypress will load the main window in the baseUrl specified as soon as your tests start and this helps in saving time. Many Cypress testers ignore to use of this functionality causing delayed test execution. Setting baseUrl allows you to skip hard-coding fully qualified domain name (FQDN) URLs in different Cypress commands. For example by setting the baseUrl ‘cy.visit(‘http://localhost:8080/index.html')’ can be shortened to cy.visit(‘index.html’), thus making scripts easier to trace.
3. Trying to visit external sites
This is one of the common mistakes that Cypress users commit. Although users might want to visit 3rd party servers in their tests for a number of reasons, the process can be time-consuming which may slow down your test execution process. Besides visiting external sites can have issues beyond the user’s control and so visiting external or 3rd party sites should be avoided.
4. Not knowing to debug
For any Cypress user, it is important that the user is aware of all the debugging options provided by Cypress. Knowing how to use these options can accelerate the process of test execution. In Cypress, you can write debugger statements or create breakpoints while test execution.
Similarly, we also have the option to run Cypress scripts in headless mode and record a video for the same. These videos are helpful in case of failure of E2E test cases.
Apart from this Cypress has the feature of cy.pause() command which helps you pause and then resume running all commands.
5. Coupling tests together
While running Cypress tests it is always a good idea to decouple your tests so that there are fewer dependencies. The coupling of tests together creates dependencies on individual test script blocks and decoupling these tests ensure nothing in previous tests leaks into subsequent ones. This is why instead of performing complex E2E tests in Cypress we must decouple it to test each layer separately or in smaller and manageable parts.
Conclusion:
Thus we see that, while Cypress is a strong E2E testing tool, our mistakes can impact the test execution process causing a loss of time and effort. If we avoid these mistakes we can improve our testing experience using Cypress.
To know more about test automation using Cypress, contact Testrig Technologies.