如何获取WebPage中当前AJAX调用的列表以及如何以编程方式跟踪(如果已完成)

时间:2022-06-17 15:16:05

I have an interesting testing issue.
My requirement is to do performance test on a web site.

我有一个有趣的测试问题。我的要求是在网站上进行性能测试。

Issue here to get the REAL time taking to load the web page (i am testing). The word REAL time i refer here as the total time taken to finished all the (initial) AJAX calls (with some response). I thought of using Page Load Event.
But this approach does not give the REAL time.
Any suggestions how to do it any reference to the information is also great!

在这里发布以获得加载网页的实时时间(我正在测试)。单词REAL time在这里指的是完成所有(初始)AJAX调用所需的总时间(带有一些响应)。我想过使用Page Load Event。但这种方法并没有给出实时。任何建议如何做任何参考信息也很棒!


My environment: Java and WedDriver.

我的环境:Java和WedDriver。

2 个解决方案

#1


0  

Tag your request objects with a timestamp and subtract this from the systime when the corresponding response is received.

使用时间戳标记您的请求对象,并在收到相应的响应时从systime中减去该值。

Depending on your methodology you could have generic Request/Response object with a <T> payload and a demuxer on the server side. These generic objects could then contain code to automagically register the time when sent and received and provide the time spent to the client. Aggregating time spent for an entire page to load is a bit trickier with this approach, but not near impossible I should think - the RPC proxy might keep track of that if requests are also tagged with the originating page.

根据您的方法,您可以使用带有 有效负载的通用Request / Response对象和服务器端的分路器。然后,这些通用对象可以包含用于自动注册发送和接收时间的代码,并提供花费在客户端上的时间。使用这种方法聚合整个页面加载所花费的时间有点棘手,但我认为并非几乎不可能 - 如果请求也使用原始页面标记,RPC代理可能会跟踪它。

if you were to provide some concrete example of your setup/code I might be able to be more precise.

如果您要提供一些具体的设置/代码示例,我可能会更精确。

Cheers,

#2


0  

As everyone said, WebDriver is not meant for Performance. However, see the following method that I use sometimes.

正如大家所说,WebDriver不适用于性能。但是,请参阅我有时使用的以下方法。

Following code will work if you can capture the performance against some particular webelement, can be a div or a span block.

如果您可以针对某个特定的webelement捕获性能,则以下代码将起作用,可以是div或span块。

1 Use any stopwatch. I am using apache stopwatch.

1使用任何秒表。我正在使用apache秒表。

import org.apache.commons.lang3.time.StopWatch;

2 Initialize the variable

2初始化变量

StopWatch timer = new StopWatch();

3 Start the timer and in next line navigate to your page. I prefer driver.navigate().to() than driver.get() as I feel it reduces other processing time to invoke a fresh URL.

3启动计时器,然后在下一行中导航到您的页面。我更喜欢driver.navigate()。to()而不是driver.get(),因为我觉得它减少了调用新URL的其他处理时间。

timer.start();
driver.navigate().to(URL); 

4 Wait for a particular element that can specify page loading finished. Once it appear, in next line stop the timer.

4等待可以指定页面加载完成的特定元素。一旦出现,在下一行停止计时器。

new WebDriverWait(driver, 10).until(ExpectedConditions. presenceOfElementLocated(By.className("demoClass")));
timer.stop();
System.out.println("timer.getTime() + " milliseconds");

Additional Note: If you want to know the loading time of Network calls of any particular webapge load, use webkit like phantomJS or thing like browsermobproxy. It will return network calls in HAR/JSON file. Parse those files and you may get your time.

附加说明:如果您想知道任何特定webapge加载的网络调用的加载时间,请使用像phantomJS这样的webkit或者像browsermobproxy这样的东西。它将在HAR / JSON文件中返回网络调用。解析这些文件,你可能会得到你的时间。

Hope this helps.

希望这可以帮助。

#1


0  

Tag your request objects with a timestamp and subtract this from the systime when the corresponding response is received.

使用时间戳标记您的请求对象,并在收到相应的响应时从systime中减去该值。

Depending on your methodology you could have generic Request/Response object with a <T> payload and a demuxer on the server side. These generic objects could then contain code to automagically register the time when sent and received and provide the time spent to the client. Aggregating time spent for an entire page to load is a bit trickier with this approach, but not near impossible I should think - the RPC proxy might keep track of that if requests are also tagged with the originating page.

根据您的方法,您可以使用带有 有效负载的通用Request / Response对象和服务器端的分路器。然后,这些通用对象可以包含用于自动注册发送和接收时间的代码,并提供花费在客户端上的时间。使用这种方法聚合整个页面加载所花费的时间有点棘手,但我认为并非几乎不可能 - 如果请求也使用原始页面标记,RPC代理可能会跟踪它。

if you were to provide some concrete example of your setup/code I might be able to be more precise.

如果您要提供一些具体的设置/代码示例,我可能会更精确。

Cheers,

#2


0  

As everyone said, WebDriver is not meant for Performance. However, see the following method that I use sometimes.

正如大家所说,WebDriver不适用于性能。但是,请参阅我有时使用的以下方法。

Following code will work if you can capture the performance against some particular webelement, can be a div or a span block.

如果您可以针对某个特定的webelement捕获性能,则以下代码将起作用,可以是div或span块。

1 Use any stopwatch. I am using apache stopwatch.

1使用任何秒表。我正在使用apache秒表。

import org.apache.commons.lang3.time.StopWatch;

2 Initialize the variable

2初始化变量

StopWatch timer = new StopWatch();

3 Start the timer and in next line navigate to your page. I prefer driver.navigate().to() than driver.get() as I feel it reduces other processing time to invoke a fresh URL.

3启动计时器,然后在下一行中导航到您的页面。我更喜欢driver.navigate()。to()而不是driver.get(),因为我觉得它减少了调用新URL的其他处理时间。

timer.start();
driver.navigate().to(URL); 

4 Wait for a particular element that can specify page loading finished. Once it appear, in next line stop the timer.

4等待可以指定页面加载完成的特定元素。一旦出现,在下一行停止计时器。

new WebDriverWait(driver, 10).until(ExpectedConditions. presenceOfElementLocated(By.className("demoClass")));
timer.stop();
System.out.println("timer.getTime() + " milliseconds");

Additional Note: If you want to know the loading time of Network calls of any particular webapge load, use webkit like phantomJS or thing like browsermobproxy. It will return network calls in HAR/JSON file. Parse those files and you may get your time.

附加说明:如果您想知道任何特定webapge加载的网络调用的加载时间,请使用像phantomJS这样的webkit或者像browsermobproxy这样的东西。它将在HAR / JSON文件中返回网络调用。解析这些文件,你可能会得到你的时间。

Hope this helps.

希望这可以帮助。