Watir Page performance feature allows you to track the response time metrics and it works fine in Chrome, Firefox, IE9 and above. Safari browser does not have the support as of now.
Let us take a closer look on how to use this feature. To make use of it, we need to install watir-performance using gem as shown below −
gem install watir-performance
We are done with installing watir-performance. The metrics that are supported are −
A working example using watir-performance is discussed here. Here, we will check the response time for site − www.howcodex.com as shown below −
require 'watir' require 'watir-performance' 10.times do b = Watir::Browser.new :chrome b.goto 'https://www.howcodex.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.howcodex.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.
require 'watir' require 'watir-performance' b = Watir::Browser.new :chrome b.goto 'https://www.howcodex.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.howcodex.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}