webdrivers 3.8.1 → 3.9.0

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
  SHA1:
3
- metadata.gz: 6896e06805c951acefc4a41cf1f647eb677bfb1a
4
- data.tar.gz: 9dbc3a6e88ed3ac7e2d3c4ca885976ed236f589b
3
+ metadata.gz: bee44be9b5854e4de983328db68fd8735a0a7587
4
+ data.tar.gz: 8dede2a2bd5446c2cd58df1485fd5db8dffeedea
5
5
  SHA512:
6
- metadata.gz: 95c2d9ff6ded3b07aeb40018bf4d27046d5c0a691153fee376a59fffefb46172e616bf2d712f8fe4aab08c32e3ea72b31c5b874dd11d8c54a300fd025a2bbfea
7
- data.tar.gz: e7476ae99421fb154d8884f6815e40274d05a1a824015a4a229910167ae430f04eeed79e3f5c7c07051ff4e66e045de0e982fd519746b3d841735038f153bf43
6
+ metadata.gz: bbbc24fb35b58c3b161f7b09d5a662f73f004f88e28bc6222ea80fa8ffb6df3cda648376462491e9e39835420ea4e057d958028701aa2529dd2bae2cd2c587ca
7
+ data.tar.gz: 8f1bd1cbcbddb25e27ffc73e35c6da979fe1fa7805254782a00d70c35da3daa0a41ef42e266f8322d129634ae64aee8987e54b0dfdcee995c30514121f876e4f
data/.rubocop.yml CHANGED
@@ -1,30 +1,39 @@
1
- require: rubocop-rspec
1
+ AllCops:
2
+ TargetRubyVersion: 2.4.6
3
+
4
+ require:
5
+ - rubocop-rspec
6
+ - rubocop-performance
7
+
8
+ Layout/SpaceInsideHashLiteralBraces:
9
+ EnforcedStyle: no_space
2
10
 
3
11
  Layout/EndOfLine:
4
12
  EnforcedStyle: lf
5
13
 
6
14
  Metrics/LineLength:
7
15
  Max: 120
16
+ IgnoredPatterns:
17
+ - '\s+# rubocop:disable'
8
18
 
9
19
  Metrics/MethodLength:
10
- Enabled: false
20
+ Max: 20
11
21
 
12
22
  Metrics/BlockLength:
13
23
  Exclude:
14
24
  - 'spec/**/*'
15
25
 
16
26
  Metrics/ClassLength:
17
- Max: 110
18
- Exclude:
19
- - 'lib/webdrivers/common.rb'
20
-
21
- Metrics/AbcSize:
22
- Exclude:
23
- - 'lib/webdrivers/common.rb'
27
+ Max: 116
24
28
 
25
29
  Metrics/CyclomaticComplexity:
26
30
  Max: 8
27
31
 
32
+ Metrics/AbcSize:
33
+ Max: 16
34
+ Exclude:
35
+ - 'lib/webdrivers/chromedriver.rb'
36
+
28
37
  Style/Documentation:
29
38
  Enabled: false
30
39
 
data/.travis.yml CHANGED
@@ -20,5 +20,5 @@ matrix:
20
20
  env: RAKE_TASK=spec
21
21
  - rvm: 2.4.6
22
22
  env: RAKE_TASK=rubocop
23
- - rvm: jruby-9.2.0.0
23
+ - rvm: jruby-9.2.7.0
24
24
  env: RAKE_TASK=spec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 3.9.0 (2019-05-07)
