衡量页面性能  

Watir-Performance gem 旨在为 Watir 操作提供一组导航计时指标,使用 W3C 页面性能标准。这是捕获响应时间指标的完美解决方案,而且非常简单。适用于 Chrome、Firefox、Edge 和 IE9 及更高版本。目前不支持 Safari。

require 'watir'
require 'watir-performance'

10.times do
  b = Watir::Browser.new :chrome
  b.goto 'http://watir.com'
  load_secs = b.performance.summary[:response_time] / 1000
  puts "Load Time: #{load_secs} seconds."
  b.close
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.

可用指标分组列表

  • :summary
  • :navigation
  • :memory
  • :timing

上次更新:2018 年 8 月 2 日