Sha256: 544a14663ac88ec5c1c05376bb4605700abf8c9627dfc107a58c62b4ea78e61f

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

require "ostruct"

module Watir

  # Adds helper for window.performance to Watir::Browser.
  #
  # This module is provided by an optional require:
  #
  #   require "watir-webdriver/extensions/performance"
  #
  # @see http://dev.w3.org/2006/webapi/WebTiming/
  #

  module PerformanceHelper

    def performance
      data = driver.execute_script("return window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance;")
      data && Performance.new(data)
    end

    class Performance
      attr_reader :timing, :navigation, :memory

      def initialize(data)
        @timing     = rubify data['timing'] || {}
        @navigation = rubify data['navigation'] || {}
        @memory     = rubify data['memory'] || {}
      end

      private

      def rubify(hash)
        result = {}

        hash.each do |k, v|
          if k =~ /^[A-Z_]+$/
            k = k.downcase
          elsif k =~ /(start|end)$/i && Fixnum === v
            v = ::Time.at(v / 1000)
          end

          result[k.snake_case] = v
        end

        OpenStruct.new(result)
      end

    end # Performance
  end # PerformanceHelper

  class Browser
    include PerformanceHelper
  end
end # Watir

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
watir-webdriver-0.2.2 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.2.1 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.2.0 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.2.0.dev2 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.2.0.dev lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.9 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.8 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.7 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.6 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.5 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.4 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.3 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.2 lib/watir-webdriver/extensions/performance.rb
ayanko-watir-webdriver-0.1.1.1 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.1 lib/watir-webdriver/extensions/performance.rb
watir-webdriver-0.1.0 lib/watir-webdriver/extensions/performance.rb