Watir Webdriver自帶一個gem Watir-WebDriver-Performance, 可以對頁面的性能進行一些簡單的測試。
方法如下:
require 'watir-webdriver'
require 'watir-webdriver-performance'
b = Watir::Browser.new :chrome
10.times do
b.goto 'http://watir.com'
load_secs = b.performance.summary[:response_time]/1000
puts "Load Time: #{load_secs} seconds."
end
得到的結(jié)果如下:
Load Time: 3.701 seconds.
Load Time: 0.694 seconds.
Load Time: 1.874 seconds.
Load Time: 1.721 seconds.
Load Time: 2.096 seconds.
Load Time: 0.823 seconds.
Load Time: 2.362 seconds.
Load Time: 1.008 seconds.
Load Time: 1.761 seconds.
Load Time: 2.066 seconds.
可以用的方法除了response_time之外,還有:
:summary
:navigation
:memory
:timing
注意,目前只能支持chrome和IE9的版本