webdrivers 4.1.2 → 5.0.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.
@@ -34,7 +34,7 @@ module Webdrivers
34
34
  #
35
35
  # @return [String]
36
36
  def base_url
37
- 'https://selenium-release.storage.googleapis.com/'
37
+ 'https://api.github.com/repos/seleniumhq/selenium/releases'
38
38
  end
39
39
 
40
40
  private
@@ -43,32 +43,26 @@ module Webdrivers
43
43
  'IEDriverServer.exe'
44
44
  end
45
45
 
46
+ def direct_url(version)
47
+ downloads[version]
48
+ end
49
+
46
50
  def downloads
47
- doc = Nokogiri::XML.parse(Network.get(base_url))
48
- items = doc.css('Key').collect(&:text)
49
- items.select! { |item| item.include?('IEDriverServer_Win32') }
50
- ds = items.each_with_object({}) do |item, hash|
51
- key = normalize_version item[/([^_]+)\.zip/, 1]
52
- hash[key] = "#{base_url}#{item}"
51
+ ds = download_manifest.each_with_object({}) do |item, hash|
52
+ version = normalize_version item['name'][/\.?([^_]+)\.zip/, 1]
53
+ hash[version] = item['browser_download_url']
53
54
  end
54
55
  Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
55
56
  ds
56
57
  end
57
- end
58
- end
59
- end
60
58
 
61
- if ::Selenium::WebDriver::Service.respond_to? :driver_path=
62
- ::Selenium::WebDriver::IE::Service.driver_path = proc { ::Webdrivers::IEdriver.update }
63
- else
64
- # v3.141.0 and lower
65
- module Selenium
66
- module WebDriver
67
- module IE
68
- def self.driver_path
69
- @driver_path ||= Webdrivers::IEdriver.update
70
- end
59
+ def download_manifest
60
+ json = Network.get(base_url)
61
+ all_assets = JSON.parse(json).map { |release| release['assets'] }.flatten
62
+ all_assets.select { |asset| asset['name'].include?('IEDriverServer_Win32') }
71
63
  end
72
64
  end
73
65
  end
74
66
  end
67
+
68
+ ::Selenium::WebDriver::IE::Service.driver_path = proc { ::Webdrivers::IEdriver.update }
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
- require 'logger'
5
-
6
- # Code adapted from Selenium Implementation
7
- # https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/logger.rb
8
-
9
3
  module Webdrivers
10
4
  #
11
5
  # @example Enable full logging
@@ -18,94 +12,9 @@ module Webdrivers
18
12
  # Webdrivers.logger.info('This is info message')
19
13
  # Webdrivers.logger.warn('This is warning message')
20
14
  #
21
- class Logger
22
- extend Forwardable
23
- include ::Logger::Severity
24
-
25
- def_delegators :@logger, :debug, :debug?,
26
- :info, :info?,
27
- :warn, :warn?,
28
- :error, :error?,
29
- :fatal, :fatal?,
30
- :level
31
-
15
+ class Logger < Selenium::WebDriver::Logger
32
16
  def initialize
33
- @logger = create_logger($stdout)
34
- end
35
-
36
- def output=(io)
37
- # `Logger#reopen` was added in Ruby 2.3
38
- if @logger.respond_to?(:reopen)
39
- @logger.reopen(io)
40
- else
41
- @logger = create_logger(io)
42
- end
43
- end
44
-
45
- #
46
- # For Ruby < 2.3 compatibility
47
- # Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
48
- #
49
-
50
- def level=(severity)
51
- if severity.is_a?(Integer)
52
- @logger.level = severity
53
- else
54
- case severity.to_s.downcase
55
- when 'debug'
56
- @logger.level = DEBUG
57
- when 'info'
58
- @logger.level = INFO
59
- when 'warn'
60
- @logger.level = WARN
61
- when 'error'
62
- @logger.level = ERROR
63
- when 'fatal'
64
- @logger.level = FATAL
65
- when 'unknown'
66
- @logger.level = UNKNOWN
67
- else
68
- raise ArgumentError, "invalid log level: #{severity}"
69
- end
70
- end
71
- end
72
-
73
- #
74
- # Returns IO object used by logger internally.
75
- #
76
- # Normally, we would have never needed it, but we want to
77
- # use it as IO object for all child processes to ensure their
78
- # output is redirected there.
79
- #
80
- # It is only used in debug level, in other cases output is suppressed.
81
- #
82
- # @api private
83
- #
84
- def io
85
- @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
86
- end
87
-
88
- #
89
- # Marks code as deprecated with replacement.
90
- #
91
- # @param [String] old
92
- # @param [String] new
93
- #
94
- def deprecate(old, new)
95
- warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
96
- end
97
-
98
- private
99
-
100
- def create_logger(output)
101
- logger = ::Logger.new(output)
102
- logger.progname = 'Webdrivers'
103
- logger.level = ($DEBUG ? DEBUG : WARN)
104
- logger.formatter = proc do |severity, time, progname, msg|
105
- "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
106
- end
107
-
108
- logger
17
+ super('Webdrivers')
109
18
  end
