How to Save Time When Automated Tests are Executing? - kloia Blog
Test Automation is an important step of Continuous Deployment . Automation reduces bug fix costs by testing early and testing often principles. Automation projects also increase quality and reliability. But test execution duration problem comes up with the benefits of the automated test.
In this post, I’m going to share 5 ways to speed up automation projects..
1-Parallel Test Execution
Parallel Test Execution is one of the best ways to speed up test automation projects. Suppose that you have 100 automated tests, and each test takes about 1 minute to run. If all tests execute one by one on a single thread, the total test duration will be 100 minutes! But if these tests execute on 10 threads, then the total test duration will be only 10 minutes.
Parallelism is easy to configure with some external gems, libraries or minor infrastructure changes in test automation projects. Keep in mind that each parallel test must be independent!
2-Headless Browser Execution
A headless browser is simply a browser without a Graphical User Interface (GUI). A headless browser simulates how an actual user accesses a web page and interacts with it, but it works in the background on memory. Headless browsers are faster than real browsers for testing because they are not opening up a browser with GUI and not trying to download CSS, JavaScript and rendering HTML. If performance is a serious issue in the project, testing with headless browsers would be a very efficient solution for you.
3-Explicit Wait
Choosing between Implicit and Explicit waits is an intermediate topic in test automation projects. Test automation developers always need both types of waits in projects.
The implicit wait sends a request to the web driver to wait for a certain amount of time before throwing an exception. The implicit wait does not wait for any condition except the predefined “wait” value. Suppose that you have a test case which opens and verifies a webpage, and let’s say this test case lasts a maximum of 10 seconds. If you use an implicit wait for the case, the test will always wait for 10 seconds even if the page is downloaded in less than 10 seconds. If the web page is downloaded in 3 seconds, you even have to wait 10–3 = 7 seconds for nothing because of implicit wait.
The explicit wait is little bit different from the implicit wait. The explicit wait sends a request to the web driver to wait for a certain condition, called Expected Condition. Let’s revisit the test case mentioned in the previous paragraph. If you use an explicit wait and define the expected condition to be seeing the Login button, the test case would be completed in 3 seconds, since the page would be downloaded completely in 3 seconds. The explicit wait watches for an explicitly-defined expected condition and if the condition occurs, the test case passes. Thus, you could save significant times using explicit wait.
4-Single-Targeted Test Cases
While developing automated tests, test developers sometimes lose the thread and they add unnecessary steps to test. Adding additional steps into a single test case which could be split up in separate test cases makes the case much longer. Let’s say you are developing “Successful Login” test case. If you put steps which is related with “Search” test case into “Success Login”, your test case would be evolved from single-targeted to multi-targeted.
Developing and executing short and single-targeted test cases are faster than multi-targeted and longer test cases. In addition, single-targeted test cases are easier to maintain. As a result, if you want to make your automation project faster, focus on developing short tests and features, and narrow the scope of each test as much as possible..
5-Caching
Assertions and validations are indispensable steps in testing. In test automation projects, test developers often check the content of UI elements to verify expected results. However, checking content is not always an adequate solution to verify expected results. Certain cases may require getting data from databases or API calls.
If the information would be used more than once while test case is running, the information should be cached to prevent calling the same database or API queries. Caching decreases wait times while waiting for responses from these calls and makes the automation project faster.
Test Faster, Fail Faster, Fix Faster!
Test Automation helps delivering more stable software projects with high quality. Experience over hundreds of projects have shown us that the teams who invest in test automation projects will have benefits and advantages in the long term. In addition to the approaches outlined here, design patterns can be applied to the automation project. This allows the teams to test faster, fail faster, fix faster.
Burak Koyuncu
Experienced Software Test Consultant with a demonstrated history of working in the finance and e-commerce industry.