Friday 14 February 2014

Measuring the response time using a timer in Selenium !!

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 will use the System.currentTimeMillis()

method to get the current time as follows:


// Get the Start Time
long startTime = System.currentTimeMillis();
// Open the BMI Calculator Mobile Application
driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");
// Wait for the Calculate Button
new WebDriverWait(driver, 10).until(ExpectedConditions.
presenceOfElementLocated(By.id("Calculate")));
// Get the End Time
long endTime = System.currentTimeMillis();
// Measure total time
long totalTime = endTime - startTime;
System.out.println("Total Page Load Time: " + totalTime + "milliseconds");


Sudhakar.Mangi

No comments:

Post a Comment