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 the response time by adding a timer.
How to do it...
We can use various strategies to use timers in our code to measure the response time or the load time. For example, if we want to measure the time for a page load based on a particular element that...