Module: SeleniumStatistics

Extended by:
SeleniumStatistics
Included in:
SeleniumStatistics
Defined in:
lib/selenium_statistics.rb,
lib/selenium_statistics/logger.rb,
lib/selenium_statistics/statistics.rb

Overview

Defined Under Namespace

Classes: Logger

Constant Summary collapse

COMMANDS =
Selenium::WebDriver::Remote::Bridge::COMMANDS.keys +
Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS.keys +
Selenium::WebDriver::Remote::OSS::Bridge::COMMANDS.keys

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#executionsObject (readonly)

Returns the value of attribute executions.



5
6
7
# File 'lib/selenium_statistics/statistics.rb', line 5

def executions
  @executions
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/selenium_statistics/statistics.rb', line 5

def time
  @time
end

Class Method Details

.loggerObject



11
12
13
# File 'lib/selenium_statistics.rb', line 11

def self.logger
  @logger ||= SeleniumStatistics::Logger.new
end

Instance Method Details

#get_element_location_once_scrolled_into_view=(*args) ⇒ Object



47
48
49
# File 'lib/selenium_statistics/statistics.rb', line 47

def get_element_location_once_scrolled_into_view=(*args)
  self.get_element_location= args.first
end

#get_element_value_of_css_property=(*args) ⇒ Object



51
52
53
# File 'lib/selenium_statistics/statistics.rb', line 51

def get_element_value_of_css_property=(*args)
  self.get_element_css_value= args.first
end


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/selenium_statistics/statistics.rb', line 63

def print_results(sort=nil)
  str = "Executed a total of #{executions} commands in #{time.round(1)} seconds\n\n"

  results(sort).each do |k,v|
    str << "#{k.to_s}:".ljust(27, ' ')
    str << "executions: #{v[:count].to_s.rjust(executions.size, ' ')}; "
    str << "total seconds: #{v[:time].round(1).to_s.rjust(time.round(1).to_s.size, ' ')}; "
    str << "avg sec/cmd: #{v[:average].round(3).to_s.rjust(5, ' ')}; "
    str << "total: #{(100*v[:average_total]).round(2).to_s.rjust(5, ' ')}%\n"
  end

  SeleniumStatistics.logger.warn str
end

#reset!Object



77
78
79
80
81
82
# File 'lib/selenium_statistics/statistics.rb', line 77

def reset!
  @commands = {}
  @time = 0
  @executions = 0
  @test_start = Time.now
end

#results(sort = nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/selenium_statistics/statistics.rb', line 55

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