selenium_statistics 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2d0106cb43aed51cad99acb471dad749f5618db
4
- data.tar.gz: 53fe5830dbd6ca24ae03a521da68640127f0782c
3
+ metadata.gz: 77e448503173f57c45238666de809c26e4fc4a01
4
+ data.tar.gz: 8b9ce8869b07e13b15fe3c2f3da554509d59ee83
5
5
  SHA512:
6
- metadata.gz: 3551ef36601de6274aa10ba0967ea6c93cf5abd261b861bc1e1292ae8d9d12ba0be698d5c54c721748d870a55d6bcf2a26df8edf86b7469fd1a87036332fe75a
7
- data.tar.gz: 42a6e4cde320961583df451f9be4e277a567471863da872ebd37b80d6337fa9e958e5e44e4640e0e43ab14eb07181602fdd71430b0a7bdd0099ff381bf903f22
6
+ metadata.gz: babcef863915bf3d6e34cd4e852647bccdc44f5a3a3af166029ae7d4aaf03328452fad5a9081ccc3f8336e660990f0fabfb10efa77e183fbc17758e66f196fb2
7
+ data.tar.gz: 1fd1bf34cb7913962d0712a1b446194e47b1b3bd568483143e14ea31cb528f507afa378348e6375c70f78e284182c72da9dc4712e9fd7b6a4e3b979bab54f18a
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .idea
data/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # SeleniumStatistics
2
2
 
3
- This gem will collect counts and times for each selenium command your code issues.
3
+ This gem will collect counts and times for each wire call your code makes.
4
4
 
5
5
  ## Usage
6
6
 
7
7
  When gem is required, statistics will be collected for each wire call.
8
- To access current results, call ```SeleniumStatistics.results```
8
+ To access current results, call ```SeleniumStatistics.print_results```
9
9
 
10
- Additional debugging information can be obtained by setting ```ENV['DEBUG'] = 'true'```
10
+ Results can be ported to a file using ```SeleniumStatistics.logger.output = file_name```
11
+
12
+ Additional debugging information can be obtained by setting
13
+ ```SeleniumStatistics.logger = :info``` or ```SeleniumStatistics.logger = :debug```
11
14
 
12
15
  ## Contributing
13
16
 