110
19
  end
111
20
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'net/http'
4
+
3
5
  module Webdrivers
4
6
  #
5
7
  # @api private
@@ -4,6 +4,12 @@ require 'rubygems/package'
4
4
  require 'zip'
5
5
  require 'English'
6
6
 
7
+ # validate zip entry sizes to avoid zip bombs
8
+ # see https://github.com/rubyzip/rubyzip#size-validation
9
+ # and https://github.com/rubyzip/rubyzip/pull/403 for further details
10
+ # this will be the default in rubyzip 2.0+
11
+ Zip.validate_entry_sizes = true
12
+
7
13
  module Webdrivers
8
14
  #
9
15
  # @api private
@@ -14,11 +20,13 @@ module Webdrivers
14
20
  max_attempts = 3
15
21
  attempts_made = 0
16
22
  delay = 0.5
17
- Webdrivers.logger.debug "Deleting #{file}"
18
23
 
19
24
  begin
20
25
  attempts_made += 1
21
- File.delete file if File.exist? file
26
+ if File.exist? file
27
+ Webdrivers.logger.debug "Deleting #{file}"
28
+ File.delete file
29
+ end
22
30
  rescue Errno::EACCES # Solves an intermittent file locking issue on Windows
23
31
  sleep(delay)
24
32
  retry if File.exist?(file) && attempts_made <= max_attempts
@@ -140,6 +148,35 @@ module Webdrivers
140
148
  end
141
149
  end
142
150
 
151
+ def apple_m1_architecture?
152
+ if platform == 'mac' && RUBY_PLATFORM.include?('arm64-darwin')
153
+ Webdrivers.logger.debug 'Apple architecture: M1 (arm64-darwin)'
154
+ return true
155
+ end
156
+
157
+ Webdrivers.logger.debug 'Apple architecture: Intel (mac64)'
158
+ false
159
+ end
160
+
161
+ # @return [TrueClass, FalseClass]
162
+ def wsl_v1?
163
+ platform == 'linux' && File.open('/proc/version').read.include?('Microsoft')
164
+ end
165
+
166
+ # @param [String] path
167
+ # @return [String]
168
+ def to_win32_path(path)
169
+ return path if /[a-z]:\\/iu.match?(path)
170
+
171
+ call("wslpath -w '#{path}'").chomp
172
+ end
173
+
174
+ # @param [String] path
175
+ # @return [String]
176
+ def to_wsl_path(path)
177
+ call("wslpath -u '#{path}'").chomp
178
+ end
179
+
143
180
  def bitsize
144
181
  Selenium::WebDriver::Platform.bitsize
145
182
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webdrivers
4
- VERSION = '4.1.2'
4
+ VERSION = '5.0.0'
5
5
  end
@@ -47,4 +47,57 @@ describe Webdrivers::ChromeFinder do
47
47
  expect { chrome_finder.version }.to raise_error(Webdrivers::BrowserNotFound)
48
48
  end
49
49
  end
