webdrivers 3.9.4 → 4.0.0.rc1

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: a4e0c2a5c2fd095d45921dd927a01a0a181e27ab
4
- data.tar.gz: 0d9be64a36320745d3d3eb17771c79ed53e6136a
3
+ metadata.gz: 35e2346c87541df0f3aade8f330ef3f9df6376cd
4
+ data.tar.gz: fd9c3d144960b435ff139b1d6b7073ef9ebd5a87
5
5
  SHA512:
6
- metadata.gz: ddea9e942925176d9239e06fd414e432e8a114fdd83279760001c0bc6080f8a4e6aaef8ca2bccefaac49e7d5988905f569ac2c3409e902c57e54dc6fd17bf911
7
- data.tar.gz: '0997d4066700cdefe6aea6acb59d96eac15475c0e9eaf5f3d053bda153d0b49d92ed512bba5c40e5a6bedb1aa2cce23ae6c586aa725ab9dd6d994c36736d2498'
6
+ metadata.gz: 0dd52833bcd3c354c45ec026c6d041d845018274fe27164a0fa0ec31f002b917221463659d9aa51e09824805444158775e63ba3b7c94c66e833b7f0dca09e2ab
7
+ data.tar.gz: 00e2e731f00ee020511d62fab5084eeaff766ffef19d7f11cba06e9a13dcd73ed31d2fd043811e5160de4dc920a515d9d74ee8244de7b7dd7484054fe7bed7d3
data/.rubocop.yml CHANGED
@@ -22,6 +22,7 @@ Metrics/MethodLength:
22
22
  Metrics/BlockLength:
23
23
  Exclude:
24
24
  - 'spec/**/*'
25
+ - 'lib/webdrivers/tasks/*.rake'
25
26
 
26
27
  Metrics/ClassLength:
27
28
  Max: 116
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ ### 4.0.0.rc1 (2019-05-20)
2
+ * locate Chrome binary the same way as chromedriver to ensure the correct browser version is obtained by default
3
+ * add rake tasts for update, remove and version
4
+ * removed all deprecated code
5
+
1
6
  ### 3.9.4 (2019-05-20)
