Class: Watir::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/test_performance.rb

Instance Method Summary collapse

Instance Method Details

#performanceObject



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/test_performance.rb', line 157

def performance
  data =
    case driver.browser
      when :internet_explorer
        Object::JSON.parse(driver.execute_script(performance_test_for_ie))
      else
        driver.execute_script(performance_test)
    end
  performance_error if data.nil?
  PerformanceData.new(data).mapping
end

#performance_dataObject Also known as: performance_supported?



173
174
175
# File 'lib/test_performance.rb', line 173

def performance_data
  driver.execute_script(performance_test)
end

#performance_errorObject



179
180
181
182
183
# File 'lib/test_performance.rb', line 179

def performance_error
  raise "Unable to collect performance metrics from the current "\
    "browser. Make sure the browser you are using supports collecting "\
    "performance metrics."
end

#performance_testObject



185
186
187
188
189
# File 'lib/test_performance.rb', line 185

def performance_test
  "return window.performance || "\
    "window.webkitPerformance || window.mozPerformance || "\
    "window.msPerformance;"
end

#performance_test_for_ieObject



191
192
193
# File 'lib/test_performance.rb', line 191

def performance_test_for_ie
  "return JSON.stringify(window.performance.toJSON());"
end

#with_performance {|PerformanceData.new(performance_data).mapping| ... } ⇒ Object

Yields:



169
170
171
# File 'lib/test_performance.rb', line 169

def with_performance
  yield PerformanceData.new(performance_data).mapping if performance_supported?
end