50
+
51
+ context 'when running in WSL' do
52
+ before do
53
+ skip "The current platform cannot be WSL, as it's not Linux" unless Selenium::WebDriver::Platform.linux?
54
+
55
+ allow(Webdrivers::System).to receive(:wsl_v1?).and_return(true)
56
+ allow(Webdrivers::System).to receive(:to_wsl_path).and_return('')
57
+ allow(Webdrivers::System).to receive(:to_win32_path).and_return('')
58
+ end
59
+
60
+ it 'checks Windows locations for Chrome' do
61
+ drive = 'c'
62
+ user = 'WinUser'
63
+ file = 'chrome.exe'
64
+ path = [
65
+ '/home/wsl-user/.local/bin',
66
+ '/usr/local/bin',
67
+ '/usr/local/games',
68
+ '/usr/bin',
69
+ "/#{drive}/Users/#{user}/AppData/Local/Microsoft/WindowsApps",
70
+ '/snap/bin'
71
+ ].join ':'
72
+
73
+ allow(chrome_finder).to receive(:user_defined_location).and_return(nil)
74
+ allow(ENV).to receive(:[]).with('WD_CHROME_PATH').and_return(nil)
75
+ allow(ENV).to receive(:[]).with('PATH').and_return(path)
76
+ allow(File).to receive(:exist?).and_return(false)
77
+
78
+ locations = [
79
+ "#{drive}:\\Users\\#{user}\\AppData\\Local\\Google\\Chrome\\Application\\#{file}",
80
+ "#{drive}:\\Program Files (x86)\\Chromium\\Application\\#{file}",
81
+ "#{drive}:\\Program Files\\Google\\Chrome\\Application\\#{file}"
82
+ ]
83
+
84
+ # CIs don't support WSL yet, so our mocks lead to the error path for simplicity
85
+ expect { chrome_finder.location }.to raise_error(Webdrivers::BrowserNotFound)
86
+
87
+ locations.each do |dir|
88
+ expect(Webdrivers::System).to have_received(:to_wsl_path).with(dir)
89
+ end
90
+ end
91
+
92
+ it 'uses win_version to get the Chrome version using win32 path' do
93
+ allow(chrome_finder).to receive(:win_version).and_return('')
94
+ allow(File).to receive(:exist?).and_return(true)
95
+
96
+ # CIs don't support WSL yet, so our mocks lead to the error path for simplicity
97
+ expect { chrome_finder.version }.to raise_error(Webdrivers::VersionError)
98
+
99
+ expect(Webdrivers::System).to have_received(:to_win32_path)
100
+ expect(chrome_finder).to have_received(:win_version)
101
+ end
102
+ end
50
103
  end
@@ -106,15 +106,16 @@ describe Webdrivers::Chromedriver do
106
106
  end
107
107
  end
108
108
 
109
- it 'makes a network call if cached driver does not match the browser' do
109
+ it 'makes network calls if cached driver does not match the browser' do
110
110
  Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
