webdrivers 3.9.1 → 3.9.2

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.
@@ -1,18 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require 'simplecov'
4
- SimpleCov.start
5
-
6
- require 'rspec'
7
- require 'webdrivers'
8
-
9
- RSpec.configure do |config|
10
- config.filter_run_including focus: true unless ENV['CI']
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
18
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'rspec'
7
+ require 'webdrivers'
8
+
9
+ RSpec.configure do |config|
10
+ config.filter_run_including focus: true unless ENV['CI']
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
18
+ end
@@ -1,243 +1,257 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Webdrivers::Chromedriver do
6
- let(:chromedriver) { described_class }
7
-
8
- before do
9
- chromedriver.remove
10
- chromedriver.required_version = nil
11
- end
12
-
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'))
18
-
19
- chromedriver.update
20
-
21
- expect(chromedriver.send(:exists?)).to be false
22
- end
23
-
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))
28
-
29
- chromedriver.update
30
-
31
- expect(File.exist?(chromedriver.driver_path)).to be false
32
- end
33
-
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'))
39
-
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)
104
-
105
- chromedriver.update
106
-
107
- expect(Webdrivers::Network).to have_received(:get).twice
108
- end
109
- end
110
-
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'))
133
- end
134
-
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
142
- allow(chromedriver).to receive(:chrome_version).and_return('100.0.0')
143
- msg = 'you appear to be using a non-production version of Chrome; please set '\
144
- '`Webdrivers::Chromedriver.required_version = <desired driver version>` to an known chromedriver version: '\
145
- 'https://chromedriver.storage.googleapis.com/index.html'
146
-
147
- expect { chromedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
148
- end
149
-
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)
156
- end
157
-
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?)
191
- end
192
- end
193
-
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')
205
- end
206
- end
207
-
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
214
- end
215
-
216
- it 'does not raise exception if no chromedriver found' do
217
- expect { chromedriver.remove }.not_to raise_error
218
- end
219
- end
220
-
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
235
- end
236
- end
237
-
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
242
- end
243
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Webdrivers::Chromedriver do
6
+ let(:chromedriver) { described_class }
7
+
8
+ before { chromedriver.remove }
9
+
10
+ describe '#update' do
11
+ context 'when evaluating #correct_binary?' do
12
+ it 'does not download when latest version and current version match' do
13
+ allow(chromedriver).to receive(:latest_version).and_return(Gem::Version.new('72.0.0'))
14
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0'))
15
+
16
+ chromedriver.update
17
+
18
+ expect(chromedriver.send(:exists?)).to be false
19
+ end
20
+
21
+ it 'does not download when offline, binary exists and is less than v70' do
22
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
23
+ allow(chromedriver).to receive(:exists?).and_return(true)
24
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new(69))
25
+
26
+ chromedriver.update
27
+
28
+ expect(File.exist?(chromedriver.driver_path)).to be false
29
+ end
30
+
31
+ it 'does not download when offline, binary exists and matches major browser version' do
32
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
33
+ allow(chromedriver).to receive(:exists?).and_return(true)
34
+ allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
35
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('73.0.3683.20'))
36
+
37
+ chromedriver.update
38
+
39
+ expect(File.exist?(chromedriver.driver_path)).to be false
40
+ end
41
+
42
+ it 'does not download when get raises exception, binary exists and matches major browser version' do
43
+ client_error = instance_double(Net::HTTPNotFound, class: Net::HTTPNotFound, code: 404, message: '')
44
+
45
+ allow(Webdrivers::Network).to receive(:get_response).and_return(client_error)
46
+ allow(chromedriver).to receive(:exists?).and_return(true)
47
+ allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
48
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('73.0.3683.20'))
49
+
50
+ chromedriver.update
51
+
52
+ expect(File.exist?(chromedriver.driver_path)).to be false
53
+ end
54
+
55
+ it 'raises ConnectionError when offline, and binary does not match major browser version' do
56
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
57
+ allow(chromedriver).to receive(:exists?).and_return(true)
58
+ allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
59
+ allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0.0'))
60
+
61
+ msg = %r{Can not reach https://chromedriver.storage.googleapis.com}
62
+ expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
63
+ end
64
+
65
+ it 'raises ConnectionError when offline, and no binary exists' do
66
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
67
+ allow(chromedriver).to receive(:exists?).and_return(false)
68
+
69
+ msg = %r{Can not reach https://chromedriver.storage.googleapis.com}
70
+ expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
71
+ end
72
+ end
73
+
74
+ context 'when correct binary is found' do
75
+ before { allow(chromedriver).to receive(:correct_binary?).and_return(true) }
76
+
77
+ it 'does not download' do
78
+ chromedriver.update
79
+
80
+ expect(chromedriver.current_version).to be_nil
81
+ end
82
+
83
+ it 'does not raise exception if offline' do
84
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
85
+
86
+ chromedriver.update
87
+
88
+ expect(chromedriver.current_version).to be_nil
89
+ end
90
+ end
91
+
92
+ context 'when correct binary is not found' do
93
+ before { allow(chromedriver).to receive(:correct_binary?).and_return(false) }
94
+
95
+ it 'downloads binary' do
96
+ chromedriver.update
97
+
98
+ expect(chromedriver.current_version).not_to be_nil
99
+ end
100
+
101
+ it 'raises ConnectionError if offline' do
102
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
103
+
104
+ msg = %r{Can not reach https://chromedriver.storage.googleapis.com/}
105
+ expect { chromedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
106
+ end
107
+ end
108
+
109
+ it 'makes a network call if cached driver does not match the browser' do
110
+ Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
111
+ allow(chromedriver).to receive(:chrome_version).and_return(Gem::Version.new('73.0.3683.68'))
112
+ allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
113
+ allow(Webdrivers::System).to receive(:download)
114
+
115
+ chromedriver.update
116
+
117
+ expect(Webdrivers::Network).to have_received(:get).twice
118
+ end
119
+ end
120
+
121
+ describe '#current_version' do
122
+ it 'returns nil if binary does not exist on the system' do
123
+ allow(chromedriver).to receive(:driver_path).and_return('')
124
+
125
+ expect(chromedriver.current_version).to be_nil
126
+ end
127
+
128
+ it 'returns a Gem::Version instance if binary is on the system' do
129
+ allow(chromedriver).to receive(:exists?).and_return(true)
130
+ allow(Webdrivers::System).to receive(:call)
131
+ .with("#{chromedriver.driver_path} --version")
132
+ .and_return '71.0.3578.137'
133
+
134
+ expect(chromedriver.current_version).to eq Gem::Version.new('71.0.3578.137')
135
+ end
136
+ end
137
+
138
+ describe '#latest_version' do
139
+ it 'returns 2.41 if the browser version is less than 70' do
140
+ allow(chromedriver).to receive(:chrome_version).and_return('69.0.0')
141
+
142
+ expect(chromedriver.latest_version).to eq(Gem::Version.new('2.41'))
143
+ end
144
+
145
+ it 'returns the correct point release for a production version greater than 70' do
146
+ allow(chromedriver).to receive(:chrome_version).and_return '71.0.3578.9999'
147
+
148
+ expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
149
+ end
150
+
151
+ it 'raises VersionError for beta version' do
152
+ allow(chromedriver).to receive(:chrome_version).and_return('100.0.0')
153
+ msg = 'Unable to find latest point release version for 100.0.0. '\
154
+ 'You appear to be using a non-production version of Chrome. '\
155
+ 'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
156
+ 'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
157
+
158
+ expect { chromedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
159
+ end
160
+
161
+ it 'raises VersionError for unknown version' do
162
+ allow(chromedriver).to receive(:chrome_version).and_return('72.0.9999.0000')
163
+ msg = 'Unable to find latest point release version for 72.0.9999. '\
164
+ 'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
165
+ 'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
166
+
167
+ expect { chromedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
168
+ end
169
+
170
+ it 'raises ConnectionError when offline' do
171
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
172
+
173
+ msg = %r{^Can not reach https://chromedriver.storage.googleapis.com}
174
+ expect { chromedriver.latest_version }.to raise_error(Webdrivers::ConnectionError, msg)
175
+ end
176
+
177
+ it 'creates cached file' do
178
+ allow(Webdrivers::Network).to receive(:get).and_return('71.0.3578.137')
179
+
180
+ chromedriver.latest_version
181
+ expect(File.exist?("#{Webdrivers::System.install_dir}/chromedriver.version")).to eq true
182
+ end
183
+
184
+ it 'does not make network call if cache is valid' do
185
+ allow(Webdrivers).to receive(:cache_time).and_return(3600)
186
+ Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
187
+ allow(Webdrivers::Network).to receive(:get)
188
+
189
+ expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
190
+
191
+ expect(Webdrivers::Network).not_to have_received(:get)
192
+ end
193
+
194
+ it 'makes a network call if cache is expired' do
195
+ Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
196
+ allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
197
+ allow(Webdrivers::System).to receive(:valid_cache?)
198
+
199
+ expect(chromedriver.latest_version).to eq Gem::Version.new('73.0.3683.68')
200
+
201
+ expect(Webdrivers::Network).to have_received(:get)
202
+ expect(Webdrivers::System).to have_received(:valid_cache?)
203
+ end
204
+ end
205
+
206
+ describe '#required_version=' do
207
+ after { chromedriver.required_version = nil }
208
+
209
+ it 'returns the version specified as a Float' do
210
+ chromedriver.required_version = 73.0
211
+
212
+ expect(chromedriver.required_version).to eq Gem::Version.new('73.0')
213
+ end
214
+
215
+ it 'returns the version specified as a String' do
216
+ chromedriver.required_version = '73.0'
217
+
218
+ expect(chromedriver.required_version).to eq Gem::Version.new('73.0')
219
+ end
220
+ end
221
+
222
+ describe '#remove' do
223
+ it 'removes existing chromedriver' do
224
+ chromedriver.update
225
+
226
+ chromedriver.remove
227
+ expect(chromedriver.current_version).to be_nil
228
+ end
229
+
230
+ it 'does not raise exception if no chromedriver found' do
231
+ expect { chromedriver.remove }.not_to raise_error
232
+ end
233
+ end
234
+
235
+ describe '#install_dir' do
236
+ it 'uses ~/.webdrivers as default value' do
237
+ expect(Webdrivers::System.install_dir).to include('.webdriver')
238
+ end
239
+
240
+ it 'uses provided value' do
241
+ begin
242
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
243
+ Webdrivers.install_dir = install_dir
244
+
245
+ expect(Webdrivers::System.install_dir).to eq install_dir
246
+ ensure
247
+ Webdrivers.install_dir = nil
248
+ end
249
+ end
250
+ end
251
+
252
+ describe '#driver_path' do
253
+ it 'returns full location of binary' do
254
+ expect(chromedriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/chromedriver")
255
+ end
256
+ end
257
+ end