我想计算 Watir 或 Selenium 中的页面加载时间

发布于 2024-10-02 12:49:23 字数 256 浏览 0 评论 0原文

这是场景:

1. Login to a web application with username and password and hit Enter (Start timer)
2. Load the login page (lap timer split, to mark the time for page load )
3. Click on a another page (split the lap timer)
4. Stop the stop watch

Here is the scenario:

1. Login to a web application with username and password and hit Enter (Start timer)
2. Load the login page (lap timer split, to mark the time for page load )
3. Click on a another page (split the lap timer)
4. Stop the stop watch

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2024-10-09 12:49:23

Watir 中的任何方法调用都会返回所需的时间,因此这是一项微不足道的任务。

例如,

b.text_field(:id, 'uid').set username
b.text_field(:id, 'pwd').set password
time1 = b.button(:id, 'logon').click
time2 = b.button(:id,  'movepage').click
puts "Time One: #{time1} Time Two: #{time2} Total Time: #{time1+time2}"

Any method call in Watir returns how long it takes, so this is a trivial task.

For example,

b.text_field(:id, 'uid').set username
b.text_field(:id, 'pwd').set password
time1 = b.button(:id, 'logon').click
time2 = b.button(:id,  'movepage').click
puts "Time One: #{time1} Time Two: #{time2} Total Time: #{time1+time2}"
当梦初醒 2024-10-09 12:49:23

所有现代浏览器都引入了新的规范。目前 Google Chrome、IE9 已内置该补丁,Mozilla 正在等待应用已提供的补丁。

这个新规范称为 WebTimings,我写了一篇 博客文章 展示如何使用 C# 访问它。访问它的方式是通过 javascript,因此可以与所有语言绑定一起使用。

所需的 JavaScript 是

var performance = window.performance || window.webkitPerformance || window.mozPerformance window.msPerformance || {};
var timings = performance.timing || {};
return timings;

这会返回一个像这样的字典

/* The dictionary returned will contain something like the following.
* The values are in milliseconds since 1/1/1970
*
* connectEnd: 1280867925716
* connectStart: 1280867925687
* domainLookupEnd: 1280867925687
* domainLookupStart: 1280867925687
* fetchStart: 1280867925685
* legacyNavigationStart: 1280867926028
* loadEventEnd: 1280867926262
* loadEventStart: 1280867926155
* navigationStart: 1280867925685
* redirectEnd: 0
* redirectStart: 0
* requestEnd: 1280867925716
* requestStart: 1280867925716
* responseEnd: 1280867925940
* responseStart: 1280867925919
* unloadEventEnd: 1280867925940
*/

There is a new Spec being introduced into all modern browsers. Currently Google Chrome, IE9 have it built in and Mozilla is waiting to apply the patch that has been supplied.

This new spec is called WebTimings and I wrote a blog post showing how to access it using C#. The way to access it is via javascript so can be used with all language bindings.

The JavaScript needed is

var performance = window.performance || window.webkitPerformance || window.mozPerformance window.msPerformance || {};
var timings = performance.timing || {};
return timings;

This returns a dictionary like this

/* The dictionary returned will contain something like the following.
* The values are in milliseconds since 1/1/1970
*
* connectEnd: 1280867925716
* connectStart: 1280867925687
* domainLookupEnd: 1280867925687
* domainLookupStart: 1280867925687
* fetchStart: 1280867925685
* legacyNavigationStart: 1280867926028
* loadEventEnd: 1280867926262
* loadEventStart: 1280867926155
* navigationStart: 1280867925685
* redirectEnd: 0
* redirectStart: 0
* requestEnd: 1280867925716
* requestStart: 1280867925716
* responseEnd: 1280867925940
* responseStart: 1280867925919
* unloadEventEnd: 1280867925940
*/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文