Skip to content

Automated Performance Testing: Using Stopwatches in Test Automation

Claus Topholt

Claus Topholt

Measuring elapsed time can be a key component in test automation. For instance, a business requirement may state that a search query must not take more than 5 seconds to respond with results. Although there are dedicated performance testing and monitoring tools such as dynaTrace on the market which can provide detailed insights, Leapwork can easily be used to do sanity checks on business transactions using the Stopwatch building block.

The following demonstrates how a single Stopwatch is started through its green execution input connector and the elapsed time is then written to the run log after some time is spent waiting:

stopwatch-demo1-5.png

Stopwatches reset every time their green execution input connector is triggered. This will for instance log approximately 5 seconds to the log endlessly until the case is manually stopped (for instance with the keyboard shortcut F10):

stopwatch-demo2-5

The Stopwatch block can be used in many different scenarios. Here's an example that reads search terms from an Excel sheet and then types them into the search box on ebay.com and checks that the results are never shown more than 5 seconds later:

stopwatch-demo3-5

The Stopwatch is started as soon as the search term is entered and the elapsed time is checked as soon as the "results" are found on screen. A Set date/time block is used to specify exactly 5 seconds as the comparison value.

It's worth noting that even though Leapwork isn't well suited for very precise performance testing, by using the fast image recognition algorithms in eg. a Find image block, only a few hundred milliseconds might be "lost" between the different steps in the test case and so the results are at the very least a good starting point for further investigations.

The "Elapsed time" property of the Stopwatch block can be expanded to reveal individual hour, minute, second and millisecond counters. But there's another use for the total "Elapsed time" property that can be useful. When compared in a Compare block using the comparison type "Number", the value is automatically converted to the total number of seconds with milliseconds as decimals. So for instance, 00:01:05:231 (one minute, five seconds and 231 milliseconds) will be understood as the value 65.231.

This can simplify the test case by removing the need for the Set date/time block. In the example below, 3 seconds are used as the comparison value B:

stopwatch-demo4-5

For another example of how to use Stopwatches in Leapwork, see this Learning Center video.

 

CTA-StartTrial-8