14
- 1. Fork it ( https://github.com/[my-github-username]/selenium_statistics/fork )
17
+ 1. Fork it ( https://github.com/titusfortner/selenium_statistics/fork )
15
18
  2. Create your feature branch (`git checkout -b my-new-feature`)
16
19
  3. Commit your changes (`git commit -am 'Add some feature'`)
17
20
  4. Push to the branch (`git push origin my-new-feature`)
@@ -19,4 +22,4 @@ Additional debugging information can be obtained by setting ```ENV['DEBUG'] = 't
19
22
 
20
23
  ## Copyright
21
24
 
22
- Copyright (c) 2016 Titus Fortner. See LICENSE for details.
25
+ Copyright (c) 2016-2017 Titus Fortner. See LICENSE for details.
@@ -1,4 +1,17 @@
1
1
  require 'selenium-webdriver'
2
+ require 'selenium_statistics/logger'
3
+
4
+ #
5
+ # Returns logger instance that can be used throughout Selenium Run.
6
+ #
7
+ # @return [Logger]
8
+ #
9
+
10
+ module SeleniumStatistics
11
+ def self.logger
12
+ @logger ||= SeleniumStatistics::Logger.new
13
+ end
14
+ end
2
15
 
3
16
  require "selenium_statistics/version"
4
17
  require 'selenium_statistics/statistics'
@@ -0,0 +1,109 @@
1
+ require 'forwardable'
2
+ require 'logger'
3
+
4
+ # Code adapted from Selenium Implementation
5
+ # https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/logger.rb
6
+
7
+ module SeleniumStatistics
8
+ #
9
+ # @example Enable full logging
10
+ # SeleniumStatistics.logger.level = :debug
11
+ #
12
+ # @example Log to file
13
+ # SeleniumStatistics.logger.output = 'watir.log'
14
+ #
15
+ # @example Use logger manually
16
+ # SeleniumStatistics.logger.info('This is info message')
17
+ # SeleniumStatistics.logger.warn('This is warning message')
18
+ #
19
+ class Logger
20
+ extend Forwardable
21
+ include ::Logger::Severity
22
+
23
+ def_delegators :@logger, :debug, :debug?,
24
+ :info, :info?,
25
+ :warn, :warn?,
26
+ :error, :error?,
27
+ :fatal, :fatal?,
28
+ :level
29
+
30
+ def initialize
31
+ @logger = create_logger($stdout)
32
+ end
33
+
34
+ def output=(io)
35
+ # `Logger#reopen` was added in Ruby 2.3
36
+ if @logger.respond_to?(:reopen)
37
+ @logger.reopen(io)
38
+ else
39
+ @logger = create_logger(io)
40
+ end
41
+ end
42
+
43
+ #
44
+ # For Ruby < 2.3 compatibility
45
+ # Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
46
+ #
47
+
48
+ def level=(severity)
49
+ if severity.is_a?(Integer)
50
+ @logger.level = severity
51
+ else
52
+ case severity.to_s.downcase
53
+ when 'debug'.freeze
54
+ @logger.level = DEBUG
55
+ when 'info'.freeze
56
+ @logger.level = INFO
57
+ when 'warn'.freeze
58
+ @logger.level = WARN
59
+ when 'error'.freeze
60
+ @logger.level = ERROR
61
+ when 'fatal'.freeze
62
+ @logger.level = FATAL
63
+ when 'unknown'.freeze
64
+ @logger.level = UNKNOWN
65
+ else
66
+ raise ArgumentError, "invalid log level: #{severity}"
67
+ end
68
+ end
69
+ end
70
+
71
+ #
72
+ # Returns IO object used by logger internally.
73
+ #
74
+ # Normally, we would have never needed it, but we want to
75
+ # use it as IO object for all child processes to ensure their
76
+ # output is redirected there.
77
+ #
78
+ # It is only used in debug level, in other cases output is suppressed.
79
+ #
80
+ # @api private
81
+ #
82
+ def io
83
+ @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
84
+ end
85
+
86
+ #
87
+ # Marks code as deprecated with replacement.
88
+ #
89
+ # @param [String] old
90
+ # @param [String] new
91
+ #
92
+ def deprecate(old, new)
93
+ warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
94
+ end
95
+
96
+ private
97
+
98
+ def create_logger(output)
99
+ logger = ::Logger.new(output)
100
+ logger.progname = 'SeleniumStatistics'
101
+ logger.level = ($DEBUG ? DEBUG : WARN)
102
+ logger.formatter = proc do |severity, time, progname, msg|
103
+ "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
104
+ end
105
+
106
+ logger
107
+ end
108
+ end
109
+ end
@@ -8,7 +8,18 @@ module SeleniumStatistics
8
8
  @executions = 0
9
9
  @time = 0
10
10
 
11
- Selenium::WebDriver::Remote::Bridge::COMMANDS.keys.each do |command|
11
+ COMMANDS = Selenium::WebDriver::Remote::Bridge::COMMANDS.keys +
12
+ Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS.keys +
13
+ Selenium::WebDriver::Remote::OSS::Bridge::COMMANDS.keys
14
+
15
+ COMMANDS.each do |command|
16
+ if command == :get_element_location_once_scrolled_into_view
17
+ command = :get_element_location
18
+ end
19
+ if command == :get_element_value_of_css_property
20
+ command = :get_element_css_value
21
+ end
22
+
12
23
  define_method("#{command}=") do |time|
13
24
  @commands[command] ||= {}
14
25
 
@@ -22,9 +33,8 @@ module SeleniumStatistics
22
33
  @executions += 1
23
34
  @time += time
24
35
 
25
- if ENV['DEBUG'] == 'true'
26
- puts "Executed #{command} in #{time} sec"
27
- end
36
+ SeleniumStatistics.logger.info "Executed #{command} in #{time} sec"
37
+ SeleniumStatistics.logger.debug "#{command} executed total of #{@commands[command][:count]} times in #{ @commands[command][:time]} seconds"
28
38
  end
29
39
 
30
40
  define_method(command) do
@@ -34,6 +44,14 @@ module SeleniumStatistics
34
44
  @test_start = Time.now
35
45
  end
36
46
 
47
+ def get_element_location_once_scrolled_into_view=(*args)
48
+ self.get_element_location= args.first
49
+ end
50
+
51
+ def get_element_value_of_css_property=(*args)
52
+ self.get_element_css_value= args.first
53
+ end
54
+
37
55
  def results(sort=nil)
38
56
  sort ||= :count
39
57
  @test_time = Time.now - @test_start
@@ -43,16 +61,17 @@ module SeleniumStatistics
43
61
  end
44
62
 
45
63
  def print_results(sort=nil)
46
- str = "Executed a total of #{executions} commands in #{time.round(1)} seconds\n"
64
+ str = "Executed a total of #{executions} commands in #{time.round(1)} seconds\n\n"
47
65
 
48
66
  results(sort).each do |k,v|
49
- str << "\t#{k}: \n\t\t\t#{v[:count]} executions;"
50
- str << "\ttotal of #{v[:time].round(1)} sec;"
51
- str << "\tavg of #{v[:average].round(3)} sec/cmd;"
52
- str << "\t#{(100*v[:average_total]).round(2)}% of total\n"
67
+ str << "#{k.to_s}:".ljust(27, ' ')
68
+ str << "executions: #{v[:count].to_s.rjust(4, ' ')}; "
69
+ str << "total seconds: #{v[:time].round(1).to_s.rjust(5, ' ')}; "
70
+ str << "avg sec/cmd: #{v[:average].round(3).to_s.rjust(5, ' ')}; "
71
+ str << "total: #{(100*v[:average_total]).round(2).to_s.rjust(5, ' ')}%\n"
53
72
  end
54
73
 
55
- puts str
74
+ SeleniumStatistics.logger.warn str
56
75
  end
57
76
 
58
77
  def reset!
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'selenium_statistics/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "selenium_statistics"
8
- spec.version = SeleniumStatistics::VERSION
7
+ spec.version = "0.2.0"
9
8
  spec.authors = ["Titus Fortner"]
10
9
  spec.email = ["titusfortner@gmail.com"]
11
10
  spec.summary = %q{Generate information about Selenium commands}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,8 +81,8 @@ files:
81
81
  - lib/CHANGES.md
82
82
  - lib/selenium_statistics.rb
83
83
  - lib/selenium_statistics/bridge.rb
84
+ - lib/selenium_statistics/logger.rb
84
85
  - lib/selenium_statistics/statistics.rb
85
- - lib/selenium_statistics/version.rb
86
86
  - selenium_statistics.gemspec
87
87
  - spec/html/test.html
88
88
  - spec/spec_helper.rb
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.4.5.1
110
+ rubygems_version: 2.6.11
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Generate information about Selenium commands
@@ -115,4 +115,3 @@ test_files:
115
115
  - spec/html/test.html
116
116
  - spec/spec_helper.rb
117
117
  - spec/statistics_spec.rb
118
- has_rdoc:
@@ -1,3 +0,0 @@
1
- module SeleniumStatistics
2
- VERSION = "0.1.0"
3
- end