webdrivers 3.8.1 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -9
- data/.travis.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +28 -24
- data/Rakefile +2 -0
- data/lib/webdrivers.rb +0 -22
- data/lib/webdrivers/chromedriver.rb +65 -59
- data/lib/webdrivers/common.rb +101 -167
- data/lib/webdrivers/geckodriver.rb +45 -18
- data/lib/webdrivers/iedriver.rb +26 -5
- data/lib/webdrivers/mswebdriver.rb +45 -49
- data/lib/webdrivers/network.rb +58 -0
- data/lib/webdrivers/system.rb +151 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/webdrivers/chromedriver_spec.rb +197 -83
- data/spec/webdrivers/geckodriver_spec.rb +181 -37
- data/spec/webdrivers/i_edriver_spec.rb +171 -20
- data/spec/webdrivers/ms_webdriver_spec.rb +17 -13
- data/spec/webdrivers_proxy_support_spec.rb +2 -2
- data/webdrivers.gemspec +3 -2
- metadata +20 -5
- data/lib/webdrivers/selenium.rb +0 -40
@@ -1,58 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'webdrivers/common'
|
4
|
+
|
3
5
|
module Webdrivers
|
4
|
-
class MSWebdriver
|
6
|
+
class MSWebdriver
|
5
7
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# Unfortunately, MicrosoftWebDriver.exe does not have an option to get the version.
|
11
|
-
# To work around it we query the currently installed version of Microsoft Edge instead
|
12
|
-
# and compare it to the list of available downloads.
|
13
|
-
version = `powershell (Get-AppxPackage -Name Microsoft.MicrosoftEdge).Version`
|
14
|
-
raise 'Failed to check Microsoft Edge version.' if version.empty? # Package name changed?
|
15
|
-
|
16
|
-
Webdrivers.logger.debug "Current version of Microsoft Edge is #{version.chomp!}"
|
17
|
-
|
18
|
-
build = version.split('.')[1] # "41.16299.248.0" => "16299"
|
19
|
-
Webdrivers.logger.debug "Expecting MicrosoftWebDriver.exe version #{build}"
|
20
|
-
build.to_i
|
21
|
-
end
|
22
|
-
|
23
|
-
# Webdriver binaries for Microsoft Edge are not backwards compatible.
|
24
|
-
# For this reason, instead of downloading the latest binary we download the correct one for the
|
25
|
-
# currently installed browser version.
|
26
|
-
alias version windows_version
|
27
|
-
|
28
|
-
def version=(*)
|
29
|
-
raise 'Version can not be set for MSWebdriver because it is dependent on the version of Edge'
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def file_name
|
35
|
-
'MicrosoftWebDriver.exe'
|
36
|
-
end
|
37
|
-
|
38
|
-
def downloads
|
39
|
-
array = Nokogiri::HTML(get(base_url)).xpath("//li[@class='driver-download']/a")
|
40
|
-
array.each_with_object({}) do |link, hash|
|
41
|
-
next if link.text == 'Insiders'
|
8
|
+
attr_accessor :ignore
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
42
12
|
|
43
|
-
|
44
|
-
|
13
|
+
module Selenium
|
14
|
+
module WebDriver
|
15
|
+
module Edge
|
16
|
+
if 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
|
45
51
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def base_url
|
49
|
-
'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/'
|
50
|
-
end
|
51
|
-
|
52
|
-
# Assume we have the latest if file exists since MicrosoftWebdriver.exe does not have an
|
53
|
-
# argument to check the current version.
|
54
|
-
def correct_binary?
|
55
|
-
File.exist?(binary)
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Webdrivers
|
4
|
+
class Network
|
5
|
+
class << self
|
6
|
+
def get(url, limit = 10)
|
7
|
+
Webdrivers.logger.debug "Making network call to #{url}"
|
8
|
+
|
9
|
+
response = get_response(url, limit)
|
10
|
+
case response
|
11
|
+
when Net::HTTPSuccess
|
12
|
+
response.body
|
13
|
+
else
|
14
|
+
raise StandardError, "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_url(url, limit = 10)
|
19
|
+
Webdrivers.logger.debug "Making network call to #{url}"
|
20
|
+
|
21
|
+
get_response(url, limit).uri.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_response(url, limit = 10)
|
25
|
+
raise StandardError, 'Too many HTTP redirects' if limit.zero?
|
26
|
+
|
27
|
+
begin
|
28
|
+
response = http.get_response(URI(url))
|
29
|
+
rescue SocketError
|
30
|
+
raise ConnectionError, "Can not reach #{url}"
|
31
|
+
end
|
32
|
+
|
33
|
+
Webdrivers.logger.debug "Get response: #{response.inspect}"
|
34
|
+
|
35
|
+
if response.is_a?(Net::HTTPRedirection)
|
36
|
+
location = response['location']
|
37
|
+
Webdrivers.logger.debug "Redirected to #{location}"
|
38
|
+
get_response(location, limit - 1)
|
39
|
+
else
|
40
|
+
response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def http
|
45
|
+
if using_proxy
|
46
|
+
Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
|
47
|
+
Webdrivers.proxy_user, Webdrivers.proxy_pass)
|
48
|
+
else
|
49
|
+
Net::HTTP
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def using_proxy
|
54
|
+
Webdrivers.proxy_addr && Webdrivers.proxy_port
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems/package'
|
4
|
+
require 'zip'
|
5
|
+
|
6
|
+
module Webdrivers
|
7
|
+
class System
|
8
|
+
class << self
|
9
|
+
def delete(file)
|
10
|
+
max_attempts = 3
|
11
|
+
attempts_made = 0
|
12
|
+
delay = 0.5
|
13
|
+
Webdrivers.logger.debug "Deleting #{file}"
|
14
|
+
|
15
|
+
begin
|
16
|
+
attempts_made += 1
|
17
|
+
File.delete file if File.exist? file
|
18
|
+
rescue Errno::EACCES # Solves an intermittent file locking issue on Windows
|
19
|
+
sleep(delay)
|
20
|
+
retry if File.exist?(file) && attempts_made <= max_attempts
|
21
|
+
raise
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def install_dir
|
26
|
+
Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
|
27
|
+
end
|
28
|
+
|
29
|
+
def cache_version(file_name, version)
|
30
|
+
FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
|
31
|
+
|
32
|
+
File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'w+') do |file|
|
33
|
+
file.print(version)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def cached_version(file_name)
|
38
|
+
File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'r', &:read)
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_cache?(file_name)
|
42
|
+
file = "#{install_dir}/#{file_name.gsub('.exe', '')}.version"
|
43
|
+
return false unless File.exist?(file)
|
44
|
+
|
45
|
+
Time.now - File.mtime(file) < Webdrivers.cache_time
|
46
|
+
end
|
47
|
+
|
48
|
+
def download(url, target)
|
49
|
+
FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
|
50
|
+
|
51
|
+
download_file(url, target)
|
52
|
+
|
53
|
+
FileUtils.chmod 'ugo+rx', target
|
54
|
+
Webdrivers.logger.debug "Completed download and processing of #{target}"
|
55
|
+
target
|
56
|
+
end
|
57
|
+
|
58
|
+
def download_file(url, target)
|
59
|
+
file_name = File.basename(url)
|
60
|
+
Dir.chdir(install_dir) do
|
61
|
+
tempfile = Tempfile.open(['', file_name], binmode: true) do |file|
|
62
|
+
file.print Network.get(url)
|
63
|
+
file
|
64
|
+
end
|
65
|
+
|
66
|
+
raise "Could not download #{url}" unless File.exist?(tempfile.to_path)
|
67
|
+
|
68
|
+
Webdrivers.logger.debug "Successfully downloaded #{tempfile.to_path}"
|
69
|
+
|
70
|
+
decompress_file(tempfile, file_name, target)
|
71
|
+
tempfile.close!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def exists?(file)
|
76
|
+
result = File.exist? file
|
77
|
+
Webdrivers.logger.debug "#{file} is#{' not' unless result} already downloaded"
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
def decompress_file(tempfile, file_name, target)
|
82
|
+
tempfile = tempfile.to_path
|
83
|
+
case tempfile
|
84
|
+
when /tar\.gz$/
|
85
|
+
untargz_file(tempfile, File.basename(target))
|
86
|
+
when /tar\.bz2$/
|
87
|
+
untarbz2_file(tempfile)
|
88
|
+
when /\.zip$/
|
89
|
+
unzip_file(tempfile)
|
90
|
+
else
|
91
|
+
Webdrivers.logger.debug 'No Decompression needed'
|
92
|
+
FileUtils.cp(tempfile, File.join(Dir.pwd, file_name))
|
93
|
+
end
|
94
|
+
raise "Could not decompress #{url} to get #{target}" unless File.exist?(target)
|
95
|
+
end
|
96
|
+
|
97
|
+
def untarbz2_file(filename)
|
98
|
+
Webdrivers.logger.debug "Decompressing #{filename}"
|
99
|
+
|
100
|
+
call("tar xjf #{filename}").gsub('.tar.bz2', '')
|
101
|
+
end
|
102
|
+
|
103
|
+
def untargz_file(source, target)
|
104
|
+
Webdrivers.logger.debug "Decompressing #{source}"
|
105
|
+
|
106
|
+
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source))
|
107
|
+
|
108
|
+
File.open(target, 'w+b') do |ucf|
|
109
|
+
tar_extract.each { |entry| ucf << entry.read }
|
110
|
+
File.basename ucf
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def unzip_file(filename)
|
115
|
+
Webdrivers.logger.debug "Decompressing #{filename}"
|
116
|
+
|
117
|
+
Zip::File.open(filename) do |zip_file|
|
118
|
+
zip_file.each do |f|
|
119
|
+
@top_path ||= f.name
|
120
|
+
f_path = File.join(Dir.pwd, f.name)
|
121
|
+
delete(f_path)
|
122
|
+
FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
|
123
|
+
zip_file.extract(f, f_path)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
@top_path
|
127
|
+
end
|
128
|
+
|
129
|
+
def platform
|
130
|
+
if Selenium::WebDriver::Platform.linux?
|
131
|
+
'linux'
|
132
|
+
elsif Selenium::WebDriver::Platform.mac?
|
133
|
+
'mac'
|
134
|
+
elsif Selenium::WebDriver::Platform.windows?
|
135
|
+
'win'
|
136
|
+
else
|
137
|
+
raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def bitsize
|
142
|
+
Selenium::WebDriver::Platform.bitsize
|
143
|
+
end
|
144
|
+
|
145
|
+
def call(cmd)
|
146
|
+
Webdrivers.logger.debug "making System call: #{cmd}"
|
147
|
+
`#{cmd}`
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,4 +9,10 @@ require 'webdrivers'
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.filter_run_including focus: true unless ENV['CI']
|
11
11
|
config.run_all_when_everything_filtered = true
|
12
|
+
config.expect_with :rspec do |expectations|
|
13
|
+
expectations.syntax = :expect
|
14
|
+
end
|
15
|
+
config.mock_with :rspec do |mocks|
|
16
|
+
mocks.verify_partial_doubles = true
|
17
|
+
end
|
12
18
|
end
|
@@ -5,125 +5,239 @@ require 'spec_helper'
|
|
5
5
|
describe Webdrivers::Chromedriver do
|
6
6
|
let(:chromedriver) { described_class }
|
7
7
|
|
8
|
-
|
9
|
-
chromedriver.
|
8
|
+
before do
|
9
|
+
chromedriver.remove
|
10
|
+
chromedriver.required_version = nil
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
describe '#update' do
|
14
|
+
context 'when evaluating #correct_binary?' do
|
15
|
+
it 'does not download when latest version and current version match' do
|
16
|
+
allow(chromedriver).to receive(:latest_version).and_return(Gem::Version.new('72.0.0'))
|
17
|
+
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0'))
|
15
18
|
|
16
|
-
|
17
|
-
old_version = Gem::Version.new('2.30')
|
18
|
-
future_version = Gem::Version.new('80.00')
|
19
|
-
latest_version = chromedriver.latest_version
|
19
|
+
chromedriver.update
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
21
|
+
expect(chromedriver.send(:exists?)).to be false
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
latest_ver = chromedriver.latest_version.version
|
30
|
-
expect(cur_ver).to eq latest_ver
|
31
|
-
end
|
24
|
+
it 'does not download when offline, binary exists and is less than v70' do
|
25
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
26
|
+
allow(chromedriver).to receive(:exists?).and_return(true)
|
27
|
+
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new(69))
|
32
28
|
|
33
|
-
|
34
|
-
chromedriver.remove
|
35
|
-
chromedriver.version = 2.29
|
36
|
-
chromedriver.download
|
37
|
-
expect(chromedriver.current_version.version).to include '2.29'
|
38
|
-
end
|
29
|
+
chromedriver.update
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
chromedriver.version = '73.0.3683.68'
|
43
|
-
chromedriver.download
|
44
|
-
expect(chromedriver.current_version.version).to eq '73.0.3683.68'
|
45
|
-
end
|
31
|
+
expect(File.exist?(chromedriver.driver_path)).to be false
|
32
|
+
end
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
it 'does not download when offline, binary exists and matches major browser version' do
|
35
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
36
|
+
allow(chromedriver).to receive(:exists?).and_return(true)
|
37
|
+
allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
|
38
|
+
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('73.0.3683.20'))
|
51
39
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
40
|
+
chromedriver.update
|
41
|
+
|
42
|
+
expect(File.exist?(chromedriver.driver_path)).to be false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'raises ConnectionError when offline, and binary does not match major browser version' do
|
46
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
47
|
+
allow(chromedriver).to receive(:exists?).and_return(true)
|
48
|
+
allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
|
49
|
+
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0.0'))
|
50
|
+
|
51
|
+
msg = %r{Can not reach https://chromedriver.storage.googleapis.com}
|
52
|
+
expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'raises ConnectionError when offline, and no binary exists' do
|
56
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
57
|
+
allow(chromedriver).to receive(:exists?).and_return(false)
|
58
|
+
|
59
|
+
msg = %r{Can not reach https://chromedriver.storage.googleapis.com}
|
60
|
+
expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when correct binary is found' do
|
65
|
+
before { allow(chromedriver).to receive(:correct_binary?).and_return(true) }
|
66
|
+
|
67
|
+
it 'does not download' do
|
68
|
+
chromedriver.update
|
69
|
+
|
70
|
+
expect(chromedriver.current_version).to be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not raise exception if offline' do
|
74
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
75
|
+
|
76
|
+
chromedriver.update
|
77
|
+
|
78
|
+
expect(chromedriver.current_version).to be_nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when correct binary is not found' do
|
83
|
+
before { allow(chromedriver).to receive(:correct_binary?).and_return(false) }
|
84
|
+
|
85
|
+
it 'downloads binary' do
|
86
|
+
chromedriver.update
|
87
|
+
|
88
|
+
expect(chromedriver.current_version).not_to be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'raises ConnectionError if offline' do
|
92
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
93
|
+
|
94
|
+
msg = %r{Can not reach https://chromedriver.storage.googleapis.com/}
|
95
|
+
expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'makes a network call if cached driver does not match the browser' do
|
100
|
+
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
|
101
|
+
allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
|
102
|
+
allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
|
103
|
+
allow(Webdrivers::System).to receive(:download)
|
57
104
|
|
58
|
-
allow(chromedriver).to receive(:chrome_version).and_return('70.0.0')
|
59
105
|
chromedriver.update
|
60
106
|
|
61
|
-
expect(
|
107
|
+
expect(Webdrivers::Network).to have_received(:get).twice
|
62
108
|
end
|
63
109
|
end
|
64
110
|
|
65
|
-
|
66
|
-
|
67
|
-
chromedriver.
|
68
|
-
|
69
|
-
chromedriver.
|
111
|
+
describe '#current_version' do
|
112
|
+
it 'returns nil if binary does not exist on the system' do
|
113
|
+
allow(chromedriver).to receive(:driver_path).and_return('')
|
114
|
+
|
115
|
+
expect(chromedriver.current_version).to be_nil
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'returns a Gem::Version instance if binary is on the system' do
|
119
|
+
allow(chromedriver).to receive(:exists?).and_return(true)
|
120
|
+
allow(Webdrivers::System).to receive(:call)
|
121
|
+
.with("#{chromedriver.driver_path} --version")
|
122
|
+
.and_return '71.0.3578.137'
|
123
|
+
|
124
|
+
expect(chromedriver.current_version).to eq Gem::Version.new('71.0.3578.137')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#latest_version' do
|
129
|
+
it 'returns 2.41 if the browser version is less than 70' do
|
130
|
+
allow(chromedriver).to receive(:chrome_version).and_return('69.0.0')
|
131
|
+
|
132
|
+
expect(chromedriver.latest_version).to eq(Gem::Version.new('2.41'))
|
70
133
|
end
|
71
134
|
|
72
|
-
it '
|
135
|
+
it 'returns the correct point release for a production version greater than 70' do
|
136
|
+
allow(chromedriver).to receive(:chrome_version).and_return '71.0.3578.9999'
|
137
|
+
|
138
|
+
expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'raises VersionError for beta version' do
|
73
142
|
allow(chromedriver).to receive(:chrome_version).and_return('100.0.0')
|
74
143
|
msg = 'you appear to be using a non-production version of Chrome; please set '\
|
75
|
-
'`Webdrivers::Chromedriver.
|
144
|
+
'`Webdrivers::Chromedriver.required_version = <desired driver version>` to an known chromedriver version: '\
|
76
145
|
'https://chromedriver.storage.googleapis.com/index.html'
|
77
|
-
|
146
|
+
|
147
|
+
expect { chromedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
|
78
148
|
end
|
79
149
|
|
80
|
-
it 'raises
|
81
|
-
allow(chromedriver).to receive(:chrome_version).and_return('72.0.
|
82
|
-
msg = 'please set `Webdrivers::Chromedriver.
|
83
|
-
'version: https://chromedriver.storage.googleapis.com/index.html'
|
84
|
-
|
150
|
+
it 'raises VersionError for unknown version' do
|
151
|
+
allow(chromedriver).to receive(:chrome_version).and_return('72.0.9999.0000')
|
152
|
+
msg = 'please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
|
153
|
+
'to an known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
|
154
|
+
|
155
|
+
expect { chromedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
|
85
156
|
end
|
86
|
-
end
|
87
157
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
158
|
+
it 'raises ConnectionError when offline' do
|
159
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
|
160
|
+
|
161
|
+
msg = %r{^Can not reach https://chromedriver.storage.googleapis.com}
|
162
|
+
expect { chromedriver.latest_version }.to raise_error(Webdrivers::ConnectionError, msg)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'creates cached file' do
|
166
|
+
allow(Webdrivers::Network).to receive(:get).and_return('71.0.3578.137')
|
167
|
+
|
168
|
+
chromedriver.latest_version
|
169
|
+
expect(File.exist?("#{Webdrivers::System.install_dir}/chromedriver.version")).to eq true
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'does not make network call if cache is valid' do
|
173
|
+
allow(Webdrivers).to receive(:cache_time).and_return(3600)
|
174
|
+
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
|
175
|
+
allow(Webdrivers::Network).to receive(:get)
|
176
|
+
|
177
|
+
expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
|
178
|
+
|
179
|
+
expect(Webdrivers::Network).not_to have_received(:get)
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'makes a network call if cache is expired' do
|
183
|
+
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
|
184
|
+
allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
|
185
|
+
allow(Webdrivers::System).to receive(:valid_cache?)
|
186
|
+
|
187
|
+
expect(chromedriver.latest_version).to eq Gem::Version.new('73.0.3683.68')
|
188
|
+
|
189
|
+
expect(Webdrivers::Network).to have_received(:get)
|
190
|
+
expect(Webdrivers::System).to have_received(:valid_cache?)
|
97
191
|
end
|
98
192
|
end
|
99
193
|
|
100
|
-
|
101
|
-
|
102
|
-
chromedriver.
|
103
|
-
|
194
|
+
describe '#required_version=' do
|
195
|
+
it 'returns the version specified as a Float' do
|
196
|
+
chromedriver.required_version = 73.0
|
197
|
+
|
198
|
+
expect(chromedriver.required_version).to eq Gem::Version.new('73.0')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns the version specified as a String' do
|
202
|
+
chromedriver.required_version = '73.0'
|
203
|
+
|
204
|
+
expect(chromedriver.required_version).to eq Gem::Version.new('73.0')
|
104
205
|
end
|
206
|
+
end
|
105
207
|
|
106
|
-
|
107
|
-
|
208
|
+
describe '#remove' do
|
209
|
+
it 'removes existing chromedriver' do
|
210
|
+
chromedriver.update
|
211
|
+
|
212
|
+
chromedriver.remove
|
213
|
+
expect(chromedriver.current_version).to be_nil
|
108
214
|
end
|
109
215
|
|
110
|
-
it '
|
111
|
-
expect { chromedriver.
|
216
|
+
it 'does not raise exception if no chromedriver found' do
|
217
|
+
expect { chromedriver.remove }.not_to raise_error
|
112
218
|
end
|
113
219
|
end
|
114
220
|
|
115
|
-
|
116
|
-
|
117
|
-
install_dir
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
221
|
+
describe '#install_dir' do
|
222
|
+
it 'uses ~/.webdrivers as default value' do
|
223
|
+
expect(Webdrivers::System.install_dir).to include('.webdriver')
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'uses provided value' do
|
227
|
+
begin
|
228
|
+
install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
|
229
|
+
Webdrivers.install_dir = install_dir
|
230
|
+
|
231
|
+
expect(Webdrivers::System.install_dir).to eq install_dir
|
232
|
+
ensure
|
233
|
+
Webdrivers.install_dir = nil
|
234
|
+
end
|
122
235
|
end
|
123
236
|
end
|
124
237
|
|
125
|
-
|
126
|
-
|
127
|
-
|
238
|
+
describe '#driver_path' do
|
239
|
+
it 'returns full location of binary' do
|
240
|
+
expect(chromedriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/chromedriver")
|
241
|
+
end
|
128
242
|
end
|
129
243
|
end
|