End-to-end tests usually take a long time. What are the techniques of accelerating them?

Codibly / Technology  / End-to-end tests usually take a long time. What are the techniques of accelerating them?

End-to-end tests usually take a long time. What are the techniques of accelerating them?

An effective test automation strategy requires automation on three levels – unit, integration, and UI. As the size and complexity of the application increases, manual testing of new functions and error detection can become cumbersome and take a lot of time. Automating repetitive tasks is a great job facilitation. In this article, we focus on the test, that Mike Cohn in his book “Succeeding whit Agile” placed on the highest level of the pyramid – UI test (end to end). End-to-end tests test the application from the end-user’s point of view. The goal of end-to-end testing is to identify system dependencies and ensure that the right information is passed between different components and systems. These test should be less in relation to unit and integration test and cover the most important paths in the application. Nevertheless, it usually takes a long time to prepare and run test. Why e2e tests are important and what are the techniques of accelerating them without losing quality? About this later…

There are many ways to create final test faster and more reliably. One of them is the use of fast selectors. To perform an action on the page (e.g.click), the element on which it will be carried out should be searched. The most reliable way is to locate an element by its id attribute. To create test reusable, xpath isn’t a good way to be implemented. Retrieving an element with its id attribute is generally optimized in all browsers, xpath is not always well implemented, which leads to different behaviors in different browsers. You should also avoid using “waits” or “sleeps” in the test. Instead of this, you should use checking to see if these items are actually available before attempting to interact with them or to verify

 await page.wait(‘1000’)vs
await page.waitForSelector(‘myId”)

If you instruct your test to sleep for a second before attempting to click a button, that might work most of the time, but will still fail when there’s a slow network connection. Moreover, your test will be unnecessarily slow most of the time when the button becomes clickable in milliseconds. So the second use case is preferred. Many of the frameworks used to create end-to-end tests support running parallel tests. To be able to implement this, the tests must be written independently to each other. If you need to implement a precondition that is valid for many tests, just use the “Before” method and configure it in the way that it will run only once during tests execution. Then the tests execution time can be reduced several times.

End to end tests are the most susceptible to change and hence difficult to maintain. It can be solved to use Page Objects. The page object model pattern is the test more readable. It also extracts the code related to element selection and actions. We can reuse the samples in many test cases. And thus save time. In order to update a selector or action, we only need to update the associated method. Without design pattern, we have to update the selector method in each test case. Before starting work with the end to end tests it is worth considering the choice of the right tool, which may also affect the speed of testing. Most of the popular end-to-end testing frameworks are built on top of Selenium WebDriver. However, now there are more and more alternatives. Here are some of them: Puppeteer, TestCafe, Cypress. They are easy to set up, have extensive documentation and support for parallel test execution.

Without End-to-End testing, software might be loaded with many defects. E2E tests allow us to cover sections of the application that unit tests and integration tests don’t cover. Although it may take a long time to prepare and run tests, the end to end testing helps the organization to avoid pitfalls in the later application, and application of several guidelines from this article will allow them to be accelerated.

No Comments

Leave a Comment