2010-11-14 26 views
3

頁面加載時間這裏的情景:我想計算的Watir或硒

 
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 

回答

3

中的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

有一個新的規格被引入到所有現代瀏覽器。目前谷歌瀏覽器,IE9已經內置,Mozilla正在等待應用已經提供的補丁。

這種新規範被稱爲WebTimings,我寫了一個blog post展示瞭如何使用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 
*/ 
+0

大文章,但我怕你會告訴我,我們不能在硒1.0.8做到這一點。這是1.0.8還是需要Selenium 2測試版?另外,最新的計時對象聽起來像是它們不適用於Firefox 3,這是正確的嗎? – MADCookie 2010-12-01 19:36:43