watir 6.18.0 → 6.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module Watir
2
+ class HttpClient < Selenium::WebDriver::Remote::Http::Default
3
+ # TODO: Remove for Watir 7; :client_timeout will be marked deprecated in 6.19
4
+ # :open_timeout should have been changed in Selenium a while back, is in 4.beta2
5
+ def initialize(open_timeout: nil, read_timeout: nil, client_timeout: nil)
6
+ read_timeout ||= client_timeout
7
+ open_timeout ||= client_timeout || 60
8
+ super(open_timeout: open_timeout, read_timeout: read_timeout)
9
+ end
10
+
11
+ def request(verb, url, headers, payload, redirects = 0)
12
+ headers['User-Agent'] = "#{headers['User-Agent']} watir/#{Watir::VERSION}"
13
+
14
+ super(verb, url, headers, payload, redirects)
15
+ end
16
+ end
17
+ end
data/lib/watir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = '6.18.0'.freeze
2
+ VERSION = '6.19.0'.freeze
3
3
  end
@@ -20,7 +20,7 @@ module Watir
20
20
 
21
21
  def each(&blk)
22
22
  reset!
23
- to_a.each(&blk)
23
+ window_list.each(&blk)
24
24
  end
25
25
 
26
26
  alias length count
@@ -66,27 +66,36 @@ module Watir
66
66
  reference = 'http://watir.com/window_indexes'
67
67
  Watir.logger.deprecate old, new, reference: reference, ids: [:window_index]
68
68
 
69
- to_a[value]
69
+ window_list[value]
70
70
  end
71
71
 
72
72
  def ==(other)
73
- to_a == other.to_a
73
+ window_list == other.send(:window_list)
74
74
  end
75
75
  alias eql? ==
76
76
 
77
- def to_a
78
- @to_a ||= begin
79
- handles = @browser.driver.window_handles.select { |wh| matches?(wh) }
80
- handles.map { |wh| Window.new(@browser, handle: wh) }
81
- end
77
+ def reset!
78
+ @window_list = nil
82
79
  end
83
80
 
84
- def reset!
85
- @to_a = nil
81
+ def to_a
82
+ old = 'WindowCollection#to_a to interact with indexed windows'
83
+ new = 'Enumerable methods to iterate over windows'
84
+ reference = 'http://watir.com/window_indexes'
85
+ Watir.logger.deprecate old, new, reference: reference, ids: [:window_index]
86
+
87
+ window_list
86
88
  end
87
89
 
88
90
  private
89
91
 
92
+ def window_list
93
+ @window_list ||= begin
94
+ handles = @browser.driver.window_handles.select { |wh| matches?(wh) }
95
+ handles.map { |wh| Window.new(@browser, handle: wh) }
96
+ end
97
+ end
98
+
90
99
  # NOTE: This is the exact same code from `Window#matches?`
91
100
  # TODO: Move this code into a separate WindowLocator class
92
101
  def matches?(handle)
@@ -45,7 +45,7 @@ module WatirSpec
45
45
  config.include(MessagesHelper)
46
46
 
47
47
  config.before(:suite) { $browser = WatirSpec.new_browser }
48
- config.after(:suite) { $browser.close }
48
+ config.after(:suite) { $browser&.close }
49
49
  end
50
50
  end
51
51
 
@@ -1,27 +1,1243 @@
1
- require_relative 'unit_helper'
1
+ require 'watirspec_helper'
2
2
 
3
3
  describe Watir::Capabilities do
4
- describe '#ie' do
5
- it 'processes options' do
6
- options = {browser_attach_timeout: 1, full_page_screenshot: true}
7
- caps = Watir::Capabilities.new(:ie, options: options)
8
- opts = caps.to_args.last[:options]
9
- expect(opts.browser_attach_timeout).to eq 1
10
- expect(opts.full_page_screenshot).to be true
4
+ before do
5
+ compliant_on :v6_18 do
6
+ ENV['IGNORE_DEPRECATIONS'] = 'true'
11
7
  end
8
+ end
12
9
 
