3

I need to measure response time for a website.

  1. Response time to open a page of a web site: I mean the loading time, some way to see the difference in time before and after open a website page.

    But this way, measuring the client loading time, will depend on the client used client. What is the best way to measure 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");
  1. if I have a search button for the same website, if I need to measure the search time, how to do it? is it as same as the above way?
9
  • You tagged this with load-testing but your question seems to be about page load time, which is something else.
    – user246
    May 26, 2016 at 12:50
  • I recommend to measure these kinda KPIs at API level specially search response time. I should say, such measures even at API level are not very accurate since it is affected by different factors e.g. Network.
    – masood ghz
    May 26, 2016 at 13:08
  • What do you mean by search time? Does that include the time to render the search results page?
    – user246
    May 26, 2016 at 14:38
  • @user246, yes how it take to load the search result in the same website.
    – Hana90
    May 27, 2016 at 4:31
  • @masoodghz, did you mean at development phase?
    – Hana90
    May 27, 2016 at 4:31

2 Answers 2

1

Selenium is the wrong tool for measuring page load times. Selenium can't actually block until the page finishes loading, so it has to poll the browser. Your load time precision is constrained by the poll interval.

The most accurate tools for measuring page load times are browser extensions like YSlow, Firebug, and the Chrome DevTools.

3
  • 1
    I need this check to be automated, can I do it with these extensions?
    – Hana90
    May 27, 2016 at 4:29
  • 1
    Please, see the edited question. I have three ways which is the best one?
    – Hana90
    May 27, 2016 at 7:40
  • Measure all three approaches, then measure the actual load time using the extensions I described above, and pick the approach that is the most accurate.
    – user246
    May 27, 2016 at 11:14
0

Try using XSLT reports this report will give you page loading time and in your script set wait.until logic below is the sample for script and the code for XSLT report. check index.html report you will page loading time. And set Web driver wait time to high like 5 minutes see the example. Hope this will help.

//Wait for maximum 5 minutes if needed WebDriverWait wait = new WebDriverWait(driver, 300);

script:

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='displayname']")));

XSLT code Add this in xml:

        <xslt in="${ng.result}/testng-results.xml" style="src/com/SatoriMainProject/xslt/testng-results.xsl"
              out="${ws.home}/XSLT_Reports/output/index.html" classpathref="test.c" processor="SaxonLiaison">
            <param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
            <param name="testNgXslt.showRuntimeTotals" expression="true"/>
        </xslt>
    </target>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.