2
+ * Make public methods more obvious and deprecate unnecessary methods (issue #36)
3
+ * Allow geckodriver binaries to be downloaded directly (issue #30)
4
+ * Allow drivers to be cached to reduce unnecessary network calls (issue #29)
5
+ * MSWebdriver class is removed as no longer supported
6
+ * Refactored to minimize network calls (issue #80)
7
+ * Fix warnings about instance variables not initialized
8
+ * Add support for managing specific drivers (issue #95)
9
+
1
10
  ### 3.8.1 (2019-05-04)
2
11
  * Downloads chromedriver with direct URL instead of parsing the downloads page
3
12
  * Raises exception if version of Chrome does not have a known version of the driver (issue #79)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017: Titus Fortner
3
+ Copyright (c) 2017-2019: Titus Fortner
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/webdrivers.svg)](https://badge.fury.io/rb/webdrivers)
4
4
  [![Build status](https://travis-ci.org/titusfortner/webdrivers.svg?branch=master)](https://travis-ci.org/titusfortner/webdrivers)
5
- [![AppVeyor status](https://ci.appveyor.com/api/projects/status/github/titusfortner/webdrivers?svg=true)](https://ci.appveyor.com/project/titusfortner/webdrivers)
5
+ [![AppVeyor status](https://ci.appveyor.com/api/projects/status/ejh90xqbvkphq4cy/branch/master?svg=true)](https://ci.appveyor.com/project/titusfortner/webdrivers/branch/master)
6
6
 
7
7
  Run Selenium tests more easily with automatic installation and updates for all supported webdrivers.
8
8
 
@@ -13,7 +13,6 @@ Run Selenium tests more easily with automatic installation and updates for all s
13
13
  * [chromedriver](http://chromedriver.chromium.org/)
14
14
  * [geckodriver](https://github.com/mozilla/geckodriver)
15
15
  * [IEDriverServer](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver)
16
- * [MicrosoftWebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)
17
16
 
18
17
  ## Usage
19
18
 
@@ -30,6 +29,12 @@ require 'webdrivers'
30
29
  The drivers will now be automatically downloaded or updated when you launch a browser
31
30
  through Selenium.
32
31
 
32
+ If you want webdrivers to only manage specific drivers you can specify as follows:
33
+ ```ruby
34
+ require 'webdrivers/chromedriver'
35
+ require 'webdrivers/iedriver'
36
+ ```
37
+
33
38
  ### Download Location
34
39
 
35
40
  The default download location is `~/.webdrivers` directory, and this is configurable:
@@ -40,24 +45,24 @@ The default download location is `~/.webdrivers` directory, and this is configur
40
45
 
41
46
  ### Version Pinning
42
47
 
43
- If you would like to use a specific (older or beta) version, you can specify it for each driver. Otherwise, the latest (stable)
44
- driver will be downloaded and passed to Selenium.
48
+ If you would like to use a specific (older or beta) version, you can specify it for each driver. Otherwise,
49
+ the latest (stable) driver will be downloaded and passed to Selenium.
45
50
 
46
51
  ```ruby
47
52
  # Chrome
48
- Webdrivers::Chromedriver.version = '2.46'
53
+ Webdrivers::Chromedriver.required_version = '2.46'
49
54
 
50
55
  # Firefox
51
- Webdrivers::Geckodriver.version = '0.23.0'
56
+ Webdrivers::Geckodriver.required_version = '0.23.0'
52
57
 
53
58
  # Microsoft Internet Explorer
54
- Webdrivers::IEdriver.version = '3.14.0'
59
+ Webdrivers::IEdriver.required_version = '3.14.0'
55
60
 
56
61
  # Microsoft Edge
57
- Webdrivers::MSWebdriver.version = '17134'
62
+ Webdrivers::MSWebdriver.required_version = '17134'
58
63
  ```
59
64
 
60
- You can also trigger the update in your code, but it is not required:
65
+ You can explicitly trigger the update in your code, but this will happen automatically when the driver is initialized:
61
66
 
62
67
  ```ruby
63
68
  Webdrivers::Chromedriver.update
@@ -107,33 +112,32 @@ Webdrivers.logger.level = :DEBUG
107
112
 
108
113
  ### Browser Specific Notes
109
114
 
110
- #### When using Chrome/Chromium
115
+ #### Chrome/Chromium
111
116
 
112
117
  The version of `chromedriver` will depend on the version of Chrome you are using it with:
113
118
 
114
- * For versions >= 70, the downloaded version of `chromedriver` will match the installed version of Google Chrome. More information [here](http://chromedriver.chromium.org/downloads/version-selection).
119
+ * For versions >= 70, the downloaded version of `chromedriver` will match the installed version of Google Chrome.
120
+ More information [here](http://chromedriver.chromium.org/downloads/version-selection).
115
121
  * For versions <= 69, `chromedriver` version 2.46 will be downloaded.
116
- * For beta versions, you'll have to set the desired beta version of `chromedriver` using `Webdrivers::Chromedriver.version`.
122
+ * For beta versions, you'll have to set the desired beta version of `chromedriver`
123
+ using `Webdrivers::Chromedriver.required_version`.
117
124
 
118
- The gem, by default, looks for the Google Chrome version. You can override this by providing a path to the Chromium binary:
125
+ The gem, by default, looks for the Google Chrome version. You can override this by providing a path to the
126
+ Chromium binary:
119
127
 
120
128
  ```ruby
121
129
  Selenium::WebDriver::Chrome.path = '/chromium/install/path/to/binary'
122
130
  ```
123
131
 
124
- This is also required if Google Chrome is not installed in its [default location](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver).
125
-
126
- #### When using Microsoft Edge
132
+ This is also required if Google Chrome is not installed in its
133
+ [default location](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver).
127
134
 
128
- After updating Microsoft Edge on Windows 10, you will need to delete the existing binary (`%USERPROFILE%/.webdrivers/MicrosoftWebDriver.exe`) to
129
- to be able to download the latest version through this gem.
135
+ #### Microsoft Edge
130
136
 
131
- This is because `MicrosoftWebDriver.exe` is not backwards compatible and it does not have an argument to retrieve
132
- the current version. We work around this limitation by querying the current Edge version from the registry and
133
- fetching the corresponding binary IF a file does not already exist. If a file does exist, the gem assumes it is the
134
- expected version and skips the download process.
137
+ Microsoft Edge support has been removed for now, as it is currently unreliable.
135
138
 
136
- If you continue with the outdated binary, Selenium will throw an error: `unable to connect to MicrosoftWebDriver localhost:17556`.
139
+ To use Microsoft Edge, please visit the
140
+ [Downloads and Installation page](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads)
137
141
 
138
142
  ## Wiki
139
143
 
@@ -150,5 +154,5 @@ Bug reports and pull requests are welcome [on GitHub](https://github.com/titusfo
150
154
 
151
155
  ## Copyright
152
156
 
153
- Copyright (c) 2017 Titus Fortner
157
+ Copyright (c) 2017-2019 Titus Fortner
154
158
  See LICENSE for details
data/Rakefile CHANGED
@@ -7,3 +7,5 @@ require 'rubocop/rake_task'
7
7
  RuboCop::RakeTask.new
8
8
 
9
9
  RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: %i[rubocop spec]
data/lib/webdrivers.rb CHANGED
@@ -1,28 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'webdrivers/selenium'
4
- require 'webdrivers/logger'
5
- require 'webdrivers/common'
6
3
  require 'webdrivers/chromedriver'
7
4
  require 'webdrivers/geckodriver'
8
5
  require 'webdrivers/iedriver'
9
6
  require 'webdrivers/mswebdriver'
10
-
11
- module Webdrivers
12
- class << self
13
- attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir
14
-
15
- def logger
16
- @logger ||= Webdrivers::Logger.new
17
- end
18
-
19
- def configure
20
- yield self
21
- end
22
-
23
- def net_http_ssl_fix
24
- raise 'Webdrivers.net_http_ssl_fix is no longer available.' \
25
- ' Please see https://github.com/titusfortner/webdrivers#ssl_connect-errors.'
26
- end
27
- end
28
- end
@@ -1,34 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'nokogiri'
4
3
  require 'shellwords'
4
+ require 'webdrivers/common'
5
5
 
6
6
  module Webdrivers
7
7
  class Chromedriver < Common
8
8
  class << self
9
9
  def current_version
10
10
  Webdrivers.logger.debug 'Checking current version'
11
- return nil unless downloaded?
11
+ return nil unless exists?
12
12
 
13
- ver = `#{binary} --version`
14
- Webdrivers.logger.debug "Current #{binary} version: #{ver}"
13
+ version = binary_version
14
+ return nil if version.nil?
15
15
 
16
16
  # Matches 2.46, 2.46.628411 and 73.0.3683.75
17
- normalize_version ver[/\d+\.\d+(\.\d+)?(\.\d+)?/]
17
+ normalize_version version[/\d+\.\d+(\.\d+)?(\.\d+)?/]
18
18
  end
19
19
 
20
20
  def latest_version
21
- return @latest_version if @latest_version
21
+ @latest_version ||= begin
22
+ # Versions before 70 do not have a LATEST_RELEASE file
23
+ return normalize_version('2.41') if release_version < normalize_version('70')
22
24
 
23
- raise StandardError, 'Can not reach site' unless site_available?
25
+ latest_applicable = with_cache(file_name) { latest_point_release(release_version) }
24
26
 
25
- # Versions before 70 do not have a LATEST_RELEASE file
26
- return normalize_version('2.46') if release_version < normalize_version('70.0.3538')
27
+ Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
28
+ normalize_version(latest_applicable)
29
+ end
30
+ end
27
31
 
28
- latest_applicable = latest_point_release(release_version)
32
+ # Returns currently installed Chrome version
33
+ def chrome_version
34
+ ver = send("chrome_on_#{System.platform}").chomp
29
35
 
30
- Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
31
- @latest_version = normalize_version(latest_applicable)
36
+ raise VersionError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
37
+
38
+ Webdrivers.logger.debug "Browser version: #{ver}"
39
+ normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
32
40
  end
33
41
 
34
42
  private
@@ -36,30 +44,20 @@ module Webdrivers
36
44
  def latest_point_release(version)
37
45
  release_file = "LATEST_RELEASE_#{version}"
38
46
  begin
39
- normalize_version(get(URI.join(base_url, release_file)))
40
- rescue Net::HTTPServerException
41
- latest_release = normalize_version(get(URI.join(base_url, 'LATEST_RELEASE')))
47
+ normalize_version(Network.get(URI.join(base_url, release_file)))
48
+ rescue StandardError
49
+ latest_release = normalize_version(Network.get(URI.join(base_url, 'LATEST_RELEASE')))
42
50
  Webdrivers.logger.debug "Unable to find a driver for: #{version}"
43
51
 
44
52
  msg = version > latest_release ? 'you appear to be using a non-production version of Chrome; ' : ''
45
- msg = "#{msg}please set `Webdrivers::Chromedriver.version = <desired driver version>` to an known "\
53
+ msg = "#{msg}please set `Webdrivers::Chromedriver.required_version = <desired driver version>` to an known "\
46
54
  'chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
47
- raise StandardError, msg
48
- end
49
- end
50
-
51
- def platform
52
- if Selenium::WebDriver::Platform.linux?
53
- 'linux64'
54
- elsif Selenium::WebDriver::Platform.mac?
55
- 'mac64'
56
- else
57
- 'win32'
55
+ raise VersionError, msg
58
56
  end
59
57
  end
60
58
 
61
59
  def file_name
62
- Selenium::WebDriver::Platform.windows? ? 'chromedriver.exe' : 'chromedriver'
60
+ System.platform == 'win' ? 'chromedriver.exe' : 'chromedriver'
63
61
  end
64
62
 
65
63
  def base_url
@@ -69,7 +67,14 @@ module Webdrivers
69
67
  def download_url
70
68
  return @download_url if @download_url
71
69
 
72
- url = "#{base_url}/#{desired_version}/chromedriver_#{platform}.zip"
70
+ version = if required_version.version.empty?
71
+ latest_version
72
+ else
73
+ normalize_version(required_version)
74
+ end
75
+
76
+ file_name = System.platform == 'win' ? 'win32' : "#{System.platform}64"
77
+ url = "#{base_url}/#{version}/chromedriver_#{file_name}.zip"
73
78
  Webdrivers.logger.debug "chromedriver URL: #{url}"
74
79
  @download_url = url
75
80
  end
@@ -83,29 +88,10 @@ module Webdrivers
83
88
  normalize_version(chrome.segments[0..2].join('.'))
84
89
  end
85
90
 
86
- # Returns currently installed Chrome version
87
- def chrome_version
88
- ver = case platform
89
- when 'win32'
90
- chrome_on_windows
91
- when 'linux64'
92
- chrome_on_linux
93
- when 'mac64'
94
- chrome_on_mac
95
- else
96
- raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
97
- end.chomp
98
-
99
- raise StandardError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
100
-
101
- Webdrivers.logger.debug "Browser version: #{ver}"
102
- normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
103
- end
104
-
105
- def chrome_on_windows
91
+ def chrome_on_win
106
92
  if browser_binary
107
93
  Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
108
- return `powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion`.strip
94
+ return System.call("powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion").strip
109
95
  end
110
96
 
111
97
  # Workaround for Google Chrome when using Jruby on Windows.
@@ -114,39 +100,39 @@ module Webdrivers
114
100
  ver = 'powershell (Get-Item -Path ((Get-ItemProperty "HKLM:\\Software\\Microsoft' \
115
101
  "\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\'))" \
116
102
  '.VersionInfo.ProductVersion'
117
- return `#{ver}`.strip
103
+ return System.call(ver).strip
118
104
  end
119
105
 
120
106
  # Default to Google Chrome
121
- reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
122
- executable = `powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'`.strip
107
+ reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
108
+ executable = System.call("powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'").strip
123
109
  Webdrivers.logger.debug "Browser executable: '#{executable}'"
124
110
  ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
125
- `powershell #{ps}`.strip
111
+ System.call("powershell #{ps}").strip
126
112
  end
127
113
 
128
114
  def chrome_on_linux
129
115
  if browser_binary
130
116
  Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
131
- return `#{Shellwords.escape browser_binary} --product-version`.strip
117
+ return System.call("#{Shellwords.escape browser_binary} --product-version").strip
132
118
  end
133
119
 
134
120
  # Default to Google Chrome
135
- executable = `which google-chrome`.strip
121
+ executable = System.call('which google-chrome').strip
136
122
  Webdrivers.logger.debug "Browser executable: '#{executable}'"
137
- `#{executable} --product-version`.strip
123
+ System.call("#{executable} --product-version").strip
138
124
  end
139
125
 
140
126
  def chrome_on_mac
141
127
  if browser_binary
142
128
  Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
143
- return `#{Shellwords.escape browser_binary} --version`.strip
129
+ return System.call("#{Shellwords.escape browser_binary} --version").strip
144
130
  end
145
131
 
146
132
  # Default to Google Chrome
147
133
  executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
148
134
  Webdrivers.logger.debug "Browser executable: #{executable}"
149
- `#{executable} --version`.strip
135
+ System.call("#{executable} --version").strip
150
136
  end
151
137
 
152
138
  #
@@ -156,6 +142,26 @@ module Webdrivers
156
142
  # For Chromium, Brave, or whatever else
157
143
  Selenium::WebDriver::Chrome.path
158
144
  end
145
+
146
+ def sufficient_binary?
147
+ super && current_version && (current_version < normalize_version('70.0.3538') ||
148
+ current_version.segments.first == release_version.segments.first)
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ if ::Selenium::WebDriver::Service.respond_to? :driver_path=
155
+ ::Selenium::WebDriver::Chrome::Service.driver_path = proc { ::Webdrivers::Chromedriver.update }
156
+ else
157
+ # v3.141.0 and lower
158
+ module Selenium
159
+ module WebDriver
160
+ module Chrome
161
+ def self.driver_path
162
+ @driver_path ||= Webdrivers::Chromedriver.update
163
+ end
164
+ end
159
165
  end
160
166
  end
161
167
  end