kamal
kamal

Reputation: 9785

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

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

Upvotes: 3

Views: 1917

Answers (2)

Alister Scott
Alister Scott

Reputation: 3685

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

Upvotes: 3

AutomatedTester
AutomatedTester

Reputation: 22418

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

Upvotes: 1

Related Questions