selenium_statistics 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2d0106cb43aed51cad99acb471dad749f5618db
4
+ data.tar.gz: 53fe5830dbd6ca24ae03a521da68640127f0782c
5
+ SHA512:
6
+ metadata.gz: 3551ef36601de6274aa10ba0967ea6c93cf5abd261b861bc1e1292ae8d9d12ba0be698d5c54c721748d870a55d6bcf2a26df8edf86b7469fd1a87036332fe75a
7
+ data.tar.gz: 42a6e4cde320961583df451f9be4e277a567471863da872ebd37b80d6337fa9e958e5e44e4640e0e43ab14eb07181602fdd71430b0a7bdd0099ff381bf903f22
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Titus Fortner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # SeleniumStatistics
2
+
3
+ This gem will collect counts and times for each selenium command your code issues.
4
+
5
+ ## Usage
6
+
7
+ When gem is required, statistics will be collected for each wire call.
8
+ To access current results, call ```SeleniumStatistics.results```
9
+
10
+ Additional debugging information can be obtained by setting ```ENV['DEBUG'] = 'true'```
11
+
12
+ ## Contributing
13
+
14
+ 1. Fork it ( https://github.com/[my-github-username]/selenium_statistics/fork )
15
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
16
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
17
+ 4. Push to the branch (`git push origin my-new-feature`)
18
+ 5. Create a new Pull Request
19
+
20
+ ## Copyright
21
+
22
+ Copyright (c) 2016 Titus Fortner. See LICENSE for details.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 (2015-03-24)
2
+
3
+ * Output counts and times for all Selenium wire commands
@@ -0,0 +1,5 @@
1
+ require 'selenium-webdriver'
2
+
3
+ require "selenium_statistics/version"
4
+ require 'selenium_statistics/statistics'
5
+ require 'selenium_statistics/bridge'
@@ -0,0 +1,27 @@
1
+ module Selenium
2
+
3
+ module WebDriver
4
+ module Remote
5
+ class Bridge
6
+
7
+ alias_method :webdriver_execute, :execute
8
+
9
+ def execute(*args)
10
+ command = args[0]
11
+
12
+ start_time = Time.now
13
+ begin
14
+ return_value = webdriver_execute(*args)
15
+ SeleniumStatistics.send("#{command}=", Time.now - start_time)
16
+ rescue Exception => ex
17
+ SeleniumStatistics.send("#{command}=", Time.now - start_time)
18
+ raise
19
+ end
20
+
21
+ return_value
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ module SeleniumStatistics
2
+
3
+ extend self
4
+
5
+ attr_reader :time, :executions
6
+
7
+ @commands = {}
8
+ @executions = 0
9
+ @time = 0
10
+
11
+ Selenium::WebDriver::Remote::Bridge::COMMANDS.keys.each do |command|
12
+ define_method("#{command}=") do |time|
13
+ @commands[command] ||= {}
14
+
15
+ @commands[command][:time] ||= 0
16
+ @commands[command][:count] ||= 0
17
+
18
+ @commands[command][:time] += time
19
+ @commands[command][:count] += 1
20
+ @commands[command][:average] = @commands[command][:time] / @commands[command][:count]
21
+
22
+ @executions += 1
23
+ @time += time
24
+
25
+ if ENV['DEBUG'] == 'true'
26
+ puts "Executed #{command} in #{time} sec"
27
+ end
28
+ end
29
+
30
+ define_method(command) do
31
+ @commands[command]
32
+ end
33
+
34
+ @test_start = Time.now
35
+ end
36
+
37
+ def results(sort=nil)
38
+ sort ||= :count
39
+ @test_time = Time.now - @test_start
40
+
41
+ @commands.each { |_k, v| v[:average_total] = v[:time]/@test_time}
42
+ @commands.sort_by { |_k, v| v[sort] }.reverse.to_h
43
+ end
44
+
45
+ def print_results(sort=nil)
46
+ str = "Executed a total of #{executions} commands in #{time.round(1)} seconds\n"
47
+
48
+ 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"
53
+ end
54
+
55
+ puts str
56
+ end
57
+
58
+ def reset!
59
+ @commands = {}
60
+ @time = 0
61
+ @executions = 0
62
+ @test_start = Time.now
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module SeleniumStatistics
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'selenium_statistics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "selenium_statistics"
8
+ spec.version = SeleniumStatistics::VERSION
9
+ spec.authors = ["Titus Fortner"]
10
+ spec.email = ["titusfortner@gmail.com"]
11
+ spec.summary = %q{Generate information about Selenium commands}
12
+ spec.description = %q{Generate information about Selenium commands}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "selenium-webdriver"
25
+
26
+ end
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ Test Page
5
+ </title>
6
+ </head>
7
+ <body>
8
+ <h1>Test Page</h1>
9
+ </body>
10
+ </html>
@@ -0,0 +1,10 @@
1
+ require "selenium_statistics"
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.after(:each) do
6
+ puts SeleniumStatistics.results
7
+ SeleniumStatistics.reset!
8
+ end
9
+
10
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'Selenium Statistics' do
4
+
5
+ let(:driver) {Selenium::WebDriver.for :chrome}
6
+ let(:html) { File.expand_path(File.dirname(__FILE__) + '/html/test.html') }
7
+
8
+ after(:each) do
9
+ driver.quit
10
+ end
11
+
12
+ specify 'records total command count' do
13
+ driver.get "file://#{html}"
14
+ driver.title
15
+ expect(SeleniumStatistics.executions).to eql(2)
16
+ end
17
+
18
+ specify 'records total command time' do
19
+ driver.get "file://#{html}"
20
+ driver.title
21
+ expect(SeleniumStatistics.executions).to eql(2)
22
+ end
23
+
24
+ specify 'records time and count for each command' do
25
+ driver.get "file://#{html}"
26
+ driver.title
27
+
28
+ expect(SeleniumStatistics.getTitle[:count]).to eql(1)
29
+ expect(SeleniumStatistics.getTitle[:time]).to be > 0
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium_statistics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Titus Fortner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Generate information about Selenium commands
70
+ email:
71
+ - titusfortner@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/CHANGES.md
82
+ - lib/selenium_statistics.rb
83
+ - lib/selenium_statistics/bridge.rb
84
+ - lib/selenium_statistics/statistics.rb
85
+ - lib/selenium_statistics/version.rb
86
+ - selenium_statistics.gemspec
87
+ - spec/html/test.html
88
+ - spec/spec_helper.rb
89
+ - spec/statistics_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Generate information about Selenium commands
114
+ test_files:
115
+ - spec/html/test.html
116
+ - spec/spec_helper.rb
117
+ - spec/statistics_spec.rb
118
+ has_rdoc: