- Watir Tutorial
- Watir - Home
- Watir - Overview
- Watir - Introduction
- Watir - Environment Setup
- Watir - Installing Drivers for Browsers
- Watir - Working with Browsers
- Watir - Web Elements
- Watir - Locating Web Elements
- Watir - Working with Iframes
- Watir - Automatic Waits
- Watir - Headless Testing
- Watir - Mobile Testing
- Watir - Capturing Screenshots
- Watir - Page Objects
- Watir - Page Performance
- Watir - Cookies
- Watir - Proxies
- Watir - Alerts
- Watir - Downloads
- Watir - Browser Windows
- Watir Useful Resources
- Watir - Quick Guide
- Watir - Useful Resources
- Watir - Discussion
Watir - Page Performance
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 −
Command
gem install watir-performance
We are done with installing watir-performance. The metrics that are supported are −
- summary
- navigation
- memory
- Timing
A working example using watir-performance is discussed here. Here, we will check the response time for site − www.tutorialspoint.com as shown below −
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
output
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.
Using performance.timing
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
output
Time taken to respond is 41 seconds.
Using 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
output
{:type_back_forward=>2, :type_navigate=>0, :type_reload=>1, :type_reserved=>255, :redirect_count=>0, :to_json=>{}, :type=>0}
Using performance.memory
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
output
{: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}
Advertisements
To Continue Learning Please Login
Login with Google