Watir-Webdriver-Performance gem released

Today I added a simple watir-webdriver-performance gem whose purpose is to collect performance metrics specified for web applications to access timing information related to navigation and elements.

User latency is an important quality benchmark for Web Applications. While JavaScript-based mechanisms can provide comprehensive instrumentation for user latency measurements within an application, in many cases, they are unable to provide a complete end-to-end latency picture.

To address the need for complete information on user experience, this document introduces the PerformanceTiming interfaces. This interface allows JavaScript mechanisms to provide complete client-side latency measurements within applications. With the proposed interface, the previous example can be modified to measure a user’s perceived page load time.

You can read more about the PerformanceTiming specification here. Essentially this gem collects all available metrics from the browser and summarises them in a format similar to the following diagram:

timing-overview

To use this gem simply install:

 gem install watir-webdriver-performance

And use the browser.performance helper method to access the metrics.

>> require 'watir-webdriver'
>> require 'watir-webdriver-performance'
>> b = Watir::Browser.new :chrome
>> b.goto "watirgrid.com"
=> "https://github.com/90kts/watirgrid"
>> # End user response time was
?> b.performance.summary[:response_time]/1000
=> 8
>> #seconds ...
?> # Time to first byte i.e. "server time" was
?> b.performance.summary[:time_to_first_byte]
=> 3341
>> #milliseconds ...
?> # Summary timings available
{
    :summary => {
                   :redirect=>0,
                  :app_cache=>0,
                        :dns=>0,
            :tcp_connection=>982,
     :tcp_connection_secure=>721,
                  :request=>1222,
                    :response=>4,
           :dom_processing=>4293,
            :response_time=>7298,
       :time_to_first_byte=>2205,
        :time_to_last_byte=>2209
    },
    :navigation => {
                     :type => 0,
        :type_back_forward => 2,
           :redirect_count => 0,
            :type_reserved => 255,
            :type_navigate => 0,
              :type_reload => 1
    },
        :memory => {
        :total_js_heap_size => 0,
        :js_heap_size_limit => 0,
         :used_js_heap_size => 0
    },
        :timing => {
                   :domain_lookup_start => 1303180421599,
                        :load_event_end => 0,
                           :connect_end => 1303180421642,
                          :response_end => 1303180421853,
                           :dom_loading => 1303180421840,
                      :navigation_start => 0,
                          :redirect_end => 0,
                    :unload_event_start => 0,
               :secure_connection_start => 0,
                         :connect_start => 1303180421600,
          :dom_content_loaded_event_end => 1303180421934,
                     :domain_lookup_end => 1303180421600,
                       :dom_interactive => 1303180421934,
                      :load_event_start => 0,
                         :request_start => 1303180421642,
                        :response_start => 1303180421838,
                          :dom_complete => 0,
                           :fetch_start => 1303180421598,
        :dom_content_loaded_event_start => 1303180421934,
                        :redirect_start => 0,
                      :unload_event_end => 0
    }
  }
Social tagging: >

5 Responses to Watir-Webdriver-Performance gem released

  1. This is quite awesome! Well done!

  2. Mordechai

    Hi Tim,

    Was trying to mess around with your example tried both in chrome and ff and got the same issue. Seems like its bombing out in the munge function because data is nil – not sure, am I doing something wrong?

    irb(main):010:0> b.goto ‘yahoo.com’
    => “http://www.yahoo.com/”
    irb(main):011:0> b.performance.summary[:response_time]/1000
    NoMethodError: undefined method `each_key’ for nil:NilClass
    from /usr/lib/ruby/gems/1.9.1/gems/watir-webdriver-performance-0.1.1/lib/watir-webdriver-performance.rb:15:in `munge’
    from /usr/lib/ruby/gems/1.9.1/gems/watir-webdriver-performance-0.1.1/lib/watir-webdriver-performance.rb:80:in `performance’
    from (irb):11
    from /usr/local/bin/irb:12:in `’

    Regards
    Mordechai

    • Tim Koopmans

      Hi Mordechai,

      It’s probably because you are using firefox. Some versions of browsers
      don’t return any performance data, hence the nilClass error you are
      getting. Currently Google Chrome & IE9 have it built in and Mozilla is
      waiting to apply the patch that has been supplied.

      I’d suggest using a current version of :chrome or :ie instead.

      You can check to see if your browser supports performance extensions
      using a javascript console such as firebug or the like:
      window.performance || window.webkitPerformance ||
      window.mozPerformance || window.msPerformance;

  3. Pingback: A Smattering of Selenium #49 « Official Selenium Blog