111
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('71.0.3578.137'))
111
112
  allow(chromedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
112
113
  allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
113
114
  allow(Webdrivers::System).to receive(:download)
114
115
 
115
116
  chromedriver.update
116
117
 
117
- expect(Webdrivers::Network).to have_received(:get).once
118
+ expect(Webdrivers::Network).to have_received(:get).twice
118
119
  end
119
120
 
120
121
  context 'when required version is 0' do
@@ -155,19 +156,19 @@ describe Webdrivers::Chromedriver do
155
156
 
156
157
  describe '#latest_version' do
157
158
  it 'returns 2.41 if the browser version is less than 70' do
158
- allow(chromedriver).to receive(:browser_version).and_return('69.0.0')
159
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('69.0.0')
159
160
 
160
161
  expect(chromedriver.latest_version).to eq(Gem::Version.new('2.41'))
161
162
  end
162
163
 
163
164
  it 'returns the correct point release for a production version greater than 70' do
164
- allow(chromedriver).to receive(:browser_version).and_return '71.0.3578.9999'
165
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('71.0.3578.9999')
165
166
 
166
167
  expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
167
168
  end
168
169
 
169
170
  it 'raises VersionError for beta version' do
170
- allow(chromedriver).to receive(:browser_version).and_return('100.0.0')
171
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('100.0.0')
171
172
  msg = 'Unable to find latest point release version for 100.0.0. '\
172
173
  'You appear to be using a non-production version of Chrome. '\
173
174
  'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
@@ -177,7 +178,7 @@ describe Webdrivers::Chromedriver do
177
178
  end
178
179
 
179
180
  it 'raises VersionError for unknown version' do
180
- allow(chromedriver).to receive(:browser_version).and_return('72.0.9999.0000')
181
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('72.0.9999.0000')
181
182
  msg = 'Unable to find latest point release version for 72.0.9999. '\
182
183
  'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
183
184
  'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
@@ -199,9 +200,12 @@ describe Webdrivers::Chromedriver do
199
200
  expect(File.exist?("#{Webdrivers::System.install_dir}/chromedriver.version")).to eq true
200
201
  end
201
202
 
202
- it 'does not make network call if cache is valid' do
203
+ it 'does not make network calls if cache is valid and driver exists' do
203
204
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
204
205
  Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
206
+ allow(chromedriver).to receive(:current_version).and_return Gem::Version.new('71.0.3578.137')
207
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('71.0.3578.137')
208
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
205
209
  allow(Webdrivers::Network).to receive(:get)
206
210
 
207
211
  expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
@@ -209,10 +213,11 @@ describe Webdrivers::Chromedriver do
209
213
  expect(Webdrivers::Network).not_to have_received(:get)
210
214
  end
211
215
 
212
- it 'makes a network call if cache is expired' do
216
+ it 'makes network calls if cache is expired' do
213
217
  Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
218
+ allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('71.0.3578.137')
214
219
  allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
215
- allow(Webdrivers::System).to receive(:valid_cache?)
220
+ allow(Webdrivers::System).to receive(:valid_cache?).and_return(false)
216
221
 
217
222
  expect(chromedriver.latest_version).to eq Gem::Version.new('73.0.3683.68')
218
223
 
@@ -5,13 +5,7 @@ require 'spec_helper'
5
5
  describe Webdrivers::EdgeFinder do
6
6
  let(:edge_finder) { described_class }
7
7
 
8
- before(:all) do # rubocop:disable RSpec/BeforeAfterAll
9
- # Skip these tests if version of selenium-webdriver being tested with doesn't
10
- # have Chromium based Edge support
11
- unless defined?(Selenium::WebDriver::EdgeChrome)
12
- skip "The current selenium-webdriver doesn't include Chromium based Edge support"
13
- end
14
- end
8
+ before { skip 'Edge is not yet supported on Linux' if Webdrivers::System.platform == 'linux' }
15
9
 
16
10
  context 'when the user relies on the gem to figure out the location of Edge' do
17
11
  it 'determines the location correctly based on the current OS' do
@@ -20,8 +14,8 @@ describe Webdrivers::EdgeFinder do
20
14
  end
21
15
 
22
16
  context 'when the user provides a path to the Edge binary' do
23
- it 'uses Selenium::WebDriver::EdgeChrome.path when it is defined' do
24
- Selenium::WebDriver::EdgeChrome.path = edge_finder.location
17
+ it 'uses Selenium::WebDriver::Edge.path when it is defined' do
18
+ Selenium::WebDriver::Edge.path = edge_finder.location
25
19
  locations = %i[win_location mac_location linux_location]
26
20
  allow(edge_finder).to receive_messages(locations)
27
21
 
@@ -29,8 +23,8 @@ describe Webdrivers::EdgeFinder do
29
23
  locations.each { |loc| expect(edge_finder).not_to have_received(loc) }
30
24
  end
31
25
 
32
- it "uses ENV['WD_EDGE_CHROME_PATH'] when it is defined" do
33
- allow(ENV).to receive(:[]).with('WD_EDGE_CHROME_PATH').and_return(edge_finder.location)
26
+ it "uses ENV['WD_EDGE_PATH'] when it is defined" do
27
+ allow(ENV).to receive(:[]).with('WD_EDGE_PATH').and_return(edge_finder.location)
34
28
  locations = %i[win_location mac_location linux_location]
35
29
  allow(edge_finder).to receive_messages(locations)
36
30
 
@@ -38,11 +32,11 @@ describe Webdrivers::EdgeFinder do
38
32
  locations.each { |loc| expect(edge_finder).not_to have_received(loc) }
39
33
  end
40
34
 
41
- it 'uses Selenium::WebDriver::EdgeChrome.path over WD_EDGE_CHROME_PATH' do
42
- Selenium::WebDriver::EdgeChrome.path = edge_finder.location
43
- allow(ENV).to receive(:[]).with('WD_EDGE_CHROME_PATH').and_return('my_wd_chrome_path')
35
+ it 'uses Selenium::WebDriver::Edge.path over WD_EDGE_PATH' do
36
+ Selenium::WebDriver::Edge.path = edge_finder.location
37
+ allow(ENV).to receive(:[]).with('WD_EDGE_PATH').and_return('my_wd_chrome_path')
44
38
  expect(edge_finder.version).not_to be_nil
45
- expect(ENV).not_to have_received(:[]).with('WD_EDGE_CHROME_PATH')
39
+ expect(ENV).not_to have_received(:[]).with('WD_EDGE_PATH')
46
40
  end
47
41
  end
48
42
 
@@ -5,16 +5,11 @@ require 'spec_helper'
5
5
  describe Webdrivers::Edgedriver do
6
6
  let(:edgedriver) { described_class }
7
7
 
8
- before(:all) do # rubocop:disable RSpec/BeforeAfterAll
9
- # Skip these tests if version of selenium-webdriver being tested with doesn't
10
- # have Chromium based Edge support
11
- unless defined?(Selenium::WebDriver::EdgeChrome)
12
- skip "The current selenium-webdriver doesn't include Chromium based Edge support"
13
- end
8
+ before do
9
+ skip 'Edge is not yet supported on Linux' if Webdrivers::System.platform == 'linux'
10
+ edgedriver.remove
14
11
  end
15
12
 
16
- before { edgedriver.remove }
17
-
18
13
  describe '#update' do
19
14
  context 'when evaluating #correct_binary?' do
20
15
  it 'does not download when latest version and current version match' do
@@ -114,15 +109,16 @@ describe Webdrivers::Edgedriver do
114
109
  end
115
110
  end
116
111
 
117
- it 'makes a network call if cached driver does not match the browser' do
112
+ it 'makes network calls if cached driver does not match the browser' do
118
113
  Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
119
- allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
114
+ allow(edgedriver).to receive(:current_version).and_return Gem::Version.new('71.0.3578.137')
115
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('73.0.3683.68')
120
116
  allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68'.encode('UTF-16'))
121
117
  allow(Webdrivers::System).to receive(:download)
122
118
 
123
119
  edgedriver.update
124
120
 
125
- expect(Webdrivers::Network).to have_received(:get).once
121
+ expect(Webdrivers::Network).to have_received(:get).twice
126
122
  end
127
123
 
128
124
  context 'when required version is 0' do
@@ -163,13 +159,13 @@ describe Webdrivers::Edgedriver do
163
159
 
164
160
  describe '#latest_version' do
165
161
  it 'returns the correct point release for a production version' do
166
- allow(edgedriver).to receive(:browser_version).and_return '77.0.207.0'
162
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
167
163
 
168
164
  expect(edgedriver.latest_version).to be_between(Gem::Version.new('77.0.207.0'), Gem::Version.new('78'))
169
165
  end
170
166
 
171
167
  it 'raises VersionError for beta version' do
172
- allow(edgedriver).to receive(:browser_version).and_return('100.0.0')
168
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('100.0.0')
173
169
  msg = 'Unable to find latest point release version for 100.0.0. '\
174
170
  'You appear to be using a non-production version of Edge. '\
175
171
  'Please set `Webdrivers::Edgedriver.required_version = <desired driver version>` '\
@@ -179,8 +175,7 @@ describe Webdrivers::Edgedriver do
179
175
  end
180
176
 
181
177
  it 'raises VersionError for unknown version' do
182
- skip "MS doesn't yet support point release latest versioning."
183
- allow(edgedriver).to receive(:browser_version).and_return('77.0.9999.0000')
178
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.9999')
184
179
  msg = 'Unable to find latest point release version for 77.0.9999. '\
185
180
  'Please set `Webdrivers::Edgedriver.required_version = <desired driver version>` '\
186
181
  'to a known edgedriver version: Can not reach https://msedgedriver.azureedge.net/'
@@ -196,28 +191,31 @@ describe Webdrivers::Edgedriver do
196
191
  end
197
192
 
198
193
  it 'creates cached file' do
199
- allow(edgedriver).to receive(:browser_version).and_return('77.0.207.0')
194
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
200
195
  allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))
