watir-performance 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +80 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/examples/basic.rb +6 -0
- data/lib/idl_extractor.rb +55 -0
- data/lib/performance.rb +23 -0
- data/lib/watir-performance.rb +108 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/watir-performance-non-supported-browser_spec.rb +29 -0
- data/spec/watir-performance_spec.rb +46 -0
- data/watir-performance.gemspec +74 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fad33273008c01f7ee6b8bc43838ddce2816fbb01ff2b2645095728f0fb2983a
|
4
|
+
data.tar.gz: 30352b0df1dbeb516ad42bf68403429588b7a6963595ec9dbed2a4aa3919222b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 909a756ba7e3ff1a1d14a3f2f2c743bc2396bb1ebcb38778664ad158e17b4afe9129f4fef5f88ca7671a8fb2e6151c27341101fb9390aa5859d0883e04b7b245
|
7
|
+
data.tar.gz: 1ea9c85abaace8f2e3f5ff36d91e9e3d38410888d99e4a74cb77fca16ebb48f2170e873698b9fcc508a4297ab09b1bf531c47108bc427eef9d60074fe157b795
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (5.2.0)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 0.7, < 2)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
addressable (2.4.0)
|
10
|
+
builder (3.2.3)
|
11
|
+
childprocess (0.9.0)
|
12
|
+
ffi (~> 1.0, >= 1.0.11)
|
13
|
+
concurrent-ruby (1.0.5)
|
14
|
+
descendants_tracker (0.0.4)
|
15
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
faraday (0.9.2)
|
18
|
+
multipart-post (>= 1.2, < 3)
|
19
|
+
ffi (1.9.23)
|
20
|
+
git (1.3.0)
|
21
|
+
github_api (0.16.0)
|
22
|
+
addressable (~> 2.4.0)
|
23
|
+
descendants_tracker (~> 0.0.4)
|
24
|
+
faraday (~> 0.8, < 0.10)
|
25
|
+
hashie (>= 3.4)
|
26
|
+
mime-types (>= 1.16, < 3.0)
|
27
|
+
oauth2 (~> 1.0)
|
28
|
+
hashie (3.5.7)
|
29
|
+
highline (1.7.10)
|
30
|
+
i18n (1.0.1)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
jeweler (2.3.9)
|
33
|
+
builder
|
34
|
+
bundler
|
35
|
+
git (>= 1.2.5)
|
36
|
+
github_api (~> 0.16.0)
|
37
|
+
highline (>= 1.6.15)
|
38
|
+
nokogiri (>= 1.5.10)
|
39
|
+
psych
|
40
|
+
rake
|
41
|
+
rdoc
|
42
|
+
semver2
|
43
|
+
jwt (1.5.6)
|
44
|
+
mime-types (2.99.3)
|
45
|
+
mini_portile2 (2.3.0)
|
46
|
+
minitest (5.11.3)
|
47
|
+
multi_json (1.13.1)
|
48
|
+
multi_xml (0.6.0)
|
49
|
+
multipart-post (2.0.0)
|
50
|
+
nokogiri (1.8.2)
|
51
|
+
mini_portile2 (~> 2.3.0)
|
52
|
+
oauth2 (1.4.0)
|
53
|
+
faraday (>= 0.8, < 0.13)
|
54
|
+
jwt (~> 1.0)
|
55
|
+
multi_json (~> 1.3)
|
56
|
+
multi_xml (~> 0.5)
|
57
|
+
rack (>= 1.2, < 3)
|
58
|
+
psych (3.0.2)
|
59
|
+
rack (2.0.5)
|
60
|
+
rake (12.3.1)
|
61
|
+
rdoc (6.0.3)
|
62
|
+
rspec (3.7.0)
|
63
|
+
rspec-core (~> 3.7.0)
|
64
|
+
rspec-expectations (~> 3.7.0)
|
65
|
+
rspec-mocks (~> 3.7.0)
|
66
|
+
rspec-core (3.7.1)
|
67
|
+
rspec-support (~> 3.7.0)
|
68
|
+
rspec-expectations (3.7.0)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.7.0)
|
71
|
+
rspec-mocks (3.7.0)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.7.0)
|
74
|
+
rspec-support (3.7.1)
|
75
|
+
rubyzip (1.2.1)
|
76
|
+
selenium-webdriver (3.11.0)
|
77
|
+
childprocess (~> 0.5)
|
78
|
+
rubyzip (~> 1.2)
|
79
|
+
semver2 (3.4.2)
|
80
|
+
thread_safe (0.3.6)
|
81
|
+
tzinfo (1.2.5)
|
82
|
+
thread_safe (~> 0.1)
|
83
|
+
watir (6.10.3)
|
84
|
+
selenium-webdriver (~> 3.4, >= 3.4.1)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
activesupport (~> 5.2)
|
91
|
+
bundler (~> 1.0)
|
92
|
+
jeweler (~> 2.3)
|
93
|
+
nokogiri (~> 1.8)
|
94
|
+
rdoc (~> 6.0)
|
95
|
+
rspec (~> 3.7)
|
96
|
+
watir (~> 6.10)
|
97
|
+
|
98
|
+
BUNDLED WITH
|
99
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Tim Koopmans
|
2
|
+
Copyright (c) 2017 Robert MacCracken
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= watir-webdriver-performance
|
2
|
+
Predecessor to https://github.com/90kts/watir-webdriver-performance for Watir as opposed to watir-webdriver
|
3
|
+
|
4
|
+
This gem collects and summarises metrics speficied in the W3C Navigation
|
5
|
+
web performance specifications at
|
6
|
+
https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html when using
|
7
|
+
watir-webdriver and a compatible browser.
|
8
|
+
|
9
|
+
== Example output of browser.performance
|
10
|
+
All summary times are in milliseconds, and are an abstraction of the w3c
|
11
|
+
web performance specification.
|
12
|
+
|
13
|
+
{
|
14
|
+
:summary => {
|
15
|
+
:redirect=>0,
|
16
|
+
:app_cache=>0,
|
17
|
+
:dns=>0,
|
18
|
+
:tcp_connection=>982,
|
19
|
+
:tcp_connection_secure=>721,
|
20
|
+
:request=>1222,
|
21
|
+
:response=>4,
|
22
|
+
:dom_processing=>4293,
|
23
|
+
:response_time=>7298,
|
24
|
+
:time_to_first_byte=>2205,
|
25
|
+
:time_to_last_byte=>2209
|
26
|
+
},
|
27
|
+
:navigation => {
|
28
|
+
:type => 0,
|
29
|
+
:type_back_forward => 2,
|
30
|
+
:redirect_count => 0,
|
31
|
+
:type_reserved => 255,
|
32
|
+
:type_navigate => 0,
|
33
|
+
:type_reload => 1
|
34
|
+
},
|
35
|
+
:memory => {
|
36
|
+
:total_js_heap_size => 0,
|
37
|
+
:js_heap_size_limit => 0,
|
38
|
+
:used_js_heap_size => 0
|
39
|
+
},
|
40
|
+
:timing => {
|
41
|
+
:domain_lookup_start => 1303180421599,
|
42
|
+
:load_event_end => 0,
|
43
|
+
:connect_end => 1303180421642,
|
44
|
+
:response_end => 1303180421853,
|
45
|
+
:dom_loading => 1303180421840,
|
46
|
+
:navigation_start => 0,
|
47
|
+
:redirect_end => 0,
|
48
|
+
:unload_event_start => 0,
|
49
|
+
:secure_connection_start => 0,
|
50
|
+
:connect_start => 1303180421600,
|
51
|
+
:dom_content_loaded_event_end => 1303180421934,
|
52
|
+
:domain_lookup_end => 1303180421600,
|
53
|
+
:dom_interactive => 1303180421934,
|
54
|
+
:load_event_start => 0,
|
55
|
+
:request_start => 1303180421642,
|
56
|
+
:response_start => 1303180421838,
|
57
|
+
:dom_complete => 0,
|
58
|
+
:fetch_start => 1303180421598,
|
59
|
+
:dom_content_loaded_event_start => 1303180421934,
|
60
|
+
:redirect_start => 0,
|
61
|
+
:unload_event_end => 0
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
== Contributing to watir-webdriver-performance
|
66
|
+
|
67
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
68
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
69
|
+
* Fork the project
|
70
|
+
* Start a feature/bugfix branch
|
71
|
+
* Commit and push until you are happy with your contribution
|
72
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
73
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
74
|
+
|
75
|
+
== Copyright
|
76
|
+
|
77
|
+
Copyright (c) 2011 Tim Koopmans, 2017 Robert MacCracken.
|
78
|
+
|
79
|
+
See LICENSE.txt for further details.
|
80
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "watir-performance"
|
15
|
+
gem.homepage = "http://github.com/MacCracken/watir-performance"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = %Q{A simple helper gem for watir performance metrics}
|
18
|
+
gem.description = %Q{This gem collects and summarises metrics speficied in the W3C Navigation web performance specifications at http://w3c-test.org/webperf/specs/NavigationTiming/ when using watir-webdriver and a compatible browser}
|
19
|
+
gem.email = ['robert.maccracken@gmail.com', "tim.koops@gmail.com"]
|
20
|
+
gem.authors = ['Robert MacCracken', "Tim Koopmans"]
|
21
|
+
end
|
22
|
+
Jeweler::RubygemsDotOrgTasks.new
|
23
|
+
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task default: :spec
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
RDoc::Task.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "watir-performance #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'zomg'
|
4
|
+
require 'activesupport'
|
5
|
+
|
6
|
+
doc = Nokogiri::HTML(open('http://w3c-test.org/webperf/specs/NavigationTiming/'))
|
7
|
+
idl = []
|
8
|
+
doc.css('pre.idl').each do |content|
|
9
|
+
idl << content.text
|
10
|
+
end
|
11
|
+
nodes = []
|
12
|
+
idl.each do |spec|
|
13
|
+
nodes << ZOMG::IDL.parse(spec) unless ZOMG::IDL.parse(spec).nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
results = {}
|
17
|
+
results[:class] = "Performance"
|
18
|
+
results[:interfaces] = {}
|
19
|
+
nodes.each do |node|
|
20
|
+
interface_name = node.children.first.header.name.gsub("Performance","")
|
21
|
+
results[:interfaces][interface_name] = {}
|
22
|
+
results[:interfaces][interface_name][:attrs] = []
|
23
|
+
results[:interfaces][interface_name][:constants] = {}
|
24
|
+
node.children.first.children.each do |child|
|
25
|
+
case child.class.to_s
|
26
|
+
when "ZOMG::IDL::Nodes::Attribute"
|
27
|
+
results[:interfaces][interface_name][:attrs] <<
|
28
|
+
child.children.first.name.underscore
|
29
|
+
when "ZOMG::IDL::Nodes::Constant"
|
30
|
+
results[:interfaces][interface_name][:constants][child.name] = child.children.children
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
open(File.expand_path(File.dirname(__FILE__)) + "/#{results[:class].underscore}.rb", "w") do |f|
|
36
|
+
f.puts "# auto-generated by idl_extractor.rb"
|
37
|
+
f.puts "class #{results[:class]}"
|
38
|
+
results[:interfaces].each_key do |interface_name|
|
39
|
+
f.puts " " * 2 + "class #{interface_name}"
|
40
|
+
results[:interfaces][interface_name][:constants].each do |k,v|
|
41
|
+
f.puts " " * 4 + "#{k} = #{v.to_i}"
|
42
|
+
end
|
43
|
+
f.puts " " * 4 + "attr_reader " +
|
44
|
+
results[:interfaces][interface_name][:attrs].collect! {|x| ":"+x}.join(", ")
|
45
|
+
f.puts <<-'eos'
|
46
|
+
def initialize args
|
47
|
+
args.each do |k,v|
|
48
|
+
instance_variable_set("@#{k}", v) if respond_to?(k.to_sym) unless v.nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
eos
|
52
|
+
f.puts " " * 2 + "end"
|
53
|
+
end
|
54
|
+
f.puts "end"
|
55
|
+
end
|
data/lib/performance.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# auto-generated by idl_extractor.rb
|
2
|
+
class Performance
|
3
|
+
class Navigation
|
4
|
+
TYPE_RESERVED = 255
|
5
|
+
TYPE_NAVIGATE = 0
|
6
|
+
TYPE_RELOAD = 1
|
7
|
+
TYPE_BACK_FORWARD = 2
|
8
|
+
attr_reader :type, :redirect_count
|
9
|
+
def initialize args
|
10
|
+
args.each do |k,v|
|
11
|
+
instance_variable_set("@#{k}", v) if respond_to?(k.to_sym) unless v.nil?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class Timing
|
16
|
+
attr_reader :navigation_start, :unload_event_start, :unload_event_end, :redirect_start, :redirect_end, :fetch_start, :domain_lookup_start, :domain_lookup_end, :connect_start, :connect_end, :secure_connection_start, :request_start, :response_start, :response_end, :dom_loading, :dom_interactive, :dom_content_loaded_event_start, :dom_content_loaded_event_end, :dom_complete, :load_event_start, :load_event_end
|
17
|
+
def initialize args
|
18
|
+
args.each do |k,v|
|
19
|
+
instance_variable_set("@#{k}", v) if respond_to?(k.to_sym) unless v.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module Watir
|
3
|
+
|
4
|
+
# Adds helper for window.performance to Watir::Browser.
|
5
|
+
# @see http://dev.w3.org/2006/webapi/WebTiming/
|
6
|
+
|
7
|
+
class PerformanceHelper
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def munge
|
14
|
+
hash = {}
|
15
|
+
@data.each_key do |key|
|
16
|
+
if key == '__fxdriver_unwrapped'
|
17
|
+
next
|
18
|
+
end
|
19
|
+
hash[key.to_sym] = {}
|
20
|
+
next unless @data[key].respond_to? :each
|
21
|
+
@data[key].each do |k,v|
|
22
|
+
if k == '__fxdriver_unwrapped'
|
23
|
+
next
|
24
|
+
end
|
25
|
+
hash[key.to_sym][underscored(k).to_sym] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
hash[:summary] = {}
|
30
|
+
hash[:summary][:redirect] = hash[:timing][:redirect_end] -
|
31
|
+
hash[:timing][:redirect_start] if hash[:timing][:redirect_end] > 0
|
32
|
+
hash[:summary][:app_cache] = hash[:timing][:domain_lookup_start] -
|
33
|
+
hash[:timing][:fetch_start] if hash[:timing][:fetch_start] > 0
|
34
|
+
hash[:summary][:dns] = hash[:timing][:domain_lookup_end] -
|
35
|
+
hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
|
36
|
+
hash[:summary][:tcp_connection] = hash[:timing][:connect_end] -
|
37
|
+
hash[:timing][:connect_start] if hash[:timing][:connect_start] > 0
|
38
|
+
hash[:summary][:tcp_connection_secure] = hash[:timing][:connect_end] -
|
39
|
+
hash[:timing][:secure_connection_start] if
|
40
|
+
((hash[:timing][:secure_connection_start] != nil) and
|
41
|
+
(hash[:timing][:secure_connection_start] > 0))
|
42
|
+
hash[:summary][:request] = hash[:timing][:response_start] -
|
43
|
+
hash[:timing][:request_start] if hash[:timing][:request_start] > 0
|
44
|
+
hash[:summary][:response] = hash[:timing][:response_end] -
|
45
|
+
hash[:timing][:response_start] if hash[:timing][:response_start] > 0
|
46
|
+
hash[:summary][:dom_processing] = hash[:timing][:dom_content_loaded_event_start] -
|
47
|
+
hash[:timing][:dom_loading] if hash[:timing][:dom_loading] > 0
|
48
|
+
hash[:summary][:time_to_first_byte] = hash[:timing][:response_start] -
|
49
|
+
hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
|
50
|
+
hash[:summary][:time_to_last_byte] = hash[:timing][:response_end] -
|
51
|
+
hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
|
52
|
+
hash[:summary][:response_time] = latest_timestamp(hash) - earliest_timestamp(hash)
|
53
|
+
OpenStruct.new(hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def underscored(camel_cased_word)
|
59
|
+
word = camel_cased_word.to_s.dup
|
60
|
+
word.gsub!(/::/, '/')
|
61
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
62
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
63
|
+
word.tr!("-", "_")
|
64
|
+
word.downcase!
|
65
|
+
word
|
66
|
+
end
|
67
|
+
|
68
|
+
def earliest_timestamp(hash)
|
69
|
+
return hash[:timing][:navigation_start] if hash[:timing][:navigation_start] > 0
|
70
|
+
return hash[:timing][:redirect_start] if hash[:timing][:redirect_start] > 0
|
71
|
+
return hash[:timing][:redirect_end] if hash[:timing][:redirect_end] > 0
|
72
|
+
return hash[:timing][:fetch_start] if hash[:timing][:fetch_start] > 0
|
73
|
+
end
|
74
|
+
|
75
|
+
def latest_timestamp(hash)
|
76
|
+
return hash[:timing][:load_event_end] if hash[:timing][:load_event_end] > 0
|
77
|
+
return hash[:timing][:load_event_start] if hash[:timing][:load_event_start] > 0
|
78
|
+
return hash[:timing][:dom_complete] if hash[:timing][:dom_complete] > 0
|
79
|
+
return hash[:timing][:dom_content_loaded_event_end] if hash[:timing][:dom_content_loaded_event_end] > 0
|
80
|
+
return hash[:timing][:dom_content_loaded_event_start] if hash[:timing][:dom_content_loaded_event_start] > 0
|
81
|
+
return hash[:timing][:dom_interactive] if hash[:timing][:dom_interactive] > 0
|
82
|
+
return hash[:timing][:response_end] if hash[:timing][:response_end] > 0
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
class Browser
|
88
|
+
def performance
|
89
|
+
data = case driver.browser
|
90
|
+
when :internet_explorer
|
91
|
+
::Object::JSON.parse(driver.execute_script("return JSON.stringify(window.performance.toJSON());"))
|
92
|
+
else
|
93
|
+
driver.execute_script("return window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance;")
|
94
|
+
end
|
95
|
+
raise 'Could not collect performance metrics from your current browser. Please ensure the browser you are using supports collecting performance metrics.' if data.nil?
|
96
|
+
PerformanceHelper.new(data).munge
|
97
|
+
end
|
98
|
+
|
99
|
+
def performance_supported?
|
100
|
+
driver.execute_script("return window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance;")
|
101
|
+
end
|
102
|
+
alias performance_data performance_supported?
|
103
|
+
|
104
|
+
def with_performance
|
105
|
+
yield PerformanceHelper.new(performance_data).munge if performance_supported?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'watir-performance'
|
5
|
+
require 'watir'
|
6
|
+
|
7
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "WatirWebdriverPerformance-NonSupportedBrowser" do
|
4
|
+
|
5
|
+
let!(:b) { @b }
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@b ||= Watir::Browser.new :safari
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
@b.close
|
13
|
+
end
|
14
|
+
|
15
|
+
pending "should raise an error when a non supported browser is encountered" do
|
16
|
+
b.goto "google.com"
|
17
|
+
expect(lambda { b.performance }).to raise_error RuntimeError, 'Could not collect performance metrics from your current browser. Please ensure the browser you are using supports collecting performance metrics.'
|
18
|
+
end
|
19
|
+
|
20
|
+
pending "should return false for supported" do
|
21
|
+
b.goto "google.com"
|
22
|
+
expect(b).not_to be_performance_supported
|
23
|
+
end
|
24
|
+
|
25
|
+
pending "should not support performance as block" do
|
26
|
+
b.goto "google.com"
|
27
|
+
b.with_performance {|performance| expect(performance).not_to be_nil }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "WatirWebdriverPerformance" do
|
4
|
+
|
5
|
+
let!(:b) { @b }
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@b ||= Watir::Browser.new
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
@b.close
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should open get performance metrics from the browser" do
|
16
|
+
b.goto "google.com"
|
17
|
+
expect(b.performance).to be_an_instance_of(OpenStruct)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get summary data from the performance metrics" do
|
21
|
+
# Summary metrics based on Processing Model of NavigationTiming
|
22
|
+
# http://w3c-test.org/webperf/specs/NavigationTiming/#processing-model
|
23
|
+
expect(b.performance.summary).to include(:app_cache)
|
24
|
+
expect(b.performance.summary).to include(:dns)
|
25
|
+
expect(b.performance.summary).to include(:tcp_connection)
|
26
|
+
expect(b.performance.summary).to include(:request)
|
27
|
+
expect(b.performance.summary).to include(:response)
|
28
|
+
expect(b.performance.summary).to include(:dom_processing)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get the summary metrics such as Response Time, TTLB and TTFB" do
|
32
|
+
expect(b.performance.summary).to include(:time_to_first_byte) # aka "server time"
|
33
|
+
expect(b.performance.summary).to include(:time_to_last_byte) # aka "network + server time"
|
34
|
+
expect(b.performance.summary).to include(:response_time)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return true for chrome supported" do
|
38
|
+
b.goto "google.com"
|
39
|
+
expect(b).to be_performance_supported
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should support performance as block" do
|
43
|
+
b.goto "google.com"
|
44
|
+
b.with_performance {|performance| expect(performance).not_to be_nil }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: watir-performance 0.5.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "watir-performance".freeze
|
9
|
+
s.version = "0.5.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Robert MacCracken".freeze, "Tim Koopmans".freeze]
|
14
|
+
s.date = "2018-05-04"
|
15
|
+
s.description = "This gem collects and summarises metrics speficied in the W3C Navigation web performance specifications at http://w3c-test.org/webperf/specs/NavigationTiming/ when using watir-webdriver and a compatible browser".freeze
|
16
|
+
s.email = ["robert.maccracken@gmail.com".freeze, "tim.koops@gmail.com".freeze]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"examples/basic.rb",
|
31
|
+
"lib/idl_extractor.rb",
|
32
|
+
"lib/performance.rb",
|
33
|
+
"lib/watir-performance.rb",
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"spec/watir-performance-non-supported-browser_spec.rb",
|
36
|
+
"spec/watir-performance_spec.rb",
|
37
|
+
"watir-performance.gemspec"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/MacCracken/watir-performance".freeze
|
40
|
+
s.licenses = ["MIT".freeze]
|
41
|
+
s.rubygems_version = "2.7.6".freeze
|
42
|
+
s.summary = "A simple helper gem for watir performance metrics".freeze
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 4
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<watir>.freeze, ["~> 6.10"])
|
49
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.0"])
|
50
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
52
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.7"])
|
53
|
+
s.add_development_dependency(%q<nokogiri>.freeze, ["~> 1.8"])
|
54
|
+
s.add_development_dependency(%q<activesupport>.freeze, ["~> 5.2"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<watir>.freeze, ["~> 6.10"])
|
57
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 6.0"])
|
58
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
59
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
60
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.7"])
|
61
|
+
s.add_dependency(%q<nokogiri>.freeze, ["~> 1.8"])
|
62
|
+
s.add_dependency(%q<activesupport>.freeze, ["~> 5.2"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<watir>.freeze, ["~> 6.10"])
|
66
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 6.0"])
|
67
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
68
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
69
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.7"])
|
70
|
+
s.add_dependency(%q<nokogiri>.freeze, ["~> 1.8"])
|
71
|
+
s.add_dependency(%q<activesupport>.freeze, ["~> 5.2"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-performance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert MacCracken
|
8
|
+
- Tim Koopmans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: watir
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '6.10'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '6.10'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rdoc
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '6.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: jeweler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.7'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.7'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: nokogiri
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.8'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.8'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: activesupport
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5.2'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '5.2'
|
112
|
+
description: This gem collects and summarises metrics speficied in the W3C Navigation
|
113
|
+
web performance specifications at http://w3c-test.org/webperf/specs/NavigationTiming/
|
114
|
+
when using watir-webdriver and a compatible browser
|
115
|
+
email:
|
116
|
+
- robert.maccracken@gmail.com
|
117
|
+
- tim.koops@gmail.com
|
118
|
+
executables: []
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files:
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.rdoc
|
123
|
+
files:
|
124
|
+
- ".document"
|
125
|
+
- ".rspec"
|
126
|
+
- Gemfile
|
127
|
+
- Gemfile.lock
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.rdoc
|
130
|
+
- Rakefile
|
131
|
+
- VERSION
|
132
|
+
- examples/basic.rb
|
133
|
+
- lib/idl_extractor.rb
|
134
|
+
- lib/performance.rb
|
135
|
+
- lib/watir-performance.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
- spec/watir-performance-non-supported-browser_spec.rb
|
138
|
+
- spec/watir-performance_spec.rb
|
139
|
+
- watir-performance.gemspec
|
140
|
+
homepage: http://github.com/MacCracken/watir-performance
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.7.6
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: A simple helper gem for watir performance metrics
|
164
|
+
test_files: []
|