Measuring the response time using a timer

Measuring page load or response time is one of the basic metrics that we can capture in the Selenium WebDriver tests. We can use timers in the test code to capture the time taken for page load, rendering of the elements, JavaScript code execution, and so on. This approach can be implemented using the Date/Time classes in programming languages.

We can also use the Stopwatch class to measure the time taken for an activity of interest. The only downside of this approach will be testing with a lot of timers added.

In this recipe, we will see how to calculate the timespan between two events in various ways.

Getting ready

We need to identify the areas where we we need to evaluate the response time. We will measure ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.