201
196
 
202
197
  edgedriver.latest_version
203
198
  expect(File.exist?("#{Webdrivers::System.install_dir}/msedgedriver.version")).to eq true
204
199
  end
205
200
 
206
- it 'does not make network call if cache is valid' do
201
+ it 'does not make network calls if cache is valid and driver exists' do
207
202
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
208
- Webdrivers::System.cache_version('msedgedriver', '77.0.207.0')
203
+ Webdrivers::System.cache_version('msedgedriver', '82.0.445.0')
204
+ allow(edgedriver).to receive(:current_version).and_return Gem::Version.new('82.0.445.0')
205
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('82.0.445.0')
206
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
209
207
  allow(Webdrivers::Network).to receive(:get)
210
208
 
211
- expect(edgedriver.latest_version).to eq Gem::Version.new('77.0.207.0')
209
+ expect(edgedriver.latest_version).to eq Gem::Version.new('82.0.445.0')
212
210
 
213
211
  expect(Webdrivers::Network).not_to have_received(:get)
214
212
  end
215
213
 
216
- it 'makes a network call if cache is expired' do
214
+ it 'makes network calls if cache is expired' do
217
215
  Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
218
216
  allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))
219
- allow(Webdrivers::System).to receive(:valid_cache?)
220
- allow(edgedriver).to receive(:browser_version).and_return('77.0.207.0')
217
+ allow(Webdrivers::System).to receive(:valid_cache?).and_return(false)
218
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
221
219
 
