module SeleniumStatistics

Returns logger instance that can be used throughout Selenium Run.

@return [Logger]

Code adapted from Selenium Implementation github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/logger.rb

Attributes

commands[R]
executions[R]
time[R]

Public Class Methods

logger() click to toggle source
# File lib/selenium_statistics.rb, line 11
def self.logger
  @logger ||= SeleniumStatistics::Logger.new
end

Public Instance Methods

method_missing(command, time = nil) click to toggle source
# File lib/selenium_statistics/statistics.rb, line 12
def method_missing(command, time = nil)
  command = command.to_s
  command.gsub!('get_element_location_once_scrolled_into_view', 'get_element_location')
  command.gsub!('get_element_value_of_css_property', 'get_element_css_value')

  return @commands[command] unless command =~ /=$/

  command = command.chomp('=')

  @commands[command] ||= {}

  @commands[command][:time] ||= 0
  @commands[command][:count] ||= 0

  @commands[command][:time] += time
  @commands[command][:count] += 1
  @commands[command][:average] =  @commands[command][:time] / @commands[command][:count]

  @executions += 1
  @time += time

  SeleniumStatistics.logger.info "Executed #{command} in #{time} sec"
  SeleniumStatistics.logger.debug "#{command} executed total of #{@commands[command][:count]} times in #{ @commands[command][:time]} seconds"
end
print_results(sort=nil) click to toggle source
reset!() click to toggle source
# File lib/selenium_statistics/statistics.rb, line 59
def reset!
  @commands = {}
  @time = 0
  @executions = 0
  @test_start = Time.now
end
results(sort=nil) click to toggle source
# File lib/selenium_statistics/statistics.rb, line 37
def results(sort=nil)
  sort ||= :count
  @test_time = Time.now - @test_start

  @commands.each { |_k, v| v[:average_total] = v[:time]/@test_time}
  @commands.sort_by { |_k, v| v[sort] }.reverse.to_h
end