I want to calculate the page load time in Watir or Selenium

守給你的承諾、 提交于 2019-12-06 07:55:05

问题


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

回答1:


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}"



回答2:


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
*/


来源:https://stackoverflow.com/questions/4177070/i-want-to-calculate-the-page-load-time-in-watir-or-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!