222
220
  expect(edgedriver.latest_version).to eq Gem::Version.new('77.0.207.0')
223
221
 
@@ -135,9 +135,10 @@ You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
135
135
  expect(File.exist?("#{Webdrivers::System.install_dir}/geckodriver.version")).to eq true
136
136
  end
137
137
 
138
- it 'does not make network call if cache is valid' do
138
+ it 'does not make network calls if cache is valid and driver exists' do
139
139
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
140
140
  Webdrivers::System.cache_version('geckodriver', '0.23.0')
141
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
141
142
  allow(Webdrivers::Network).to receive(:get)
142
143
 
143
144
  expect(geckodriver.latest_version).to eq Gem::Version.new('0.23.0')
@@ -191,14 +192,12 @@ You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
191
192
  end
192
193
 
193
194
  it 'uses provided value' do
194
- begin
195
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
196
- Webdrivers.install_dir = install_dir
195
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
196
+ Webdrivers.install_dir = install_dir
197
197
 
198
- expect(Webdrivers::System.install_dir).to eq install_dir
199
- ensure
200
- Webdrivers.install_dir = nil
201
- end
198
+ expect(Webdrivers::System.install_dir).to eq install_dir
199
+ ensure
200
+ Webdrivers.install_dir = nil
202
201
  end
203
202
  end
204
203
 
@@ -6,6 +6,10 @@ describe Webdrivers::IEdriver do
6
6
  let(:iedriver) { described_class }
7
7
 
8
8
  before do
9
+ if ENV['CI'] && !Selenium::WebDriver::Platform.windows?
10
+ skip('Only run IE tests on Windows on CI because rate limiting')
11
+ end
12
+
9
13
  iedriver.remove
10
14
  iedriver.required_version = nil
11
15
  end
@@ -69,7 +73,7 @@ describe Webdrivers::IEdriver do
69
73
  it 'raises ConnectionError if offline' do
70
74
  allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
75
 
72
- msg = %r{Can not reach https://selenium-release.storage.googleapis.com/}
76
+ msg = %r{Can not reach https://api.github.com/repos/seleniumhq/selenium/releases}
73
77
  expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
78
  end
75
79
  end
@@ -109,15 +113,17 @@ describe Webdrivers::IEdriver do
109
113
  end
110
114
 
111
115
  it 'creates cached file' do
112
- allow(Webdrivers::Network).to receive(:get).and_return('3.4.0')
116
+ json = '[{"assets": [{"name":"IEDriverServer_Win32_3.150.0.zip"}]}]'
117
+ allow(Webdrivers::Network).to receive(:get).and_return(json)
113
118
 
114
119
  iedriver.latest_version
115
120
  expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
116
121
  end
117
122
 
118
- it 'does not make network call if cache is valid' do
123
+ it 'does not make network calls if cache is valid and driver exists' do
119
124
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
120
125
  Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
126
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
121
127
  allow(Webdrivers::Network).to receive(:get)
122
128
 
123
129
  expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
@@ -173,14 +179,12 @@ describe Webdrivers::IEdriver do
173
179
  end
174
180
 
175
181
  it 'uses provided value' do
176
- begin
177
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
178
- Webdrivers.install_dir = install_dir
182
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
183
+ Webdrivers.install_dir = install_dir
179
184
 
180
- expect(Webdrivers::System.install_dir).to eq install_dir
181
- ensure
182
- Webdrivers.install_dir = nil
183
- end
185
+ expect(Webdrivers::System.install_dir).to eq install_dir
186
+ ensure
187
+ Webdrivers.install_dir = nil
184
188
  end
185
189
  end
186
190