watir-performance 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fad33273008c01f7ee6b8bc43838ddce2816fbb01ff2b2645095728f0fb2983a
4
- data.tar.gz: 30352b0df1dbeb516ad42bf68403429588b7a6963595ec9dbed2a4aa3919222b
3
+ metadata.gz: 6017f0df9996f014d68143f9406bb7f7f7ca79620eaf17d282690c0a7af149cd
4
+ data.tar.gz: e5fa32036832cedc85736344f05c8a51c3a801a963fd2d364595ea612bf4452e
5
5
  SHA512:
6
- metadata.gz: 909a756ba7e3ff1a1d14a3f2f2c743bc2396bb1ebcb38778664ad158e17b4afe9129f4fef5f88ca7671a8fb2e6151c27341101fb9390aa5859d0883e04b7b245
7
- data.tar.gz: 1ea9c85abaace8f2e3f5ff36d91e9e3d38410888d99e4a74cb77fca16ebb48f2170e873698b9fcc508a4297ab09b1bf531c47108bc427eef9d60074fe157b795
6
+ metadata.gz: e6cf09ea0b1c504e0681e029b3e9336f2b39a9ad1d71c1bfd963ac7ce824a5d872e942b5d7dc5c4228c2b856533a1c036ceca6374730c07649af9f13c54f51d2
7
+ data.tar.gz: e0aa61d4822e4e9582eda6331fc97c49e68c5cdd1c8147345b8a444be0df61a7fbf6e21969f4882e0647c7420cd4154f7b47ca83fd4aa31e0833bfde1e751d31
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --format documentation
3
+ --require ./spec/spec_helper.rb
data/.travis.yml ADDED
@@ -0,0 +1,54 @@
1
+ sudo: required
2
+ language: ruby
3
+
4
+ matrix:
5
+ include:
6
+
7
+ - os: linux
8
+ rvm: 2.5.1
9
+ addons:
10
+ chrome: stable
11
+ firefox: "59.0.2"
12
+ before_install:
13
+ - bash ./spec/support/setup-chromedriver.sh
14
+ - bash ./spec/support/setup-geckodriver.sh
15
+ - gem install bundler -v 1.16.1
16
+ script: xvfb-run bundle exec rake
17
+
18
+ - os: linux
19
+ rvm: 2.5.0
20
+ addons:
21
+ chrome: stable
22
+ firefox: "59.0"
23
+ before_install:
24
+ - bash ./spec/support/setup-chromedriver.sh
25
+ - bash ./spec/support/setup-geckodriver.sh
26
+ - gem install bundler -v 1.16.1
27
+ script: xvfb-run bundle exec rake
28
+
29
+ - os: osx
30
+ rvm: 2.5.1
31
+ addons:
32
+ chrome: beta
33
+ firefox: "59.0.2"
34
+ before_install:
35
+ - sudo bash ./spec/support/setup-chromedriver.sh
36
+ - sudo bash ./spec/support/setup-geckodriver-alt.sh
37
+ - sudo safaridriver --enable
38
+ - gem install bundler -v 1.16.1
39
+ script: xvfb-run bundle exec rake
40
+
41
+ - os: osx
42
+ rvm: 2.5.0
43
+ addons:
44
+ chrome: beta
45
+ firefox: "59.0"
46
+ before_install:
47
+ - sudo bash ./spec/support/setup-chromedriver.sh
48
+ - sudo bash ./spec/support/setup-geckodriver-alt.sh
49
+ - sudo safaridriver --enable
50
+ - gem install bundler -v 1.16.1
51
+ script: xvfb-run bundle exec rake
52
+
53
+ notifications:
54
+ email: false
data/Gemfile.lock CHANGED
@@ -58,7 +58,7 @@ GEM
58
58
  psych (3.0.2)
59
59
  rack (2.0.5)
60
60
  rake (12.3.1)
61
- rdoc (6.0.3)
61
+ rdoc (6.0.4)
62
62
  rspec (3.7.0)
63
63
  rspec-core (~> 3.7.0)
64
64
  rspec-expectations (~> 3.7.0)