13
- it 'processes args' do
14
- caps = Watir::Capabilities.new(:ie, args: %w[foo bar])
15
- opts = caps.to_args.last[:options]
16
- expect(opts.args).to eq Set.new(%w[foo bar])
10
+ before do
11
+ compliant_on :v6_18 do
12
+ ENV['IGNORE_DEPRECATIONS'] = 'true'
13
+ end
14
+ end
15
+
16
+ after(:all) { ENV['IGNORE_DEPRECATIONS'] = nil }
17
+
18
+ def expected_browser(browser)
19
+ case browser
20
+ when :ie
21
+ 'internet explorer'
22
+ when :edge
23
+ 'MicrosoftEdge'
24
+ else
25
+ browser.to_s
26
+ end
27
+ end
28
+
29
+ def service_class(browser)
30
+ Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Service")
31
+ end
32
+
33
+ def options_class(browser)
34
+ Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Options")
35
+ end
36
+
37
+ def expected_browser_class(browser)
38
+ browser == :ie ? 'IE' : browser.capitalize
39
+ end
40
+
41
+ def halt_service(browser)
42
+ allow(Selenium::WebDriver::Platform).to receive(:find_binary).and_return(true)
43
+ allow(File).to receive(:file?).and_return(true)
44
+ allow(File).to receive(:executable?).and_return(true)
45
+ service_class(browser).driver_path = nil
46
+ end
47
+
48
+ def default_client
49
+ compliant_on :v6_18 do
50
+ return Selenium::WebDriver::Remote::Http::Default
51
+ end
52
+ Watir::HttpClient
53
+ end
54
+
55
+ def capabilities_key
56
+ compliant_on :v6_18 do
57
+ return :desired_capabilities
58
+ end
59
+ :capabilities
60
+ end
61
+
62
+ supported_browsers = %i[chrome firefox ie safari]
63
+
64
+ not_compliant_on :v6_18, :v6_19 do
65
+ supported_browsers << :edge
66
+ end
67
+
68
+ # Options:
69
+ # :listener
70
+ # :service (Built from Hash)
71
+ # :http_client (Generated or Built from Hash)
72
+ # :options (Generated or Built from Hash)
73
+ # :capabilities (incompatible with options)
74
+
75
+ supported_browsers.each do |browser_symbol|
76
+ # 6.18 works except for safari
77
+ # 6.19 fix safari
78
+ # 7.0 remove Capabilities requirement
79
+ it 'just browser has client, options & capabilities but not service' do
80
+ compliant_on :v6_18 do
81
+ skip if browser_symbol == :safari # No extra processing needed
82
+ end
83
+ capabilities = Watir::Capabilities.new(browser_symbol)
84
+
85
+ args = capabilities.to_args
86
+ expect(args.last[:http_client]).to be_a default_client
87
+ expect(args.last[:options]).to be_a options_class(browser_symbol)
88
+ expect(args.last[:desired_capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
89
+ expect(args.last).not_to include(:service)
90
+ end
91
+
92
+ # 6.18 never implemented
93
+ # 6.19 implement
94
+ # 7.0 valid
95
+ not_compliant_on :v6_18 do
96
+ it 'just options has client, options & capabilities but not service' do
97
+ capabilities = Watir::Capabilities.new(options: options_class(browser_symbol).new)
98
+
99
+ args = capabilities.to_args
100
+
101
+ expect(args.last[:http_client]).to be_a default_client
102
+ expect(args.last[:options]).to be_a options_class(browser_symbol)
103
+ expect(args.last[:desired_capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
104
+ expect(args.last[:desired_capabilities].browser_name).to eq expected_browser(browser_symbol)
105
+ expect(args.last).not_to include(:service)
106
+ end
107
+ end
108
+
109
+ # 6.18 never implemented
110
+ # 6.19 implement
111
+ # 7.0 valid
112
+ not_compliant_on :v6_18 do
113
+ it 'just capabilities has client, options & capabilities but not service' do
114
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
115
+ capabilities = Watir::Capabilities.new(capabilities_key => caps)
116
+
117
+ args = capabilities.to_args
118
+
119
+ expect(args.last[:http_client]).to be_a default_client
120
+ expect(args.last[:options]).to be_a options_class(browser_symbol)
121
+ expect(args.last[:desired_capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
122
+ expect(args.last[:desired_capabilities].browser_name).to eq expected_browser(browser_symbol)
123
+ expect(args.last).not_to include(:service)
124
+ end
125
+ end
126
+
127
+ # 6.18 works
128
+ # 6.19 deprecate :desired_capabilities
129
+ # 7.0 raise exception
130
+ it 'desired_capabilities works but deprecated' do
131
+ expect {
132
+ desired_capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
133
+ capabilities = Watir::Capabilities.new(browser_symbol,
134
+ desired_capabilities: desired_capabilities)
135
+ args = capabilities.to_args
136
+ expect(args.first).to eq browser_symbol
137
+ desired_capabilities = args.last[:desired_capabilities]
138
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
139
+ expect(desired_capabilities.browser_name).to eq expected_browser(browser_symbol)
140
+ }.to have_deprecated_desired_capabilities
141
+ end
142
+
143
+ # 6.18 broken; puts service in desired capabilities so of course not there
144
+ # 6.19 fix with deprecation
145
+ # 7.0 raise exception
146
+ it 'service not allowed when url specified' do
147
+ halt_service(browser_symbol)
148
+
149
+ expect {
150
+ capabilities = Watir::Capabilities.new(browser_symbol,
151
+ url: 'http://example.com',
152
+ service: service_class(browser_symbol).new)
153
+ args = capabilities.to_args
154
+ expect(args.first).to eq :remote
155
+ expect(args.last).not_to include(:service)
156
+ }.to have_deprecated_url_service
157
+ end
158
+
159
+ context 'service' do
160
+ # 6.18 never implemented
161
+ # 6.19 implement
162
+ # 7.0 valid
163
+ it 'uses provided service' do
164
+ halt_service(browser_symbol)
165
+
166
+ service = service_class(browser_symbol).new(port: 1234)
167
+ capabilities = Watir::Capabilities.new(browser_symbol, service: service)
168
+ args = capabilities.to_args
169
+ expect(args.first).to eq browser_symbol
170
+ actual_service = args.last[:service]
171
+ expect(actual_service.instance_variable_get('@port')).to eq 1234
172
+ end
173
+
174
+ # 6.18 never implemented
175
+ # 6.19 implement!
176
+ # 7.0 valid
177
+ not_compliant_on :v6_18 do
178
+ it 'builds service from a Hash' do
179
+ halt_service(browser_symbol)
180
+
181
+ service = {port: 1234, path: '/path/to/driver', args: %w[--foo --bar]}
182
+ capabilities = Watir::Capabilities.new(browser_symbol, service: service)
183
+ args = capabilities.to_args
184
+ expect(args.first).to eq browser_symbol
185
+ actual_service = args.last[:service]
186
+ expect(actual_service.instance_variable_get('@port')).to eq 1234
187
+ expect(actual_service.instance_variable_get('@executable_path')).to eq '/path/to/driver'
188
+ expect(actual_service.instance_variable_get('@extra_args')).to include '--foo', '--bar'
189
+ end
190
+
191
+ it 'is a bad argument to service' do
192
+ capabilities = Watir::Capabilities.new(browser_symbol, service: 7)
193
+
194
+ expect { capabilities.to_args }.to raise_exception(TypeError)
195
+ end
196
+ end
197
+
198
+ # 6.18 broken: puts it in desired capabilities (neither ":path" nor ":driver_path" work)
199
+ # 6.19 do nothing
200
+ # 7.0 remove
201
+ xit 'creates when :path specified' do
202
+ halt_service(browser_symbol)
203
+ capabilities = Watir::Capabilities.new(browser_symbol, path: '/path/to/driver')
204
+
205
+ args = capabilities.to_args
206
+ expect(args.last[:path]).to eq '/path/to/driver'
207
+ end
208
+
209
+ # 6.18 works - puts them at top level in selenium opts, which Selenium 3 can read
210
+ # 6.19 deprecate - put inside :service keyword
211
+ # 7.0 remove
212
+ it 'creates when service port specified' do
213
+ halt_service(browser_symbol)
214
+
215
+ expect {
216
+ capabilities = Watir::Capabilities.new(browser_symbol,
217
+ port: 1234)
218
+ @args = capabilities.to_args
219
+ }.to have_deprecated_port_keyword
220
+
221
+ compliant_on :v6_18 do
222
+ expect(@args.last[:port]).to eq 1234
223
+ end
224
+
225
+ not_compliant_on :v6_18 do
226
+ expect(@args.last[:service].instance_variable_get('@port')).to eq 1234
227
+ end
228
+ end
17
229
  end
18
230
 
19
- it 'processes options class' do
20
- options = Selenium::WebDriver::IE::Options.new(browser_attach_timeout: 1, full_page_screenshot: true)
21
- caps = Watir::Capabilities.new(:ie, options: options)
22
- opts = caps.to_args.last[:options]
23
- expect(opts.browser_attach_timeout).to eq 1
24
- expect(opts.full_page_screenshot).to be true
231
+ context 'http_client' do
232
+ # 6.18 works
233
+ # 6.19 update to Watir::HttpClient
234
+ # 7.0 valid
235
+ it 'uses default HTTP Client' do
236
+ capabilities = Watir::Capabilities.new(browser_symbol)
237
+ args = capabilities.to_args
238
+ expect(args.last[:http_client]).to be_a default_client
239
+ end
240
+
241
+ # 6.18 works
242
+ # 6.19 do nothing
243
+ # 7.0 valid
244
+ it 'accepts an HTTP Client object' do
245
+ client = Selenium::WebDriver::Remote::Http::Default.new
246
+ capabilities = Watir::Capabilities.new(browser_symbol, http_client: client)
247
+ args = capabilities.to_args
248
+ expect(args.last[:http_client]).to eq client
249
+ end
250
+
251
+ # 6.18 Not implemented
252
+ # 6.19 implement!
253
+ # 7.0 valid
254
+ not_compliant_on :v6_18 do
255
+ it 'builds an HTTP Client from Hash' do
256
+ client_opts = {open_timeout: 10, read_timeout: 10}
257
+ capabilities = Watir::Capabilities.new(browser_symbol, http_client: client_opts)
258
+ args = capabilities.to_args
259
+ actual_client = args.last[:http_client]
260
+ expect(actual_client).to be_a default_client
261
+ expect(actual_client.instance_variable_get('@read_timeout')).to eq 10
262
+ expect(actual_client.instance_variable_get('@open_timeout')).to eq 10
263
+ end
264
+ end
265
+
266
+ # 6.18 Not implemented
267
+ # 6.19 implement!
268
+ # 7.0 valid
269
+ not_compliant_on :v6_18 do
270
+ it 'raises an exception if :client receives something other than Hash or Client object' do
271
+ expect {
272
+ Watir::Capabilities.new(browser_symbol, http_client: 7).to_args
273
+ }.to raise_exception(TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance')
274
+ end
275
+ end
276
+
277
+ # 6.18 works
278
+ # 6.19 deprecate --> client_timeout isn't a thing any more
279
+ # 7.0 remove
280
+ it 'builds a client from client_timeout' do
281
+ expect {
282
+ opt = {client_timeout: 10}
283
+ capabilities = Watir::Capabilities.new(browser_symbol, opt)
284
+ args = capabilities.to_args
285
+ actual_client = args.last[:http_client]
286
+ expect(actual_client).to be_a default_client
287
+ expect(actual_client.instance_variable_get('@read_timeout')).to eq 10
288
+ expect(actual_client.instance_variable_get('@open_timeout')).to eq 10
289
+ }.to have_deprecated_http_client_timeout
290
+ end
291
+
292
+ # 6.18 works
293
+ # 6.19 deprecate --> timeouts inside http_client key
294
+ # 7.0 remove
295
+ %i[open_timeout read_timeout].each do |timeout|
296
+ it "builds a client from #{timeout}" do
297
+ expect {
298
+ opt = {timeout => 10}
299
+
300
+ capabilities = Watir::Capabilities.new(browser_symbol, opt)
301
+ args = capabilities.to_args
302
+ actual_client = args.last[:http_client]
303
+ expect(actual_client).to be_a default_client
304
+ expect(actual_client.instance_variable_get("@#{timeout}")).to eq 10
305
+ }.to send("have_deprecated_http_#{timeout}")
306
+ end
307
+ end
308
+ end
309
+
310
+ # 6.18 works
311
+ # 6.19 do nothing
312
+ # 7.0 valid
313
+ it 'uses a listener' do
314
+ listener = Selenium::WebDriver::Support::AbstractEventListener.new
315
+ capabilities = Watir::Capabilities.new(browser_symbol, listener: listener)
316
+ args = capabilities.to_args
317
+ expect(args.last[:listener]).to eq listener
318
+ end
319
+
320
+ # 6.18 works
321
+ # 6.19 warn
322
+ # 7.0 Raise Exception
323
+ it 'accepts both capabilities and Options' do
324
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
325
+ opts = options_class(browser_symbol).new
326
+
327
+ expect {
328
+ @capabilities = Watir::Capabilities.new(browser_symbol,
329
+ capabilities_key => caps,
330
+ options: opts)
331
+ }.to have_deprecated_options_capabilities
332
+
333
+ args = @capabilities.to_args
334
+ expect(args.last[:desired_capabilities]).to eq caps
335
+
336
+ # Safari never implemented to accept options
337
+ if browser_symbol == :safari
338
+ not_compliant_on :v6_18 do
339
+ expect(args.last[:options]).to eq opts
340
+ end
341
+ end
342
+ end
343
+
344
+ # 6.18 works
345
+ # 6.19 deprecate --> put in options
346
+ # 7.0 remove
347
+ context 'extra things' do
348
+ it 'puts in capabilities when capabilities not specified' do
349
+ expect {
350
+ capabilities = Watir::Capabilities.new(browser_symbol, foo: 'bar')
351
+ args = capabilities.to_args
352
+ expect(args.last[:desired_capabilities][:foo]).to eq 'bar'
353
+ }.to have_deprecated_unknown_keyword
354
+ end
355
+
356
+ # 6.18 works
357
+ # 6.19 deprecate --> put in options
358
+ # 7.0 remove
359
+ it 'puts in top level when Capabilities specified' do
360
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
361
+ capabilities = Watir::Capabilities.new(browser_symbol,
362
+ capabilities_key => caps,
363
+ foo: 'bar')
364
+ expect {
365
+ expect(capabilities.to_args.last[:foo]).to eq 'bar'
366
+ }.to have_deprecated_unknown_keyword
367
+ end
368
+
369
+ # 6.18 works
370
+ # 6.19 deprecate --> put in options
371
+ # 7.0 remove
372
+ it 'puts in top level when Options specified' do
373
+ expect {
374
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
375
+ capabilities = Watir::Capabilities.new(browser_symbol,
376
+ capabilities_key => caps,
377
+ options: options_class(browser_symbol).new,
378
+ foo: 'bar')
379
+ args = capabilities.to_args
380
+ expect(args.last[:foo]).to eq 'bar'
381
+ }.to have_deprecated_unknown_keyword
382
+ end
383
+ end
384
+ end
385
+
386
+ # Options:
387
+ # :url (Required)
388
+ # :service (Errors)
389
+ # :listener
390
+ # :http_client (Generated or Built from Hash)
391
+ # :options (Generated or Built from Hash)
392
+ # :capabilities (incompatible with options)
393
+
394
+ describe 'Remote execution' do
395
+ # 6.18 Was not implemented
396
+ # 6.19 Implement
397
+ # 7.0 Valid
398
+ not_compliant_on :v6_18 do
399
+ it 'with just url' do
400
+ capabilities = Watir::Capabilities.new(url: 'http://example.com')
401
+ args = capabilities.to_args
402
+ expect(args.first).to eq :remote
403
+ desired_capabilities = args.last[:desired_capabilities]
404
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
405
+ expect(desired_capabilities.browser_name).to eq 'chrome'
406
+ end
407
+ end
408
+
409
+ # 6.18 does not work
410
+ # 6.19 do nothing
411
+ # 7.0 remove
412
+ xit ':remote keyword with url has options, chrome and client but not service' do
413
+ capabilities = Watir::Capabilities.new(:remote,
414
+ url: 'https://example.com/wd/hub/')
415
+ args = capabilities.to_args
416
+ expect(args.first).to eq :remote
417
+ expect(args.last[:url]).to eq 'https://example.com/wd/hub'
418
+ expect(args.last[:http_client]).to be_a default_client
419
+ expect(args.last[:options]).to be_a Selenium::WebDriver::Chrome::Options
420
+ desired_capabilities = args.last[:desired_capabilities]
421
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
422
+ expect(desired_capabilities.browser_name).to eq 'chrome'
423
+ expect(args.last).not_to include(:service)
424
+ end
425
+
426
+ # 6.18 works
427
+ # 6.19 this should use options instead of capabilities
428
+ # 7.0 valid
429
+ it 'browser name with url has capabilities and client but not service' do
430
+ capabilities = Watir::Capabilities.new(:firefox,
431
+ url: 'https://example.com/wd/hub/')
432
+ args = capabilities.to_args
433
+ expect(args.first).to eq :remote
434
+ expect(args.last[:url]).to eq 'https://example.com/wd/hub/'
435
+ expect(args.last[:http_client]).to be_a default_client
436
+
437
+ not_compliant_on :v6_18 do
438
+ expect(args.last[:options]).to be_a Selenium::WebDriver::Firefox::Options
439
+ end
440
+
441
+ not_compliant_on :v6_19 do
442
+ desired_capabilities = args.last[:desired_capabilities]
443
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
444
+ expect(desired_capabilities.browser_name).to eq 'firefox'
445
+ end
446
+
447
+ expect(args.last).not_to include(:service)
448
+ end
449
+
450
+ # 6.18 works
451
+ # 6.19 deprecate :remote_keyword
452
+ # 7.0 remove
453
+ it 'remote keyword with url and browser name' do
454
+ expect {
455
+ capabilities = Watir::Capabilities.new(:remote,
456
+ {browser: :firefox,
457
+ url: 'https://example.com'})
458
+ args = capabilities.to_args
459
+ expect(args.first).to eq :remote
460
+ desired_capabilities = args.last[:desired_capabilities]
461
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
462
+ expect(desired_capabilities.browser_name).to eq 'firefox'
463
+ }.to have_deprecated_remote_keyword
464
+ end
465
+
466
+ # 6.18 not implemented
467
+ # 6.19 do nothing
468
+ # 7.0 remove
469
+ xit 'remote keyword errors when given a service' do
470
+ capabilities = Watir::Capabilities.new(:remote,
471
+ url: 'http://example.com',
472
+ service: Selenium::WebDriver::Chrome::Service.new)
473
+
474
+ capabilities.to_args
475
+ end
476
+
477
+ # 6.18 not implemented; just ignores them
478
+ # 6.19 throw error
479
+ # 7.0 throw error
480
+ not_compliant_on :v6_18 do
481
+ it 'browser name errors when given a service' do
482
+ expect {
483
+ Watir::Capabilities.new(:chrome,
484
+ url: 'http://example.com',
485
+ service: Selenium::WebDriver::Chrome::Service.new)
486
+ }.to have_deprecated_url_service
487
+ end
488
+ end
489
+
490
+ # 6.18 works
491
+ # 6.19 nothing
492
+ # 7.0 valid
493
+ it 'accepts a listener' do
494
+ listener = Selenium::WebDriver::Support::AbstractEventListener.new
495
+ capabilities = Watir::Capabilities.new(:chrome,
496
+ url: 'http://example.com/wd/hub/',
497
+ listener: listener)
498
+ args = capabilities.to_args
499
+ expect(args.last[:listener]).to eq listener
500
+ end
501
+
502
+ # 6.18 not implemented (should have defaulted to chrome)
503
+ # 6.19 do nothing; it never worked
504
+ # 7.0 remove
505
+ xit 'remote keyword with url and http client object' do
506
+ client = default_client.new
507
+ capabilities = Watir::Capabilities.new(:remote,
508
+ url: 'https://example.com/wd/hub',
509
+ http_client: client)
510
+ args = capabilities.to_args
511
+ expect(args.first).to eq :remote
512
+ expect(args.last[:http_client]).to eq client
513
+ desired_capabilities = args.last[:desired_capabilities]
514
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
515
+ expect(desired_capabilities.browser_name).to eq 'chrome'
516
+ end
517
+
518
+ # 6.18 works
519
+ # 6.19 nothing
520
+ # 7.0 valid
521
+ it 'browser name with url and http client object' do
522
+ client = default_client.new
523
+ capabilities = Watir::Capabilities.new(:chrome,
524
+ url: 'https://example.com/wd/hub',
525
+ http_client: client)
526
+ args = capabilities.to_args
527
+ expect(args.first).to eq :remote
528
+ expect(args.last[:http_client]).to eq client
529
+ desired_capabilities = args.last[:desired_capabilities]
530
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
531
+ expect(desired_capabilities.browser_name).to eq 'chrome'
532
+ end
533
+
534
+ # 6.18 not implemented (should have defaulted to chrome)
535
+ # 6.19 do nothing; never worked
536
+ # 7.0 remove
537
+ xit 'remote keyword with url and http client Hash' do
538
+ capabilities = Watir::Capabilities.new(:remote,
539
+ url: 'https://example.com/wd/hub',
540
+ client: {read_timeout: 30})
541
+ args = capabilities.to_args
542
+ expect(args.first).to eq :remote
543
+ expect(args.last[:http_client].instance_variable_get('@read_timeout')).to eq 30
544
+ desired_capabilities = args.last[:desired_capabilities]
545
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
546
+ expect(desired_capabilities.browser_name).to eq 'chrome'
547
+ end
548
+
549
+ # 6.18 not implemented - does not build from Hash
550
+ # 6.19 build from hash
551
+ # 7.0 valid
552
+ not_compliant_on :v6_18 do
553
+ it 'browser name with url and http client Hash' do
554
+ capabilities = Watir::Capabilities.new(:chrome,
555
+ url: 'https://example.com/wd/hub',
556
+ http_client: {read_timeout: 30})
557
+ args = capabilities.to_args
558
+ expect(args.first).to eq :remote
559
+ expect(args.last[:http_client].instance_variable_get('@read_timeout')).to eq 30
560
+ desired_capabilities = args.last[:desired_capabilities]
561
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
562
+ expect(desired_capabilities.browser_name).to eq 'chrome'
563
+ end
564
+ end
565
+
566
+ # 6.18 Broken
567
+ # 6.19 do nothing; never worked
568
+ # 7.0 remove
569
+ xit 'remote keyword with url and options object' do
570
+ capabilities = Watir::Capabilities.new(:remote,
571
+ url: 'https://example.com/wd/hub',
572
+ options: Selenium::WebDriver::Chrome::Options.new)
573
+ args = capabilities.to_args
574
+ expect(args.first).to eq :remote
575
+ desired_capabilities = args.last[:desired_capabilities]
576
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
577
+ expect(desired_capabilities.browser_name).to eq 'chrome'
578
+ end
579
+
580
+ # 6.18 broken; options eaten
581
+ # 6.19 fix
582
+ # 7.0 valid
583
+ not_compliant_on :v6_18 do
584
+ it 'browser name with url and options object' do
585
+ opts = {args: ['--foo']}
586
+ capabilities = Watir::Capabilities.new(:chrome,
587
+ url: 'https://example.com/wd/hub',
588
+ options: Selenium::WebDriver::Chrome::Options.new(opts))
589
+ args = capabilities.to_args
590
+ expect(args.first).to eq :remote
591
+ desired_capabilities = args.last[:desired_capabilities]
592
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
593
+ expect(desired_capabilities.browser_name).to eq 'chrome'
594
+ options = args.last[:options]
595
+ expect(options.args).to include('--foo')
596
+ end
597
+ end
598
+
599
+ # 6.18 not implemented - can't figure out options
600
+ # 6.19 do nothing; never worked
601
+ # 7.0 remove
602
+ xit 'remote keyword with url and options hash' do
603
+ capabilities = Watir::Capabilities.new(:remote,
604
+ url: 'http://example.com',
605
+ options: {prefs: {foo: 'bar'}})
606
+ args = capabilities.to_args
607
+ expect(args.first).to eq :remote
608
+ expect(args.last[:url]).to eq 'http://example.com'
609
+ options = args.last[:options]
610
+ expect(options).to be_a(Selenium::WebDriver::Chrome::Options)
611
+ end
612
+
613
+ # 6.18 does not work; options got dropped
614
+ # 6.19 fix
615
+ # 7.0 valid
616
+ not_compliant_on :v6_18 do
617
+ it 'browser name with url and options hash' do
618
+ options = {prefs: {foo: 'bar'}}
619
+ capabilities = Watir::Capabilities.new(:chrome,
620
+ url: 'http://example.com',
621
+ options: options)
622
+ args = capabilities.to_args
623
+ expect(args.first).to eq :remote
624
+ expect(args.last[:url]).to eq 'http://example.com'
625
+ actual_options = args.last[:options]
626
+ expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
627
+ expect(actual_options.prefs).to eq(foo: 'bar')
628
+ end
629
+ end
630
+
631
+ # 6.18 works
632
+ # 6.19 deprecate :remote_keyword
633
+ # 7.0 remove
634
+ it 'remote keyword with url and capabilities' do
635
+ expect {
636
+ caps = Watir::Capabilities.new(:remote,
637
+ url: 'https://example.com/wd/hub',
638
+ capabilities_key => Selenium::WebDriver::Remote::Capabilities.chrome)
639
+ args = caps.to_args
640
+ expect(args.first).to eq :remote
641
+ desired_capabilities = args.last[:desired_capabilities]
642
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
643
+ expect(desired_capabilities.browser_name).to eq 'chrome'
644
+ }.to have_deprecated_remote_keyword # (and desired_capabilities)
645
+ end
646
+
647
+ # 6.18 works
648
+ # 6.19 nothing
649
+ # 7.0 valid
650
+ it 'browser name with url and capabilities' do
651
+ caps = Watir::Capabilities.new(:chrome,
652
+ url: 'https://example.com/wd/hub',
653
+ capabilities_key => Selenium::WebDriver::Remote::Capabilities.chrome)
654
+ args = caps.to_args
655
+ expect(args.first).to eq :remote
656
+ desired_capabilities = args.last[:desired_capabilities]
657
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
658
+ expect(desired_capabilities.browser_name).to eq 'chrome'
659
+ end
660
+
661
+ # 6.18 works
662
+ # 6.19 deprecate :remote_keyword
663
+ # 7.0 remove
664
+ it 'remote keyword with http client & capabilities' do
665
+ expect {
666
+ client = default_client.new
667
+ caps = Watir::Capabilities.new(:remote,
668
+ url: 'https://example.com/wd/hub',
669
+ capabilities_key => Selenium::WebDriver::Remote::Capabilities.chrome,
670
+ http_client: client)
671
+
672
+ args = caps.to_args
673
+ expect(args.first).to eq :remote
674
+ expect(args.last[:http_client]).to eq client
675
+ desired_capabilities = args.last[:desired_capabilities]
676
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
677
+ expect(desired_capabilities.browser_name).to eq 'chrome'
678
+ }.to have_deprecated_remote_keyword # (and desired_capabilities)
679
+ end
680
+
681
+ # 6.18 works
682
+ # 6.19 nothing
683
+ # 7.0 valid
684
+ it 'browser name with http client & capabilities' do
685
+ client = default_client.new
686
+ caps = Watir::Capabilities.new(:chrome,
687
+ url: 'https://example.com/wd/hub',
688
+ capabilities_key => Selenium::WebDriver::Remote::Capabilities.chrome,
689
+ http_client: client)
690
+
691
+ args = caps.to_args
692
+ expect(args.first).to eq :remote
693
+ expect(args.last[:http_client]).to eq client
694
+ desired_capabilities = args.last[:desired_capabilities]
695
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
696
+ expect(desired_capabilities.browser_name).to eq 'chrome'
697
+ end
698
+
699
+ # 6.18 broken; options is eaten
700
+ # 6.19 fix
701
+ # 7.0 valid
702
+ not_compliant_on :v6_18 do
703
+ it 'browser name with http client & options object' do
704
+ client = default_client.new
705
+ opts = {prefs: {foo: 'bar'}}
706
+ options = Selenium::WebDriver::Chrome::Options.new(opts)
707
+ caps = Watir::Capabilities.new(:chrome,
708
+ url: 'https://example.com/wd/hub',
709
+ options: options,
710
+ http_client: client)
711
+
712
+ args = caps.to_args
713
+ expect(args.first).to eq :remote
714
+ expect(args.last[:http_client]).to eq client
715
+ actual_options = args.last[:options]
716
+ expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
717
+ expect(actual_options.prefs).to eq(foo: 'bar')
718
+ end
719
+ end
720
+
721
+ # 6.18 broken; options is eaten
722
+ # 6.19 do nothing
723
+ # 7.0 raise exception
724
+ not_compliant_on :v6_18 do
725
+ it 'browser name with options & capabilities' do
726
+ options = {prefs: {foo: 'bar'}}
727
+
728
+ expect {
729
+ @caps = Watir::Capabilities.new(:chrome,
730
+ url: 'https://example.com/wd/hub',
731
+ capabilities_key => Selenium::WebDriver::Remote::Capabilities.chrome,
732
+ options: options)
733
+ }.to have_deprecated_options_capabilities
734
+
735
+ args = @caps.to_args
736
+ expect(args.first).to eq :remote
737
+ desired_capabilities = args.last[:desired_capabilities]
738
+ expect(desired_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
739
+ expect(desired_capabilities.browser_name).to eq 'chrome'
740
+ actual_options = args.last[:options]
741
+ expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
742
+ expect(actual_options.prefs).to eq(foo: 'bar')
743
+ end
744
+ end
745
+
746
+ # 6.18 broken - Selenium doesn't support "chromeOptions" in Capabilities. Did it even at one point?
747
+ # 6.19 fix! allow to stay in top level
748
+ # 7.0 valid
749
+ not_compliant_on :v6_18 do
750
+ it 'allows headless to be set in chrome' do
751
+ capabilities = Watir::Capabilities.new(:chrome,
752
+ headless: true,
753
+ url: 'http://example.com')
754
+ args = capabilities.to_args
755
+ actual_options = args.last[:options]
756
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
757
+ end
758
+ end
759
+
760
+ # 6.18 works - Putting it straight into Desired Capabilities. Bold move Watir 6.6. Bold move.
761
+ # 6.19 keep, but do this with Options instead of capabilities
762
+ # 7.0 valid
763
+ it 'allows headless to be set in firefox' do
764
+ capabilities = Watir::Capabilities.new(:firefox,
765
+ headless: true,
766
+ url: 'http://example.com')
767
+ args = capabilities.to_args
768
+
769
+ compliant_on :v6_18 do
770
+ actual_capabilities = args.last[:desired_capabilities]
771
+ expect(actual_capabilities['moz:firefoxOptions']['args']).to include '--headless'
772
+ end
773
+
774
+ not_compliant_on :v6_18 do
775
+ expect(args.last[:options].args).to include '--headless'
776
+ end
777
+ end
778
+
779
+ # 6.18 works - Putting it into desired capabilities
780
+ # 6.19 deprecate this, it should go under options
781
+ # 7.0 remove
782
+ it 'allows sending to Browser Service Provider top level' do
783
+ expect {
784
+ capabilities = Watir::Capabilities.new(:chrome,
785
+ 'sauce:options' => {username: ENV['SAUCE_USERNAME'],
786
+ access_key: ENV['SAUCE_ACCESS_KEY']},
787
+ url: 'https://ondemand.us-west-1.saucelabs.com')
788
+ args = capabilities.to_args
789
+ actual_capabilities = args.last[:desired_capabilities]
790
+ expect(actual_capabilities['sauce:options'].keys).to include :username, :access_key
791
+ }.to have_deprecated_unknown_keyword
792
+ end
793
+
794
+ # 6.18 broken; options class eats it
795
+ # 6.19 Fix it
796
+ # 7.0 valid
797
+ it 'allows sending to Browser Service Provider via options' do
798
+ not_compliant_on :v6_18 do
799
+ capabilities = Watir::Capabilities.new(:chrome,
800
+ options: {'sauce:options' => {username: ENV['SAUCE_USERNAME'],
801
+ access_key: ENV['SAUCE_ACCESS_KEY']}},
802
+ url: 'https://ondemand.us-west-1.saucelabs.com')
803
+ args = capabilities.to_args
804
+ actual_capabilities = args.last[:desired_capabilities]
805
+ expect(actual_capabilities['sauce:options']&.keys).to include :username, :access_key
806
+ end
807
+ end
808
+ end
809
+
810
+ describe 'chrome' do
811
+ # 6.18 never implemented
812
+ # 6.19 implement
813
+ # 7.0 valid
814
+ not_compliant_on :v6_18 do
815
+ it 'by default uses chrome, has client, options & capabilities' do
816
+ capabilities = Watir::Capabilities.new
817
+ args = capabilities.to_args
818
+ expect(args.last[:http_client]).to be_a default_client
819
+ expect(args.last[:options]).to be_a Selenium::WebDriver::Chrome::Options
820
+ expect(args.last[:desired_capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
821
+ expect(args.last).not_to include(:service)
822
+ end
823
+ end
824
+
825
+ # 6.18 works - puts them at top level in selenium opts, which Selenium 3 can read
826
+ # 6.19 deprecate - put inside :service keyword
827
+ # 7.0 remove
828
+ it 'creates when service driver opts specified' do
829
+ halt_service(:chrome)
830
+
831
+ expect {
832
+ capabilities = Watir::Capabilities.new(:chrome,
833
+ driver_opts: {verbose: true})
834
+ @args = capabilities.to_args
835
+ }.to have_deprecated_driver_opts_keyword
836
+
837
+ compliant_on :v6_18 do
838
+ expect(@args.last[:driver_opts]).to eq(verbose: true)
839
+ end
840
+
841
+ not_compliant_on :v6_18 do
842
+ expect(@args.last[:service].instance_variable_get('@extra_args')).to eq ['--verbose']
843
+ end
844
+ end
845
+
846
+ # 6.18 works
847
+ # 6.19 deprecate --> put in options
848
+ # 7.0 remove
849
+ it 'places args by creating options' do
850
+ expect {
851
+ capabilities = Watir::Capabilities.new(:chrome,
852
+ args: ['--foo'])
853
+ args = capabilities.to_args
854
+ actual_options = args.last[:options]
855
+ expect(actual_options.args).to include '--foo'
856
+ }.to have_deprecated_args_keyword
857
+ end
858
+
859
+ # 6.18 broken because assumes args is empty and overrides
860
+ # 6.19 do nothing; never worked
861
+ # 7.0 remove
862
+ xit 'places args when paired with options Hash' do
863
+ capabilities = Watir::Capabilities.new(:chrome,
864
+ args: ['--foo'],
865
+ options: {args: ['--bar']})
866
+ args = capabilities.to_args
867
+ actual_options = args.last[:options]
868
+ expect(actual_options.args).to include '--foo', '--bar'
869
+ end
870
+
871
+ # 6.18 broken because assumes options is a Hash
872
+ # 6.19 do nothing; never worked
873
+ # 7.0 remove
874
+ xit 'places args when paired with options object' do
875
+ options = Selenium::WebDriver::Chrome::Options.new(args: ['--bar'])
876
+ capabilities = Watir::Capabilities.new(:chrome,
877
+ args: ['--foo'],
878
+ options: options)
879
+ args = capabilities.to_args
880
+ actual_options = args.last[:options]
881
+ expect(actual_options.args).to include '--foo', '--bar'
882
+ end
883
+
884
+ # 6.18 works
885
+ # 6.19 deprecate --> no more "switches"
886
+ # 7.0 remove
887
+ it 'places switches as args by creating options' do
888
+ expect {
889
+ capabilities = Watir::Capabilities.new(:chrome,
890
+ switches: ['--foo'])
891
+ args = capabilities.to_args
892
+ actual_options = args.last[:options]
893
+ expect(actual_options.args).to include '--foo'
894
+ }.to have_deprecated_switches_keyword
895
+ end
896
+
897
+ # 6.18 works
898
+ # 6.19 allow to stay in top level
899
+ # 7.0 valid
900
+ it 'sets headless by creating options' do
901
+ capabilities = Watir::Capabilities.new(:chrome, headless: true)
902
+ args = capabilities.to_args
903
+ actual_options = args.last[:options]
904
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
905
+ end
906
+
907
+ # 6.18 broken because assumes options is a Hash
908
+ # 6.19 fix
909
+ # 7.0 valid
910
+ not_compliant_on :v6_18 do
911
+ it 'sets headless in existing options class' do
912
+ capabilities = Watir::Capabilities.new(:chrome,
913
+ options: Selenium::WebDriver::Chrome::Options.new,
914
+ headless: true)
915
+ args = capabilities.to_args
916
+ actual_options = args.last[:options]
917
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
918
+ end
919
+ end
920
+
921
+ # 6.18 works
922
+ # 6.19 allow to stay in top level
923
+ # 7.0 valid
924
+ it 'sets headless when existing options is a Hash' do
925
+ options = {args: ['--foo']}
926
+ capabilities = Watir::Capabilities.new(:chrome,
927
+ options: options,
928
+ headless: true)
929
+ args = capabilities.to_args
930
+ actual_options = args.last[:options]
931
+ expect(actual_options.args).to include '--headless', '--disable-gpu', '--foo'
932
+ end
933
+
934
+ # 6.18 Working; Selenium correctly disappears any non-valid options
935
+ # 6.19 Keep
936
+ # 7.0 Valid
937
+ it 'generates options from Hash' do
938
+ options = {args: %w[--foo --bar]}
939
+ capabilities = Watir::Capabilities.new(:chrome, options: options)
940
+ args = capabilities.to_args
941
+ actual_options = args.last[:options]
942
+ expect(actual_options).to be_a Selenium::WebDriver::Chrome::Options
943
+ expect(actual_options.args).to include '--foo', '--bar'
944
+ end
945
+
946
+ # 6.18 Never implemented
947
+ # 6.19 Implement
948
+ # 7.0 Valid
949
+ not_compliant_on :v6_18 do
950
+ it 'accepts browser and w3c capabilities in options Hash' do
951
+ opts = {page_load_strategy: 'eager',
952
+ args: %w[--foo --bar]}
953
+ capabilities = Watir::Capabilities.new(:chrome,
954
+ options: opts)
955
+ args = capabilities.to_args
956
+ actual_capabilities = args.last[:desired_capabilities]
957
+ expect(actual_capabilities[:page_load_strategy]).to eq 'eager'
958
+ actual_options = args.last[:options]
959
+ expect(actual_options.args).to include '--foo', '--bar'
960
+ end
961
+ end
962
+ end
963
+
964
+ describe 'firefox' do
965
+ # 6.18 works - puts them at top level in selenium opts, which Selenium 3 can read
966
+ # 6.19 deprecate - put inside :service keyword
967
+ # 7.0 remove
968
+ it 'creates when service driver opts specified' do
969
+ halt_service(:firefox)
970
+
971
+ expect {
972
+ capabilities = Watir::Capabilities.new(:firefox,
973
+ driver_opts: {log: 'foo.log'})
974
+ @args = capabilities.to_args
975
+ }.to have_deprecated_driver_opts_keyword
976
+
977
+ compliant_on :v6_18 do
978
+ expect(@args.last[:driver_opts]).to eq(log: 'foo.log')
979
+ end
980
+
981
+ not_compliant_on :v6_18 do
982
+ expect(@args.last[:service].instance_variable_get('@extra_args')).to include '--log=foo.log'
983
+ end
984
+ end
985
+
986
+ # 6.18 Works; supposed to be deprecated already
987
+ # 6.19 Fix deprecation
988
+ # 7.0 Remove
989
+ not_compliant_on :v6_18 do
990
+ it 'puts Profile inside Options as object' do
991
+ profile = Selenium::WebDriver::Firefox::Profile.new
992
+ options = Selenium::WebDriver::Firefox::Options.new
993
+
994
+ capabilities = Watir::Capabilities.new(:firefox, options: options, profile: profile)
995
+ expect {
996
+ actual_options = capabilities.to_args.last[:options]
997
+ expect(actual_options.profile).to eq profile
998
+ }.to have_deprecated_firefox_profile
999
+ end
1000
+ end
1001
+
1002
+ # 6.18 Works; supposed to be deprecated already
1003
+ # 6.19 Fix deprecation
1004
+ # 7.0 Remove
1005
+ it 'puts Profile inside Options as Hash' do
1006
+ profile = Selenium::WebDriver::Firefox::Profile.new
1007
+ options = {args: ['--foo']}
1008
+
1009
+ capabilities = Watir::Capabilities.new(:firefox, options: options, profile: profile)
1010
+
1011
+ expect {
1012
+ actual_options = capabilities.to_args.last[:options]
1013
+ expect(actual_options.args).to include '--foo'
1014
+ expect(actual_options.profile).to eq profile
1015
+ }.to have_deprecated_firefox_profile
1016
+ end
1017
+
1018
+ # 6.18 Works
1019
+ # 6.19 Do nothing
1020
+ # 7.0 Valid
1021
+ it 'puts Profile inside Hash options' do
1022
+ profile = Selenium::WebDriver::Firefox::Profile.new
1023
+ options = {args: ['--foo'], profile: profile}
1024
+
1025
+ capabilities = Watir::Capabilities.new(:firefox, options: options)
1026
+
1027
+ actual_options = capabilities.to_args.last[:options]
1028
+ expect(actual_options.args).to include '--foo'
1029
+ expect(actual_options.profile).to eq profile
1030
+ end
1031
+
1032
+ # 6.18 works
1033
+ # 6.19 allow to stay in top level
1034
+ # 7.0 valid
1035
+ it 'sets headless by creating options' do
1036
+ capabilities = Watir::Capabilities.new(:firefox, headless: true)
1037
+ args = capabilities.to_args
1038
+ actual_options = args.last[:options]
1039
+ expect(actual_options.args).to include '--headless'
1040
+ end
1041
+
1042
+ # 6.18 broken; assumes options is a Hash
1043
+ # 6.19 fix!
1044
+ # 7.0 valid
1045
+ not_compliant_on :v6_18 do
1046
+ it 'sets headless in existing options class' do
1047
+ capabilities = Watir::Capabilities.new(:firefox,
1048
+ options: Selenium::WebDriver::Firefox::Options.new,
1049
+ headless: true)
1050
+ args = capabilities.to_args
1051
+ actual_options = args.last[:options]
1052
+ expect(actual_options.args).to include '--headless'
1053
+ end
1054
+ end
1055
+
1056
+ # 6.18 works
1057
+ # 6.19 allow to stay in top level
1058
+ # 7.0 valid
1059
+ it 'sets headless when existing options is a Hash' do
1060
+ options = {args: ['--foo']}
1061
+ capabilities = Watir::Capabilities.new(:firefox,
1062
+ options: options,
1063
+ headless: true)
1064
+ args = capabilities.to_args
1065
+ actual_options = args.last[:options]
1066
+ expect(actual_options.args).to include '--headless', '--foo'
1067
+ end
1068
+
1069
+ # 6.18 Working
1070
+ # 6.19 Keep
1071
+ # 7.0 Valid
1072
+ it 'generates Options instance from Hash' do
1073
+ options = {args: %w[--foo --bar]}
1074
+ capabilities = Watir::Capabilities.new(:firefox, options: options)
1075
+ args = capabilities.to_args
1076
+ actual_options = args.last[:options]
1077
+ expect(actual_options).to be_a Selenium::WebDriver::Firefox::Options
1078
+ expect(actual_options.args).to include '--foo', '--bar'
1079
+ end
1080
+
1081
+ # 6.18 Never implemented
1082
+ # 6.19 Implement
1083
+ # 7.0 Valid
1084
+ not_compliant_on :v6_18 do
1085
+ it 'accepts browser and w3c capabilities in options Hash' do
1086
+ opts = {page_load_strategy: 'eager',
1087
+ args: %w[--foo --bar]}
1088
+ capabilities = Watir::Capabilities.new(:firefox,
1089
+ options: opts)
1090
+ args = capabilities.to_args
1091
+ actual_capabilities = args.last[:desired_capabilities]
1092
+ expect(actual_capabilities[:page_load_strategy]).to eq 'eager'
1093
+ actual_options = args.last[:options]
1094
+ expect(actual_options.args).to include '--foo', '--bar'
1095
+ end
1096
+ end
1097
+ end
1098
+
1099
+ describe 'safari' do
1100
+ # 6.18 works
1101
+ # 6.19 do nothing
1102
+ # 7.0 valid
1103
+ it 'sets Technology Preview' do
1104
+ halt_service(:safari)
1105
+
1106
+ Watir::Capabilities.new(:safari, technology_preview: true).to_args
1107
+
1108
+ expect(Selenium::WebDriver::Safari::Service.driver_path)
1109
+ .to eq Selenium::WebDriver::Safari.technology_preview
1110
+ end
1111
+
1112
+ # 6.18 broken because doesn't handle generic Safari browser options
1113
+ # 6.19 Fix
1114
+ # 7.0 Valid
1115
+ not_compliant_on :v6_18 do
1116
+ it 'generates options from Hash' do
1117
+ options = {automatic_inspection: true}
1118
+ capabilities = Watir::Capabilities.new(:safari, options: options)
1119
+ args = capabilities.to_args
1120
+ actual_options = args.last[:options]
1121
+ expect(actual_options).to be_a Selenium::WebDriver::Safari::Options
1122
+ expect(actual_options.automatic_inspection).to eq true
1123
+ end
1124
+ end
1125
+
1126
+ # 6.18 Never implemented
1127
+ # 6.19 Implement
1128
+ # 7.0 Valid
1129
+ not_compliant_on :v6_18 do
1130
+ it 'accepts browser and w3c capabilities in options Hash' do
1131
+ opts = {page_load_strategy: 'eager',
1132
+ automatic_inspection: true}
1133
+ capabilities = Watir::Capabilities.new(:safari,
1134
+ options: opts)
1135
+ args = capabilities.to_args
1136
+ actual_capabilities = args.last[:desired_capabilities]
1137
+ expect(actual_capabilities[:page_load_strategy]).to eq 'eager'
1138
+ actual_options = args.last[:options]
1139
+ expect(actual_options.automatic_inspection).to eq true
1140
+ end
1141
+ end
1142
+ end
1143
+
1144
+ describe 'ie' do
1145
+ # 6.18 works - puts them at top level in selenium opts, which Selenium 3 can read
1146
+ # 6.19 deprecate - put inside :service keyword
1147
+ # 7.0 remove
1148
+ it 'creates when service driver opts specified' do
1149
+ halt_service(:ie)
1150
+
1151
+ expect {
1152
+ capabilities = Watir::Capabilities.new(:ie,
1153
+ driver_opts: {silent: true})
1154
+ @args = capabilities.to_args
1155
+ }.to have_deprecated_driver_opts_keyword
1156
+
1157
+ compliant_on :v6_18 do
1158
+ expect(@args.last[:driver_opts]).to eq(silent: true)
1159
+ end
1160
+
1161
+ not_compliant_on :v6_18 do
1162
+ expect(@args.last[:service].instance_variable_get('@extra_args')).to include '--silent'
1163
+ end
1164
+ end
1165
+
1166
+ # 6.18 Working
1167
+ # 6.19 Keep
1168
+ # 7.0 Valid
1169
+ it 'generates Options instance from Hash with args' do
1170
+ options = {args: %w[--foo --bar]}
1171
+ capabilities = Watir::Capabilities.new(:ie, options: options)
1172
+ args = capabilities.to_args
1173
+ actual_options = args.last[:options]
1174
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
1175
+ expect(actual_options.args).to include '--foo', '--bar'
1176
+ end
1177
+
1178
+ # 6.18 Working
1179
+ # 6.19 Keep
1180
+ # 7.0 Valid
1181
+ it 'generates Options instance from Hash with valid option' do
1182
+ options = {browser_attach_timeout: true}
1183
+ capabilities = Watir::Capabilities.new(:ie, options: options)
1184
+ args = capabilities.to_args
1185
+ actual_options = args.last[:options]
1186
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
1187
+ expect(actual_options.options[:browser_attach_timeout]).to eq true
1188
+ end
1189
+
1190
+ # 6.18 broken; assumes options is a hash
1191
+ # 6.19 Do nothing; never worked
1192
+ # 7.0 Remove
1193
+ xit 'adds args to existing options instance' do
1194
+ args = %w[--foo --bar]
1195
+ options = Selenium::WebDriver::IE::Options.new
1196
+ capabilities = Watir::Capabilities.new(:ie, options: options, args: args)
1197
+ args = capabilities.to_args
1198
+ actual_options = args.last[:options]
1199
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
1200
+ expect(actual_options.args).to include '--foo', '--bar'
1201
+ end
1202
+
1203
+ # 6.18 broken; overwrites args in options
1204
+ # 6.19 do nothing; never worked
1205
+ # 7.0 Remove
1206
+ xit 'adds args to existing options hash' do
1207
+ options = {args: ['--foo']}
1208
+ capabilities = Watir::Capabilities.new(:ie, options: options, args: ['--bar'])
1209
+ args = capabilities.to_args
1210
+ actual_options = args.last[:options]
1211
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
1212
+ expect(actual_options.args).to include '--foo', '--bar'
1213
+ end
1214
+
1215
+ # 6.18 Never implemented
1216
+ # 6.19 Implement
1217
+ # 7.0 Valid
1218
+ not_compliant_on :v6_18 do
1219
+ it 'accepts browser and w3c capabilities in options Hash' do
1220
+ opts = {page_load_strategy: 'eager',
1221
+ args: ['--foo']}
1222
+ capabilities = Watir::Capabilities.new(:ie,
1223
+ options: opts)
1224
+ args = capabilities.to_args
1225
+ actual_capabilities = args.last[:desired_capabilities]
1226
+ expect(actual_capabilities[:page_load_strategy]).to eq 'eager'
1227
+ actual_options = args.last[:options]
1228
+ expect(actual_options.args).to include '--foo'
1229
+ end
1230
+ end
1231
+
1232
+ # 6.18 Works
1233
+ # 6.19 Deprecate
1234
+ # 7.0 Remove
1235
+ it 'adds args by itself' do
1236
+ caps = Watir::Capabilities.new(:ie, args: %w[foo bar])
1237
+ expect {
1238
+ opts = caps.to_args.last[:options]
1239
+ expect(opts.args).to eq Set.new(%w[foo bar])
1240
+ }.to have_deprecated_args_keyword
25
1241
  end
26
1242
  end
27
1243
  end