Class: Watir::PerformanceHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-performance.rb

Overview

Adds helper for window.performance to Watir::Browser.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ PerformanceHelper

Returns a new instance of PerformanceHelper.


7
8
9
10
# File 'lib/watir-performance.rb', line 7

def initialize(data)
  @data = data
  @hash = {}
end

Instance Method Details

#data_to_hashObject


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/watir-performance.rb', line 16

def data_to_hash
  @data.each_key do |key|
    next if key == '__fxdriver_unwrapped'
    @hash[key.to_sym] = {}
    next unless @data[key].respond_to? :each
    @data[key].each do |k, v|
      next if k == '__fxdriver_unwrapped'
      @hash[key.to_sym][underscored(k).to_sym] = v
    end
  end
  @hash
end

#mungeObject


12
13
14
# File 'lib/watir-performance.rb', line 12

def munge
  OpenStruct.new(summarized_hash(data_to_hash))
end

#summarized_hash(hash) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/watir-performance.rb', line 29

def summarized_hash(hash)
  hash[:summary] = {}
  timing = hash[:timing]
  hash[:summary][:redirect] = redirect_timer(timing)
  hash[:summary][:app_cache] = app_cache(timing)
  hash[:summary][:dns] = hash[:timing][:domain_lookup_end] -
    hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
  hash[:summary][:tcp_connection] = hash[:timing][:connect_end] -
    hash[:timing][:connect_start] if hash[:timing][:connect_start] > 0
  hash[:summary][:tcp_connection_secure] = hash[:timing][:connect_end] -
    hash[:timing][:secure_connection_start] if
      ((hash[:timing][:secure_connection_start] != nil) and
       (hash[:timing][:secure_connection_start] > 0))
  hash[:summary][:request] = hash[:timing][:response_start] -
    hash[:timing][:request_start] if hash[:timing][:request_start] > 0
  hash[:summary][:response] = hash[:timing][:response_end] -
    hash[:timing][:response_start] if hash[:timing][:response_start] > 0
  hash[:summary][:dom_processing] = hash[:timing][:dom_content_loaded_event_start] -
    hash[:timing][:dom_loading] if hash[:timing][:dom_loading] > 0
  hash[:summary][:time_to_first_byte] = hash[:timing][:response_start] -
    hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
  hash[:summary][:time_to_last_byte] = hash[:timing][:response_end] -
    hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
  hash[:summary][:response_time] = latest_timestamp(hash) - earliest_timestamp(hash)
  hash
end