data/README.rdoc CHANGED
@@ -1,10 +1,18 @@
1
- = watir-webdriver-performance
2
- Predecessor to https://github.com/90kts/watir-webdriver-performance for Watir as opposed to watir-webdriver
1
+ = watir-performance
2
+
3
+ {<img src="https://badge.fury.io/rb/watir-performance.svg" alt="Gem Version" />}[https://badge.fury.io/rb/watir-performance]
4
+ {<img src="https://beta.gemnasium.com/badges/github.com/MacCracken/watir-performance.svg" alt="Dependency Status" />}[https://beta.gemnasium.com/projects/github.com/MacCracken/watir-performance]
5
+ {<img src="https://api.codeclimate.com/v1/badges/ce9c9de5e6146dedab27/maintainability" />}[https://codeclimate.com/github/MacCracken/watir-performance/maintainability]
6
+ {<img src="https://travis-ci.org/MacCracken/watir-performance.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/MacCracken/watir-performance]
7
+
8
+ Predecessor to https://github.com/90kts/watir-webdriver-performance for Watir as opposed to watir-webdriver.
9
+
10
+ The Watir-Performance aims to provide a set of navigation timing metrics for Watir[https://github.com/watir/watir] actions using a {W3C page performance standard}[http://w3c-test.org/webperf/specs/NavigationTiming/]. This is a perfect solution to capture response time metrics, and it’s very straightforward to do. Works for Chrome, Firefox, Edge and IE9 and up. Currently no Safari support.
3
11
 
4
12
  This gem collects and summarises metrics speficied in the W3C Navigation
5
13
  web performance specifications at
6
14
  https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html when using
7
- watir-webdriver and a compatible browser.
15
+ watir and a compatible browser.
8
16
 
9
17
  == Example output of browser.performance
10
18
  All summary times are in milliseconds, and are an abstraction of the w3c
@@ -62,7 +70,7 @@ web performance specification.
62
70
  }
63
71
  }
64
72
 
65
- == Contributing to watir-webdriver-performance
73
+ == Contributing to watir-performance
66
74
 
67
75
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
68
76
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -1,31 +1,32 @@
1
1
  require 'ostruct'
2
- module Watir
3
2
 
3
+ module Watir
4
4
  # Adds helper for window.performance to Watir::Browser.
5
5
  # @see http://dev.w3.org/2006/webapi/WebTiming/
6
-
7
6
  class PerformanceHelper
8
-
9
7
  def initialize(data)
10
8
  @data = data
9
+ @hash = {}
11
10
  end
12
11
 
13
12
  def munge
14
- hash = {}
13
+ OpenStruct.new(summarized_hash(data_to_hash))
14
+ end
15
+
16
+ def data_to_hash
15
17
  @data.each_key do |key|
16
- if key == '__fxdriver_unwrapped'
17
- next
18
- end
19
- hash[key.to_sym] = {}
18
+ next if key == '__fxdriver_unwrapped'
19
+ @hash[key.to_sym] = {}
20
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
21
+ @data[key].each do |k, v|
22
+ next if k == '__fxdriver_unwrapped'
23
+ @hash[key.to_sym][underscored(k).to_sym] = v
26
24
  end
27
25
  end
26
+ @hash
27
+ end
28
28
 
29
+ def summarized_hash(hash)
29
30
  hash[:summary] = {}
30
31
  hash[:summary][:redirect] = hash[:timing][:redirect_end] -
31
32
  hash[:timing][:redirect_start] if hash[:timing][:redirect_end] > 0
@@ -50,7 +51,7 @@ module Watir
50
51
  hash[:summary][:time_to_last_byte] = hash[:timing][:response_end] -
51
52
  hash[:timing][:domain_lookup_start] if hash[:timing][:domain_lookup_start] > 0
52
53
  hash[:summary][:response_time] = latest_timestamp(hash) - earliest_timestamp(hash)
53
- OpenStruct.new(hash)
54
+ hash # Return
54
55
  end
55
56
 
56
57
  private
@@ -81,28 +82,38 @@ module Watir
81
82
  return hash[:timing][:dom_interactive] if hash[:timing][:dom_interactive] > 0
82
83
  return hash[:timing][:response_end] if hash[:timing][:response_end] > 0
83
84
  end
84
-
85
85
  end
86
86
 
87
+ PERFORMS = 'return window.performance || window.webkitPerformance || '\
88
+ 'window.mozPerformance || window.msPerformance;'.freeze
89
+ ERRORMESSAGE = 'Could not collect performance metrics from your current ' \
90
+ 'browser. Please ensure the browser you are using supports ' \
91
+ 'collecting performance metrics.'.freeze
92
+
93
+ # Extending Watir Browser
94
+ # See Documentation Here
95
+ # https://www.rubydoc.info/gems/watir/
87
96
  class Browser
88
97
  def performance
89
98
  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?
99
+ when :internet_explorer
100
+ script = 'return JSON.stringify(window.performance.toJSON());'
101
+ cmd = driver.execute_script(script)
102
+ ::Object::JSON.parse(cmd)
103
+ else
104
+ driver.execute_script(PERFORMS)
105
+ end
106
+ raise ERRORMESSAGE if data.nil?
96
107
  PerformanceHelper.new(data).munge
97
108
  end
98
109
 
99
110
  def performance_supported?
100
- driver.execute_script("return window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance;")
111
+ driver.execute_script(PERFORMS)
101
112
  end
102
113
  alias performance_data performance_supported?
103
114
 
104
115
  def with_performance
105
- yield PerformanceHelper.new(performance_data).munge if performance_supported?
116
+ yield PerformanceHelper.new(performance_data).munge if performance_supported?
106
117
  end
107
118
  end
108
119
  end
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,7 @@ require 'rspec'
4
4
  require 'watir-performance'
5
5
  require 'watir'
6
6
 
7
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
8
8
 
9
9
  RSpec.configure do |config|
10
-
11
10
  end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ echo "#### Getting Chromedriver ####"
3
+ latest_chromedriver=$(wget -qO- http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
4
+ wget https://chromedriver.storage.googleapis.com/${latest_chromedriver}/chromedriver_linux64.zip
5
+ unzip chromedriver_linux64.zip
6
+ sudo cp chromedriver /usr/local/bin/chromedriver
7
+ sudo chown root /usr/local/bin/chromedriver
8
+ sudo chmod +x /usr/local/bin/chromedriver
9
+ sudo chmod 755 /usr/local/bin/chromedriver
10
+ rm chromedriver*
@@ -0,0 +1,7 @@
1
+ echo "#### Getting Geckodriver ####"
2
+ GK_VERSION=0.20.1
3
+ echo "Using GeckoDriver version: "$GK_VERSION
4
+ wget --no-verbose -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GK_VERSION/geckodriver-v$GK_VERSION-linux64.tar.gz
5
+ tar -C /opt -zxf /tmp/geckodriver.tar.gz && rm /tmp/geckodriver.tar.gz
6
+ sudo chmod 755 /opt/geckodriver
7
+ export PATH=$PATH:/opt/geckodriver
@@ -0,0 +1,9 @@
1
+ echo "#### Getting Geckodriver ####"
2
+ latest_geckodriver=latest
3
+ GK_VERSION=$(if [ ${GECKODRIVER_VERSION:-latest} = "latest" ]; then echo $(wget -qO- "https://api.github.com/repos/mozilla/geckodriver/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([0-9.]+)".*/\1/'); else echo $GECKODRIVER_VERSION; fi)
4
+ echo "Using GeckoDriver version: "$GK_VERSION
5
+ wget --no-verbose -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GK_VERSION/geckodriver-v$GK_VERSION-linux64.tar.gz
6
+ tar -C /opt -zxf /tmp/geckodriver.tar.gz && rm /tmp/geckodriver.tar.gz
7
+ sudo mv /opt/geckodriver /opt/geckodriver-$GK_VERSION
8
+ sudo chmod 755 /opt/geckodriver-$GK_VERSION
9
+ sudo ln -fs /opt/geckodriver-$GK_VERSION /usr/bin/geckodriver
@@ -1,29 +1,29 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ uname=`uname -s`.chomp
2
+ if uname == "Darwin"
3
+ describe 'WatirPerformance-NonSupportedBrowser' do
4
+ let!(:b) { @b }
2
5
 
3
- describe "WatirWebdriverPerformance-NonSupportedBrowser" do
6
+ before(:all) do
7
+ @b ||= Watir::Browser.new :safari
8
+ end
4
9
 
5
- let!(:b) { @b }
10
+ after(:all) do
11
+ @b.quit
12
+ end
6
13
 
7
- before(:all) do
8
- @b ||= Watir::Browser.new :safari
9
- end
10
-
11
- after(:all) do
12
- @b.close
13
- end
14
+ pending 'should raise an error when a non supported browser is encountered' do
15
+ b.goto "google.com"
16
+ expect(-> { 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.'
17
+ end
14
18
 
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
19
+ pending "should return false for supported" do
20
+ b.goto "google.com"
21
+ expect(b).not_to be_performance_supported
22
+ end
24
23
 
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 }
24
+ pending "should not support performance as block" do
25
+ b.goto "google.com"
26
+ b.with_performance {|performance| expect(performance).not_to be_nil }
27
+ end
28
28
  end
29
29
  end
@@ -1,46 +1,51 @@
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
1
+ uname = `uname -s`.chomp
2
+ browsers = %i[chrome firefox]
3
+ if %w[MINGW CYGWIN].include? uname
4
+ browsers << %i[edge internet_explorer]
5
+ end
41
6
 
42
- it "should support performance as block" do
43
- b.goto "google.com"
44
- b.with_performance {|performance| expect(performance).not_to be_nil }
7
+ browsers.each do |browser|
8
+ describe "WatirPerformance-#{browser.upcase}" do
9
+ let!(:b) { @b }
10
+
11
+ before(:all) do
12
+ @b ||= Watir::Browser.new browser
13
+ end
14
+
15
+ after(:all) do
16
+ @b.close
17
+ end
18
+
19
+ it 'should open get performance metrics from the browser' do
20
+ b.goto 'google.com'
21
+ expect(b.performance).to be_an_instance_of(OpenStruct)
22
+ end
23
+
24
+ it 'should get summary data from the performance metrics' do
25
+ # Summary metrics based on Processing Model of NavigationTiming
26
+ # http://w3c-test.org/webperf/specs/NavigationTiming/#processing-model
27
+ expect(b.performance.summary).to include(:app_cache)
28
+ expect(b.performance.summary).to include(:dns)
29
+ expect(b.performance.summary).to include(:tcp_connection)
30
+ expect(b.performance.summary).to include(:request)
31
+ expect(b.performance.summary).to include(:response)
32
+ expect(b.performance.summary).to include(:dom_processing)
33
+ end
34
+
35
+ it 'should get the summary metrics such as Response Time, TTLB and TTFB' do
36
+ expect(b.performance.summary).to include(:time_to_first_byte) # aka "server time"
37
+ expect(b.performance.summary).to include(:time_to_last_byte) # aka "network + server time"
38
+ expect(b.performance.summary).to include(:response_time)
39
+ end
40
+
41
+ it 'should return true for chrome supported' do
42
+ b.goto 'google.com'
43
+ expect(b).to be_performance_supported
44
+ end
45
+
46
+ it 'should support performance as block' do
47
+ b.goto 'google.com'
48
+ b.with_performance {|performance| expect(performance).not_to be_nil }
49
+ end
45
50
  end
46
51
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: watir-performance 0.5.0 ruby lib
5
+ # stub: watir-performance 0.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "watir-performance".freeze
9
- s.version = "0.5.0"
9
+ s.version = "0.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Robert MacCracken".freeze, "Tim Koopmans".freeze]
14
- s.date = "2018-05-04"
14
+ s.date = "2018-05-05"
15
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
16
  s.email = ["robert.maccracken@gmail.com".freeze, "tim.koops@gmail.com".freeze]
17
17
  s.extra_rdoc_files = [
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = [
22
22
  ".document",
23
23
  ".rspec",
24
+ ".travis.yml",
24
25
  "Gemfile",
25
26
  "Gemfile.lock",
26
27
  "LICENSE.txt",
@@ -32,6 +33,9 @@ Gem::Specification.new do |s|
32
33
  "lib/performance.rb",
33
34
  "lib/watir-performance.rb",
34
35
  "spec/spec_helper.rb",
36
+ "spec/support/setup-chromedriver.sh",
37
+ "spec/support/setup-geckodriver-alt.sh",
38
+ "spec/support/setup-geckodriver.sh",
35
39
  "spec/watir-performance-non-supported-browser_spec.rb",
36
40
  "spec/watir-performance_spec.rb",
37
41
  "watir-performance.gemspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert MacCracken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-04 00:00:00.000000000 Z
12
+ date: 2018-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir
@@ -123,6 +123,7 @@ extra_rdoc_files:
123
123
  files:
124
124
  - ".document"
125
125
  - ".rspec"
126
+ - ".travis.yml"
126
127
  - Gemfile
127
128
  - Gemfile.lock
128
129
  - LICENSE.txt
@@ -134,6 +135,9 @@ files:
134
135
  - lib/performance.rb
135
136
  - lib/watir-performance.rb
136
137
  - spec/spec_helper.rb
138
+ - spec/support/setup-chromedriver.sh
139
+ - spec/support/setup-geckodriver-alt.sh
140
+ - spec/support/setup-geckodriver.sh
137
141
  - spec/watir-performance-non-supported-browser_spec.rb
138
142
  - spec/watir-performance_spec.rb
139
143
  - watir-performance.gemspec