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
得到的结果如下:
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的版本