Я хочу рассчитать время загрузки страницы в Watir или Selenium - PullRequest
3 голосов
/ 14 ноября 2010

Вот сценарий:

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

Ответы [ 2 ]

3 голосов
/ 02 декабря 2010

Любой вызов метода в 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}"
1 голос
/ 14 ноября 2010

Существует новая спецификация, внедряемая во все современные браузеры. В настоящее время он встроен в 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
*/
...