UI 应用程序页面加载时间的测量 [英] Measurement of UI application page load time

查看:27
本文介绍了UI 应用程序页面加载时间的测量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始进行 UI 测试,想知道是否有任何工具可以计算加载 UI 页面以加载到浏览器中所需的时间,包括服务器响应时间(我的意思是从请求发送到浏览器的总时间)页面加载).我知道可以使用萤火虫/开发人员工具手动查找它,但还有其他方法可以做到这一点.使用 selenium,我可以使用 Firefox 驱动程序并找出获取页面所需的时间并报告该时间,但我不确定这是否是正确的时间.

I have recently started working on UI testing and was wondering if there is any tool to figure out the time it takes to load the UI page to load in browser including the server response time ( i mean total browser time from request send till page load ). I know that firebug/developer tools can be used to find it manually but is there any other way of doing it. Using selenium, i could use firefox driver and find out the time it takes to get the page and report that time, but i am not sure if it is the correct time.

推荐答案

关于解决方案的几句话:

A few words about the solution:

我们将借助 Google Chrome 浏览器作为参考.正如我们所知,当页面完全加载时,浏览器将 Document.ReadyState 作为 Complete 返回给 Selenium.这就是 Selenium 执行下一行代码的时候.我们将启动计时器并开始加载网页.当 document.readyState 设置为 complete 时,我们将停止计时器.这是 Selenium-Java 代码块:

We will take help of Google Chrome browser for our reference. As we know when a page loads completely the browser returns Document.ReadyState as Complete to Selenium. That's when Selenium executes the next line of code. We will start the timer and start loading the webpage. When ever the document.readyState will be set to complete we will stop the timer. Here is the Selenium-Java code block:

package demo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Q_44643596_measurement_application_load {

    public static void main(String[] args) {


        System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
        WebDriver driver =  new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 30);
        long start = System.currentTimeMillis();
        driver.get("https://stackoverflow.com/");
        boolean pageLoaded = wait.until(ExpectedConditions.jsReturnsValue("return document.readyState")).equals("complete");
        long finish = System.currentTimeMillis();
        System.out.println("Page has loaded? " + pageLoaded);

        long totalTime = finish - start; 
        System.out.println("Total Time (in Milli Seconds) for page load - "+totalTime);

    }

}

这篇关于UI 应用程序页面加载时间的测量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