2
7
  * Fix bug from bug fix that warned users about setting cache time when it was already set (issue #118)
3
- * make #base_url public for easier mocking (issue #113)
8
+ * make #base_url public for easier mocking (issue #109)
4
9
 
5
10
  ### 3.9.3 (2019-05-17)
6
11
  * Fix the bug that warned users about setting cache time when it was already set
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  (The MIT License)
2
2
 
3
3
  Copyright (c) 2017-2019: Titus Fortner
4
+ Copyright (c) 2019: Lakshya Kapoor, Thomas Walpole
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining
6
7
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -31,9 +31,10 @@ through Selenium.
31
31
 
32
32
  ### Specific Drivers
33
33
 
34
- If you want webdrivers to only manage specific drivers you can specify as follows:
34
+ If you want webdrivers to only manage specific drivers you can specify one or more as follows:
35
35
  ```ruby
36
36
  require 'webdrivers/chromedriver'
37
+ require 'webdrivers/firefox'
37
38
  require 'webdrivers/iedriver'
38
39
  ```
39
40
 
@@ -45,6 +46,9 @@ The default download location is `~/.webdrivers` directory, and this is configur
45
46
  Webdrivers.install_dir = '/webdrivers/install/dir'
46
47
  ```
47
48
 
49
+ Alternatively, you can define the path via the `WD_INSTALL_DIR` environment
50
+ variable.
51
+
48
52
  ### Version Pinning
49
53
 
50
54
  If you would like to use a specific (older or beta) version, you can specify it for each driver. Otherwise,
@@ -57,14 +61,12 @@ Webdrivers::Chromedriver.required_version = '2.46'
57
61
  # Firefox
58
62
  Webdrivers::Geckodriver.required_version = '0.23.0'
59
63
 
60
- # Microsoft Internet Explorer
64
+ # Internet Explorer
61
65
  Webdrivers::IEdriver.required_version = '3.14.0'
62
-
63
- # Microsoft Edge
64
- Webdrivers::MSWebdriver.required_version = '17134'
65
66
  ```
66
67
 
67
- You can explicitly trigger the update in your code, but this will happen automatically when the driver is initialized:
68
+ You can explicitly trigger the update in your code, but this will happen
69
+ automatically when the driver is initialized:
68
70
 
69
71
  ```ruby
70
72
  Webdrivers::Chromedriver.update
@@ -72,12 +74,17 @@ Webdrivers::Chromedriver.update
72
74
 
73
75
  ### Caching Drivers
74
76
 
75
- You can set Webdrivers to only look for updates if the previous check was longer ago than a specified number of seconds.
77
+ You can set Webdrivers to only look for updates if the previous check
78
+ was longer ago than a specified number of seconds.
79
+
76
80
  ```ruby
77
81
  Webdrivers.cache_time = 86_400
78
82
  ```
79
83
 
80
- The default in 3.9 is zero, and the default for 4.x will be 24 hours (86,400 seconds)
84
+ Alternatively, you can define this value via the `WD_CACHE_TIME` environment
85
+ variable.
86
+
87
+ The default is set to 24 hours (86,400 seconds).
81
88
 
82
89
  ### Proxy
83
90
 
@@ -113,6 +120,39 @@ require 'net_http_ssl_fix'
113
120
 
114
121
  Other solutions are documented on the RubyGems [website](https://guides.rubygems.org/ssl-certificate-update/).
115
122
 
123
+ ### Rake tasks
124
+
125
+ Each driver has its own set of `rake` tasks (with `Railtie` support) that
126
+ you can call once before executing the tests. These are especially
127
+ useful if you're running tests in parallel and want to avoid performing
128
+ an update check per thread.
129
+
130
+ ```bash
131
+ $ bundle exec rake -T
132
+ rake webdrivers:chromedriver:remove # Force remove chromedriver
133
+ rake webdrivers:chromedriver:update[version] # Remove and download updated chromedriver if necessary
134
+ rake webdrivers:chromedriver:version # Print current chromedriver version
135
+ rake webdrivers:geckodriver:remove # Force remove geckodriver
136
+ rake webdrivers:geckodriver:update[version] # Remove and download updated geckodriver if necessary
137
+ rake webdrivers:geckodriver:version # Print current geckodriver version
138
+ rake webdrivers:iedriver:remove # Force remove IEDriverServer
139
+ rake webdrivers:iedriver:update[version] # Remove and download updated IEDriverServer if necessary
140
+ rake webdrivers:iedriver:version # Print current IEDriverServer version
141
+ ```
142
+
143
+ These tasks respect the `WD_INSTALL_DIR` and `WD_CACHE_TIME` environment
144
+ variables which can also be passed through the `rake` command:
145
+
146
+ ```bash
147
+ $ bundle exec rake webdrivers:chromedriver:update[2.46] webdrivers:geckodriver:update[0.24.0] WD_CACHE_TIME=86_400 WD_INSTALL_DIR='my_dir'
148
+ 2019-05-20 19:03:01 INFO Webdrivers Updated to chromedriver 2.46.628388
149
+ 2019-05-20 19:03:04 INFO Webdrivers Updated to geckodriver 0.24.0
150
+ ```
151
+
152
+ Please note that these tasks do not use any of the configurations from your
153
+ project (code) and only respect the `ENV` variables and the version (optional)
154
+ passed to the `rake` task.
155
+
116
156
  ### Logging
117
157
 
118
158
  The logging level can be configured for debugging purpose:
@@ -129,7 +169,7 @@ The version of `chromedriver` will depend on the version of Chrome you are using
129
169
 
130
170
  * For versions >= 70, the downloaded version of `chromedriver` will match the installed version of Google Chrome.
131
171
  More information [here](http://chromedriver.chromium.org/downloads/version-selection).
132
- * For versions <= 69, `chromedriver` version 2.46 will be downloaded.
172
+ * For versions <= 69, `chromedriver` version 2.41 will be downloaded.
133
173
  * For beta versions, you'll have to set the desired beta version of `chromedriver`
134
174
  using `Webdrivers::Chromedriver.required_version`.
135
175
 
@@ -161,9 +201,5 @@ see LICENSE.txt for full details and copyright.
161
201
 
162
202
  ## Contributing
163
203
 
164
- Bug reports and pull requests are welcome [on GitHub](https://github.com/titusfortner/webdrivers). Run `bundle exec rake` and squash the commits in your PRs.
165
-
166
- ## Copyright
167
-
168
- Copyright (c) 2017-2019 Titus Fortner
169
- See LICENSE for details
204
+ Bug reports and pull requests are welcome [on GitHub](https://github.com/titusfortner/webdrivers).
205
+ Run `bundle exec rake` and squash the commits in your PRs.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webdrivers'
4
+
5
+ path = File.expand_path(__dir__)
6
+ Dir.glob("#{path}/tasks/*.rake").each { |f| import f }
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webdrivers
4
+ class ChromeFinder
5
+ class << self
6
+ def version
7
+ location = Selenium::WebDriver::Chrome.path || send("#{System.platform}_location")
8
+ version = send("#{System.platform}_version", location)
9
+
10
+ raise VersionError, 'Failed to find Chrome binary or its version.' if version.nil? || version.empty?
11
+
12
+ Webdrivers.logger.debug "Browser version: #{version}"
13
+ version[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
14
+ end
15
+
16
+ def win_location
17
+ return Selenium::WebDriver::Chrome.path unless Selenium::WebDriver::Chrome.path.nil?
18
+
19
+ envs = %w[LOCALAPPDATA PROGRAMFILES PROGRAMFILES(X86)]
20
+ directories = ['\\Google\\Chrome\\Application', '\\Chromium\\Application']
21
+ file = 'chrome.exe'
22
+
23
+ directories.each do |dir|
24
+ envs.each do |root|
25
+ option = "#{ENV[root]}\\#{dir}\\#{file}"
26
+ return option if File.exist?(option)
27
+ end
28
+ end
29
+ end
30
+
31
+ def mac_location
32
+ directories = ['', File.expand_path('~')]
33
+ files = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
34
+ '/Applications/Chromium.app/Contents/MacOS/Chromium']
35
+
36
+ directories.each do |dir|
37
+ files.each do |file|
38
+ option = "#{dir}/#{file}"
39
+ return option if File.exist?(option)
40
+ end
41
+ end
42
+ end
43
+
44
+ def linux_location
45
+ directories = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /opt/google/chrome]
46
+ files = %w[google-chrome chrome chromium chromium-browser]
47
+
48
+ directories.each do |dir|
49
+ files.each do |file|
50
+ option = "#{dir}/#{file}"
51
+ return option if File.exist?(option)
52
+ end
53
+ end
54
+ end
55
+
56
+ def win_version(location)
57
+ System.call("powershell (Get-ItemProperty '#{location}').VersionInfo.ProductVersion")&.strip
58
+ end
59
+
60
+ def linux_version(location)
61
+ System.call("#{Shellwords.escape location} --product-version")&.strip
62
+ end
63
+
64
+ def mac_version(location)
65
+ System.call("#{Shellwords.escape location} --version")&.strip
66
+ end
67
+ end
68
+ end
69
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'shellwords'
4
4
  require 'webdrivers/common'
5
+ require 'webdrivers/chrome_finder'
5
6
 
6
7
  module Webdrivers
7
8
  class Chromedriver < Common
@@ -42,12 +43,7 @@ module Webdrivers
42
43
  #
43
44
  # @return [Gem::Version]
44
45
  def chrome_version
45
- ver = send("chrome_on_#{System.platform}").chomp
46
-
47
- raise VersionError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
48
-
49
- Webdrivers.logger.debug "Browser version: #{ver}"
50
- normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
46
+ normalize_version ChromeFinder.version
51
47
  end
52
48
 
53
49
  #
@@ -110,61 +106,6 @@ module Webdrivers
110
106
  normalize_version(chrome.segments[0..2].join('.'))
111
107
  end
112
108
 
113
- def chrome_on_win
114
- if browser_binary
115
- Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
116
- return System.call("powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion").strip
117
- end
118
-
119
- # Workaround for Google Chrome when using Jruby on Windows.
120
- # @see https://github.com/titusfortner/webdrivers/issues/41
121
- if RUBY_PLATFORM == 'java'
122
- ver = 'powershell (Get-Item -Path ((Get-ItemProperty "HKLM:\\Software\\Microsoft' \
123
- "\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\'))" \
124
- '.VersionInfo.ProductVersion'
125
- return System.call(ver).strip
126
- end
127
-
128
- # Default to Google Chrome
129
- reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
130
- executable = System.call("powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'").strip
131
- Webdrivers.logger.debug "Browser executable: '#{executable}'"
132
- ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
133
- System.call("powershell #{ps}").strip
134
- end
135
-
136
- def chrome_on_linux
137
- if browser_binary
138
- Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
139
- return System.call("#{Shellwords.escape browser_binary} --product-version").strip
140
- end
141
-
142
- # Default to Google Chrome
143
- executable = System.call('which google-chrome').strip
144
- Webdrivers.logger.debug "Browser executable: '#{executable}'"
145
- System.call("#{executable} --product-version").strip
146
- end
147
-
148
- def chrome_on_mac
149
- if browser_binary
150
- Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
151
- return System.call("#{Shellwords.escape browser_binary} --version").strip
152
- end
153
-
154
- # Default to Google Chrome
155
- executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
156
- Webdrivers.logger.debug "Browser executable: #{executable}"
157
- System.call("#{executable} --version").strip
158
- end
159
-
160
- #
161
- # Returns user defined browser executable path from Selenium::WebDrivers::Chrome#path.
162
- #
163
- def browser_binary
164
- # For Chromium, Brave, or whatever else
165
- Selenium::WebDriver::Chrome.path
166
- end
167
-
168
109
  def sufficient_binary?
169
110
  super && current_version && (current_version < normalize_version('70.0.3538') ||
170
111
  current_version.segments.first == release_version.segments.first)
@@ -6,6 +6,7 @@ require 'webdrivers/logger'
6
6
  require 'webdrivers/network'
7
7
  require 'webdrivers/system'
8
8
  require 'selenium-webdriver'
9
+ require 'webdrivers/version'
9
10
 
10
11
  module Webdrivers
11
12
  class ConnectionError < StandardError
@@ -18,22 +19,22 @@ module Webdrivers
18
19
  end
19
20
 
20
21
  class << self
21
- attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir
22
+ attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass
23
+ attr_writer :install_dir, :cache_time
22
24
 
23
25
  #
24
26
  # Returns the amount of time (Seconds) the gem waits between two update checks.
25
27
  #
26
28
  def cache_time
27
- @cache_time || 0
29
+ @cache_time || ENV['WD_CACHE_TIME'].to_i
28
30
  end
29
31
 
30
32
  #
31
- # Set the amount of time (Seconds) the gem waits between two update checks. Disable
32
- # Common.cache_warning.
33
+ # Returns the install (download) directory path for the drivers.
33
34
  #
34
- def cache_time=(value)
35
- Common.cache_warning = true
36
- @cache_time = value
35
+ # @return [String]
36
+ def install_dir
37
+ @install_dir || ENV['WD_INSTALL_DIR'] || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
37
38
  end
38
39
 
39
40
  def logger
@@ -65,17 +66,6 @@ end
65
66
  class Common
66
67
  class << self
67
68
  attr_writer :required_version
68
- attr_accessor :cache_warning
69
-
70
- def version
71
- Webdrivers.logger.deprecate("#{self.class}#version", "#{self.class}#required_version")
72
- required_version
73
- end
74
-
75
- def version=(version)
76
- Webdrivers.logger.deprecate("#{self.class}#version=", "#{self.class}#required_version=")
77
- self.required_version = version
78
- end
79
69
 
80
70
  #
81
71
  # Returns the user defined required version.
@@ -100,14 +90,6 @@ end
100
90
  System.download(download_url, driver_path)
101
91
  end
102
92
 
103
- def desired_version
104
- old = "#{self.class}#desired_version"
105
- new = "#{self.class}#required_version or #{self.class}#latest_version"
106
- Webdrivers.logger.deprecate(old, new)
107
-
108
- desired_version == EMPTY_VERSION ? latest_version : normalize_version(desired_version)
109
- end
110
-
111
93
  #
112
94
  # Deletes the existing driver binary.
113
95
  #
@@ -118,16 +100,6 @@ end
118
100
  System.delete driver_path
119
101
  end
120
102
 
121
- def download
122
- Webdrivers.logger.deprecate('#download', '#update')
123
- System.download(download_url, driver_path)
124
- end
125
-
126
- def binary
127
- Webdrivers.logger.deprecate('#binary', '#driver_path')
128
- driver_path
129
- end
130
-
131
103
  #
132
104
  # Returns path to the driver binary.
133
105
  #
@@ -181,11 +153,6 @@ end
181
153
  if System.valid_cache?(file_name)
182
154
  normalize_version System.cached_version(file_name)
183
155
  else
184
- unless Common.cache_warning
185
- Webdrivers.logger.warn 'Driver caching is turned off in this version, but will be '\
186
- 'enabled by default in 4.x. Set the value with `Webdrivers#cache_time=` in seconds'
187
- Common.cache_warning = true
188
- end
189
156
  version = yield
190
157
  System.cache_version(file_name, version)
191
158
  normalize_version version
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webdrivers'
4
+ require 'rails'
5
+
6
+ module Webdrivers
7
+ class Railtie < Rails::Railtie
8
+ railtie_name :webdrivers
9
+
10
+ rake_tasks do
11
+ path = File.expand_path(__dir__)
12
+ Dir.glob("#{path}/tasks/*.rake").each { |f| load f }
13
+ end
14
+ end
15
+ end
@@ -26,7 +26,7 @@ module Webdrivers
26
26
  end
27
27
 
28
28
  def install_dir
29
- Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
29
+ Webdrivers.install_dir
30
30
  end
31
31
 
32
32
  def cache_version(file_name, version)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :webdrivers do
4
+ require 'webdrivers/chromedriver'
5
+
6
+ namespace :chromedriver do
7
+ Webdrivers.logger.level = :info
8
+
9
+ desc 'Print current chromedriver version'
10
+ task :version do
11
+ gem_ver = Webdrivers::Chromedriver.current_version
12
+ if gem_ver
13
+ Webdrivers.logger.info "chromedriver #{gem_ver.version}"
14
+ else
15
+ Webdrivers.logger.warn 'No existing chromedriver found.'
16
+ end
17
+ end
18
+
19
+ desc 'Remove and download updated chromedriver if necessary'
20
+ task :update, [:version] do |_, args|
21
+ args.with_defaults(version: 0)
22
+ Webdrivers.cache_time = ENV.fetch('WD_CACHE_TIME', 86_400)
23
+ Webdrivers.install_dir = ENV.fetch('WD_INSTALL_DIR', nil)
24
+ Webdrivers::Chromedriver.required_version = args.version
25
+ Webdrivers::Chromedriver.update
26
+ Webdrivers.logger.info "Updated to chromedriver #{Webdrivers::Chromedriver.current_version}"
27
+ end
28
+
29
+ desc 'Force remove chromedriver'
30
+ task :remove do
31
+ unless File.exist? Webdrivers::Chromedriver.driver_path
32
+ Webdrivers.logger.info 'No existing chromedriver to remove.'
33
+ next # Return early
34
+ end
35
+
36
+ cur_version = Webdrivers::Chromedriver.current_version
37
+ Webdrivers::Chromedriver.remove
38
+
39
+ if File.exist? Webdrivers::Chromedriver.driver_path # Failed for some reason
40
+ Webdrivers.logger.error 'Failed to remove chromedriver. Please try removing manually.'
41
+ else
42
+ Webdrivers.logger.info "Removed chromedriver #{cur_version}."
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :webdrivers do
4
+ require 'webdrivers/geckodriver'
5
+
6
+ namespace :geckodriver do
7
+ Webdrivers.logger.level = :info
8
+
9
+ desc 'Print current geckodriver version'
10
+ task :version do
11
+ gem_ver = Webdrivers::Geckodriver.current_version
12
+ if gem_ver
13
+ Webdrivers.logger.info "geckodriver #{gem_ver.version}"
14
+ else
15
+ Webdrivers.logger.warn 'No existing geckodriver found.'
16
+ end
17
+ end
18
+
19
+ desc 'Remove and download updated geckodriver if necessary'
20
+ task :update, [:version] do |_, args|
21
+ args.with_defaults(version: 0)
22
+ Webdrivers.cache_time = ENV.fetch('WD_CACHE_TIME', 86_400)
23
+ Webdrivers.install_dir = ENV.fetch('WD_INSTALL_DIR', nil)
24
+ Webdrivers::Geckodriver.required_version = args.version
25
+ Webdrivers::Geckodriver.update
26
+ Webdrivers.logger.info "Updated to geckodriver #{Webdrivers::Geckodriver.current_version}"
27
+ end
28
+
29
+ desc 'Force remove geckodriver'
30
+ task :remove do
31
+ unless File.exist? Webdrivers::Geckodriver.driver_path
32
+ Webdrivers.logger.info 'No existing geckodriver to remove.'
33
+ next # Return early
34
+ end
35
+
36
+ cur_version = Webdrivers::Geckodriver.current_version
37
+ Webdrivers::Geckodriver.remove
38
+
39
+ if File.exist? Webdrivers::Geckodriver.driver_path # Failed for some reason
40
+ Webdrivers.logger.error 'Failed to remove geckodriver. Please try removing manually.'
41
+ else
42
+ Webdrivers.logger.info "Removed geckodriver #{cur_version}."
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :webdrivers do
4
+ require 'webdrivers/iedriver'
5
+
6
+ namespace :iedriver do
7
+ Webdrivers.logger.level = :info
8
+
9
+ desc 'Print current IEDriverServer version'
10
+ task :version do
11
+ gem_ver = Webdrivers::IEdriver.current_version
12
+ if gem_ver
13
+ Webdrivers.logger.info "IEDriverServer #{gem_ver.version}"
14
+ else
15
+ Webdrivers.logger.warn 'No existing IEDriverServer found.'
16
+ end
17
+ end
18
+
19
+ desc 'Remove and download updated IEDriverServer if necessary'
20
+ task :update, [:version] do |_, args|
21
+ args.with_defaults(version: 0)
22
+ Webdrivers.cache_time = ENV.fetch('WD_CACHE_TIME', 86_400)
23
+ Webdrivers.install_dir = ENV.fetch('WD_INSTALL_DIR', nil)
24
+ Webdrivers::IEdriver.required_version = args.version
25
+ Webdrivers::IEdriver.update
26
+ Webdrivers.logger.info "Updated to IEDriverServer #{Webdrivers::IEdriver.current_version}"
27
+ end
28
+
29
+ desc 'Force remove IEDriverServer'
30
+ task :remove do
31
+ unless File.exist? Webdrivers::IEdriver.driver_path
32
+ Webdrivers.logger.info 'No existing IEDriverServer to remove.'
33
+ next # Return early
34
+ end
35
+
36
+ cur_version = Webdrivers::IEdriver.current_version
37
+ Webdrivers::IEdriver.remove
38
+
39
+ if File.exist? Webdrivers::IEdriver.driver_path # Failed for some reason
40
+ Webdrivers.logger.error 'Failed to remove IEDriverServer. Please try removing manually.'
41
+ else
42
+ Webdrivers.logger.info "Removed IEDriverServer #{cur_version}."
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webdrivers
4
+ VERSION = '4.0.0.rc1'
5
+ end
data/lib/webdrivers.rb CHANGED
@@ -3,4 +3,4 @@
3
3
  require 'webdrivers/chromedriver'
4
4
  require 'webdrivers/geckodriver'
5
5
  require 'webdrivers/iedriver'
6
- require 'webdrivers/mswebdriver'
6
+ require 'webdrivers/railtie' if defined?(Rails)
@@ -116,6 +116,31 @@ describe Webdrivers::Chromedriver do
116
116
 
117
117
  expect(Webdrivers::Network).to have_received(:get).twice
118
118
  end
119
+
120
+ context 'when required version is 0' do
121
+ it 'downloads the latest version' do
122
+ allow(chromedriver).to receive(:latest_version).and_return(Gem::Version.new('72.0.3626.7'))
123
+ chromedriver.required_version = 0
124
+ chromedriver.update
125
+ expect(chromedriver.current_version.version).to eq('72.0.3626.7')
126
+ end
127
+ end
128
+
129
+ context 'when required version is nil' do
130
+ it 'downloads the latest version' do
131
+ allow(chromedriver).to receive(:latest_version).and_return(Gem::Version.new('72.0.3626.7'))
132
+ chromedriver.required_version = nil
133
+ chromedriver.update
134
+ expect(chromedriver.current_version.version).to eq('72.0.3626.7')
135
+ end
136
+ end
137
+
138
+ context 'when ENV variable WD_CACHE_TIME is set' do
139
+ it 'uses cache time value from ENV variable' do
140
+ allow(ENV).to receive(:[]).with('WD_CACHE_TIME').and_return('999')
141
+ expect(Webdrivers.cache_time).to be(999)
142
+ end
143
+ end
119
144
  end
120
145
 
121
146
  describe '#current_version' do
@@ -234,19 +259,26 @@ describe Webdrivers::Chromedriver do
234
259
 
235
260
  describe '#install_dir' do
236
261
  it 'uses ~/.webdrivers as default value' do
237
- expect(Webdrivers::System.install_dir).to include('.webdriver')
262
+ expect(Webdrivers.install_dir).to include('.webdriver')
238
263
  end
239
264
 
240
265
  it 'uses provided value' do
241
266
  begin
242
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
267
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
243
268
  Webdrivers.install_dir = install_dir
244
269
 
245
- expect(Webdrivers::System.install_dir).to eq install_dir
270
+ expect(Webdrivers.install_dir).to eq install_dir
246
271
  ensure
247
272
  Webdrivers.install_dir = nil
248
273
  end
249
274
  end
275
+
276
+ context 'when ENV variable WD_INSTALL_DIR is set' do
277
+ it 'uses path from the ENV variable' do
278
+ allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('custom_dir')
279
+ expect(Webdrivers.install_dir).to be('custom_dir')
280
+ end
281
+ end
250
282
  end
251
283
 
252
284
  describe '#driver_path' do
data/webdrivers.gemspec CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('../lib', __dir__)
3
+ lib = File.expand_path('lib', __dir__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+ require "webdrivers/version"
4
6
 
5
7
  Gem::Specification.new do |s|
6
8
  s.name = 'webdrivers'
7
- s.version = '3.9.4'
8
- s.authors = ['Titus Fortner', 'Lakshya Kapoor']
9
+ s.version = Webdrivers::VERSION
10
+ s.authors = ['Titus Fortner', 'Lakshya Kapoor', 'Thomas Walpole']
9
11
  s.email = %w[titusfortner@gmail.com kapoorlakshya@gmail.com]
10
12
  s.homepage = 'https://github.com/titusfortner/webdrivers'
11
13
  s.summary = 'Easy download and use of browser drivers.'
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.4
4
+ version: 4.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  - Lakshya Kapoor
9
+ - Thomas Walpole
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2019-05-20 00:00:00.000000000 Z
13
+ date: 2019-05-21 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: ffi
@@ -171,19 +172,24 @@ files:
171
172
  - Rakefile
172
173
  - appveyor.yml
173
174
  - lib/webdrivers.rb
175
+ - lib/webdrivers/Rakefile
176
+ - lib/webdrivers/chrome_finder.rb
174
177
  - lib/webdrivers/chromedriver.rb
175
178
  - lib/webdrivers/common.rb
176
179
  - lib/webdrivers/geckodriver.rb
177
180
  - lib/webdrivers/iedriver.rb
178
181
  - lib/webdrivers/logger.rb
179
- - lib/webdrivers/mswebdriver.rb
180
182
  - lib/webdrivers/network.rb
183
+ - lib/webdrivers/railtie.rb
181
184
  - lib/webdrivers/system.rb
185
+ - lib/webdrivers/tasks/chromedriver.rake
186
+ - lib/webdrivers/tasks/geckodriver.rake
187
+ - lib/webdrivers/tasks/iedriver.rake
188
+ - lib/webdrivers/version.rb
182
189
  - spec/spec_helper.rb
183
190
  - spec/webdrivers/chromedriver_spec.rb
184
191
  - spec/webdrivers/geckodriver_spec.rb
185
192
  - spec/webdrivers/i_edriver_spec.rb
186
- - spec/webdrivers/ms_webdriver_spec.rb
187
193
  - spec/webdrivers/webdrivers_spec.rb
188
194
  - spec/webdrivers_proxy_support_spec.rb
189
195
  - webdrivers.gemspec
@@ -202,9 +208,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
208
  version: '0'
203
209
  required_rubygems_version: !ruby/object:Gem::Requirement
204
210
  requirements:
205
- - - ">="
211
+ - - ">"
206
212
  - !ruby/object:Gem::Version
207
- version: '0'
213
+ version: 1.3.1
208
214
  requirements: []
209
215
  rubyforge_project:
210
216
  rubygems_version: 2.6.14.4
@@ -216,6 +222,5 @@ test_files:
216
222
  - spec/webdrivers/chromedriver_spec.rb
217
223
  - spec/webdrivers/geckodriver_spec.rb
218
224
  - spec/webdrivers/i_edriver_spec.rb
219
- - spec/webdrivers/ms_webdriver_spec.rb
220
225
  - spec/webdrivers/webdrivers_spec.rb
221
226
  - spec/webdrivers_proxy_support_spec.rb
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'webdrivers/common'
4
-
5
- module Webdrivers
6
- class MSWebdriver
7
- class << self
8
- attr_accessor :ignore
9
- end
10
- end
11
- end
12
-
13
- module Selenium
14
- module WebDriver
15
- module Edge
16
- if defined?(Selenium::WebDriver::VERSION) && Selenium::WebDriver::VERSION > '3.141.0'
17
- class Service < WebDriver::Service
18
- class << self
19
- alias se_driver_path driver_path
20
-
21
- def driver_path
22
- unless Webdrivers::MSWebdriver.ignore
23
- Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
24
- ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
25
- 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
26
- 'or place it in PATH Environment Variable. '\
27
- 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
28
- 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
29
- end
30
-
31
- se_driver_path
32
- end
33
- end
34
- end
35
- else
36
- class << self
37
- alias se_driver_path driver_path
38
-
39
- def driver_path
40
- unless Webdrivers::MSWebdriver.ignore
41
- Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
42
- ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
43
- 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
44
- 'or place it in PATH Environment Variable. '\
45
- 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
46
- 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
47
- end
48
-
49
- se_driver_path
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Webdrivers::MSWebdriver do
6
- let(:mswebdriver) { described_class }
7
-
8
- it 'gives deprecation for using it' do
9
- msg = /WARN Webdrivers Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers gem/
10
-
11
- if defined?(Selenium::WebDriver::VERSION) && Selenium::WebDriver::VERSION > '3.141.0'
12
- expect { Selenium::WebDriver::Edge::Service.driver_path }.to output(msg).to_stdout_from_any_process
13
- else
14
- expect { Selenium::WebDriver::Edge.driver_path }.to output(msg).to_stdout_from_any_process
15
- end
16
- end
17
-
18
- it 'does not give deprecation when set to ignore' do
19
- described_class.ignore = true
20
-
21
- service = instance_double(Selenium::WebDriver::Service, host: '', start: nil, uri: '')
22
- bridge = instance_double(Selenium::WebDriver::Remote::Bridge, create_session: nil, session_id: '')
23
-
24
- allow(Selenium::WebDriver::Service).to receive(:new).and_return(service)
25
- allow(Selenium::WebDriver::Remote::Bridge).to receive(:new).and_return(bridge)
26
- allow(Selenium::WebDriver::Remote::W3C::Bridge).to receive(:new)
27
-
28
- expect { Selenium::WebDriver.for :edge }.not_to output.to_stdout_from_any_process
29
- end
30
- end