Watir – 页面性能
Watir – 页面性能
Watir 页面性能功能允许您跟踪响应时间指标,它在 Chrome、Firefox、IE9 及更高版本中运行良好。Safari 浏览器目前不支持。
让我们仔细看看如何使用此功能。为了使用它,我们需要使用 gem 安装 watir-performance,如下所示 –
命令
gem install watir-performance
我们已经完成了 watir-performance 的安装。支持的指标是 –
- 概括
- 导航
- 记忆
- 定时
这里讨论了一个使用 watir-performance 的工作示例。在这里,我们将检查站点的响应时间 – www.tutorialspoint.com如下所示 –
require 'watir' require 'watir-performance' 10.times do b = Watir::Browser.new :chrome b.goto 'https://www.tutorialspoint.com' load_secs = b.performance.summary[:response_time] / 1000 puts "Load Time: #{load_secs} seconds." b.close end
输出
Load Time: 7 seconds. Load Time: 7 seconds. Load Time: 5 seconds. Load Time: 5 seconds. Load Time: 6 seconds. Load Time: 5 seconds. Load Time: 5 seconds. Load Time: 13 seconds. Load Time: 12 seconds. Load Time: 5 seconds.
使用性能计时
require 'watir' require 'watir-performance' b = Watir::Browser.new :chrome b.goto 'https://www.tutorialspoint.com' load_secs = b.performance.timing[:response_end] - b.performance.timing[:response_start] puts "Time taken to respond is #{load_secs} seconds." b.close
输出
Time taken to respond is 41 seconds.
使用 performance.navigation
require 'watir' require 'watir-performance' b = Watir::Browser.new :chrome b.goto 'https://www.tutorialspoint.com' perf_nav = b.performance.navigation puts "#{perf_nav}" b.close
输出
{:type_back_forward=>2, :type_navigate=>0, :type_reload=>1, :type_reserved=>255, :redirect_count=>0, :to_json=>{}, :type=>0}
使用性能内存
require 'watir' require 'watir-performance' b = Watir::Browser.new :chrome b.goto 'https://www.tutorialspoint.com' memory_used = b.performance.memory puts "#{memory_used}" b.close
输出
{:js_heap_size_limit=>2, :type_navigate=>0, :type_reload=>1, :ty2136997888, :total_js_heap_size=>2, :type_navigate=>0, :type_reload=>1, :ty12990756, :used_js_heap_size=>2, :type_navigate=>0, :type_reload=>1, :ty7127092}