I need to measure response time for website using Selenium and Selenide.
Response time of a website:
I mean the loading time, I see that there is method to take difference between time before and after open website.
But this way, will measure the client loading time, will it depend on the used client? What is the best way for do that?
long startTime = System.currentTimeMillis();
driver.get("http://zyxware.com");
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("Calculate")));
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println("Total Page Load Time: " + totalTime + "milliseconds");
or this?
driver.get("url");
WebElement ele = $(By.tagName("body"));
// get the page load time
Long loadtime = (Long)((JavascriptExecutor)driver).executeScript(
"return performance.timing.loadEventEnd - performance.timing.navigationStart;");
System.out.println(loadtime);
and last way the following:
StopWatch pageLoad = new StopWatch();
pageLoad.start();
//Open your web app (In my case, I opened facebook)
driver.get("url");
// Wait for the required any element (I am waiting for Login button in fb)
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")));
pageLoad.stop();
//Get the time
long pageLoadTime_ms = pageLoad.getTime();
long pageLoadTime_Seconds = pageLoadTime_ms / 1000;
System.out.println("Total Page Load Time: " + pageLoadTime_ms + " milliseconds");
Do you know how long it takes for your website to load? Take the Google PageSpeed test.
The usage of ngWebdriver with Selenium helps in making the automation tool widely accepted to automate web pages that are developed in the Angular framework.
You can use selenium web driver to gather the timing data about your web page. Just do this:
from selenium import webdriver
source = "http://www.example.com/"
driver = webdriver.Chrome()
driver.get(source)
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
print "Back End: %s" % backendPerformance
print "Front End: %s" % frontendPerformance
driver.quit()
You can get the timing-related performance information for a given page with the performance.timing
API:
// launch the browser
WebDriver driver = new FirefoxDriver();
// visit a page
driver.get("http://stackoverflow.com");
// get the page load time
Long loadtime = (Long)((JavascriptExecutor)driver).executeScript(
"return performance.timing.loadEventEnd - performance.timing.navigationStart;");
The doc :
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming
Selenium doesn't provide a better way to do this. The way you are using it is the best way possible as far as I know. For the search method you can use the same way as you used for the page loading. Except you'd be doing some different actions between the start and stop time.
Also take a look at this question as I believe it answers your question. How can we get exact time to load a page using Selenium WebDriver?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With