watir 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +1 -1
  3. data/.github/workflows/edge.yml +1 -1
  4. data/.github/workflows/firefox.yml +1 -1
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +1 -1
  8. data/.rubocop.yml +25 -12
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +6 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +1 -1
  13. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  14. data/lib/watir/locators/element/matcher.rb +2 -1
  15. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  16. data/lib/watir/locators/text_field/matcher.rb +0 -4
  17. data/lib/watir/version.rb +1 -1
  18. data/spec/locator_spec_helper.rb +0 -8
  19. data/spec/unit/capabilities_spec.rb +553 -561
  20. data/spec/unit/element_locator_spec.rb +89 -78
  21. data/spec/unit/match_elements/button_spec.rb +69 -62
  22. data/spec/unit/match_elements/element_spec.rb +303 -309
  23. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  24. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  25. data/spec/unit/selector_builder/button_spec.rb +209 -202
  26. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  27. data/spec/unit/selector_builder/element_spec.rb +634 -627
  28. data/spec/unit/selector_builder/row_spec.rb +119 -113
  29. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  30. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  31. data/spec/unit/wait_spec.rb +85 -81
  32. data/spec/watirspec/adjacent_spec.rb +249 -247
  33. data/spec/watirspec/after_hooks_spec.rb +161 -159
  34. data/spec/watirspec/alert_spec.rb +61 -58
  35. data/spec/watirspec/browser_spec.rb +409 -409
  36. data/spec/watirspec/capabilities_spec.rb +89 -99
  37. data/spec/watirspec/cookies_spec.rb +120 -118
  38. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  39. data/spec/watirspec/element_hidden_spec.rb +66 -60
  40. data/spec/watirspec/elements/area_spec.rb +49 -47
  41. data/spec/watirspec/elements/areas_spec.rb +27 -25
  42. data/spec/watirspec/elements/button_spec.rb +253 -251
  43. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  44. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  45. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  46. data/spec/watirspec/elements/collections_spec.rb +126 -119
  47. data/spec/watirspec/elements/date_field_spec.rb +185 -183
  48. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  49. data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
  50. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  51. data/spec/watirspec/elements/dd_spec.rb +87 -85
  52. data/spec/watirspec/elements/dds_spec.rb +27 -25
  53. data/spec/watirspec/elements/del_spec.rb +106 -104
  54. data/spec/watirspec/elements/dels_spec.rb +26 -24
  55. data/spec/watirspec/elements/div_spec.rb +225 -221
  56. data/spec/watirspec/elements/divs_spec.rb +37 -35
  57. data/spec/watirspec/elements/dl_spec.rb +110 -108
  58. data/spec/watirspec/elements/dls_spec.rb +28 -26
  59. data/spec/watirspec/elements/dt_spec.rb +86 -84
  60. data/spec/watirspec/elements/dts_spec.rb +27 -25
  61. data/spec/watirspec/elements/element_spec.rb +794 -775
  62. data/spec/watirspec/elements/elements_spec.rb +40 -38
  63. data/spec/watirspec/elements/em_spec.rb +62 -60
  64. data/spec/watirspec/elements/ems_spec.rb +28 -26
  65. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  66. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  67. data/spec/watirspec/elements/font_spec.rb +20 -18
  68. data/spec/watirspec/elements/form_spec.rb +51 -49
  69. data/spec/watirspec/elements/forms_spec.rb +29 -27
  70. data/spec/watirspec/elements/frame_spec.rb +89 -87
  71. data/spec/watirspec/elements/frames_spec.rb +27 -25
  72. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  73. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  74. data/spec/watirspec/elements/hn_spec.rb +59 -57
  75. data/spec/watirspec/elements/hns_spec.rb +26 -24
  76. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  77. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  78. data/spec/watirspec/elements/image_spec.rb +148 -146
  79. data/spec/watirspec/elements/images_spec.rb +26 -24
  80. data/spec/watirspec/elements/input_spec.rb +9 -7
  81. data/spec/watirspec/elements/ins_spec.rb +106 -104
  82. data/spec/watirspec/elements/inses_spec.rb +26 -24
  83. data/spec/watirspec/elements/label_spec.rb +56 -54
  84. data/spec/watirspec/elements/labels_spec.rb +26 -24
  85. data/spec/watirspec/elements/li_spec.rb +76 -74
  86. data/spec/watirspec/elements/link_spec.rb +173 -177
  87. data/spec/watirspec/elements/links_spec.rb +45 -43
  88. data/spec/watirspec/elements/lis_spec.rb +27 -25
  89. data/spec/watirspec/elements/list_spec.rb +44 -42
  90. data/spec/watirspec/elements/map_spec.rb +57 -55
  91. data/spec/watirspec/elements/maps_spec.rb +27 -25
  92. data/spec/watirspec/elements/meta_spec.rb +16 -14
  93. data/spec/watirspec/elements/metas_spec.rb +26 -24
  94. data/spec/watirspec/elements/ol_spec.rb +56 -65
  95. data/spec/watirspec/elements/ols_spec.rb +26 -24
  96. data/spec/watirspec/elements/option_spec.rb +91 -89
  97. data/spec/watirspec/elements/p_spec.rb +81 -79
  98. data/spec/watirspec/elements/pre_spec.rb +77 -75
  99. data/spec/watirspec/elements/pres_spec.rb +26 -24
  100. data/spec/watirspec/elements/ps_spec.rb +26 -24
  101. data/spec/watirspec/elements/radio_spec.rb +251 -249
  102. data/spec/watirspec/elements/radios_spec.rb +28 -26
  103. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  104. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  105. data/spec/watirspec/elements/span_spec.rb +112 -110
  106. data/spec/watirspec/elements/spans_spec.rb +26 -24
  107. data/spec/watirspec/elements/strong_spec.rb +58 -58
  108. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  109. data/spec/watirspec/elements/table_spec.rb +192 -139
  110. data/spec/watirspec/elements/tables_spec.rb +28 -26
  111. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  112. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  113. data/spec/watirspec/elements/td_spec.rb +66 -64
  114. data/spec/watirspec/elements/tds_spec.rb +41 -39
  115. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  116. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  117. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  118. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  119. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  120. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  121. data/spec/watirspec/elements/thead_spec.rb +65 -63
  122. data/spec/watirspec/elements/theads_spec.rb +42 -40
  123. data/spec/watirspec/elements/tr_spec.rb +48 -46
  124. data/spec/watirspec/elements/trs_spec.rb +42 -40
  125. data/spec/watirspec/elements/ul_spec.rb +56 -54
  126. data/spec/watirspec/elements/uls_spec.rb +26 -24
  127. data/spec/watirspec/radio_set_spec.rb +269 -267
  128. data/spec/watirspec/screenshot_spec.rb +20 -18
  129. data/spec/watirspec/scroll_spec.rb +152 -148
  130. data/spec/watirspec/shadow_root_spec.rb +86 -83
  131. data/spec/watirspec/user_editable_spec.rb +200 -198
  132. data/spec/watirspec/wait_spec.rb +289 -295
  133. data/spec/watirspec/window_switching_spec.rb +422 -434
  134. data/spec/watirspec_helper.rb +1 -23
  135. data/watir.gemspec +5 -4
  136. metadata +44 -33
  137. data/spec/watirspec/attributes_spec.rb +0 -18
  138. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  139. data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,678 +2,670 @@
2
2
 
3
3
  require_relative 'unit_helper'
4
4
 
5
- describe Watir::Capabilities do
6
- before(:all) { Watir.logger.ignore(:watir_client) }
7
-
8
- def expected_browser(browser)
9
- case browser
10
- when :ie
11
- 'internet explorer'
12
- when :edge
13
- 'MicrosoftEdge'
14
- else
15
- browser.to_s
5
+ module Watir
6
+ describe Capabilities do
7
+ before(:all) { Watir.logger.ignore(:watir_client) }
8
+
9
+ def expected_browser(browser)
10
+ case browser
11
+ when :ie
12
+ 'internet explorer'
13
+ when :edge
14
+ 'MicrosoftEdge'
15
+ else
16
+ browser.to_s
17
+ end
16
18
  end
17
- end
18
-
19
- def service_class(browser)
20
- Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Service")
21
- end
22
19
 
23
- def options_class(browser)
24
- Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Options")
25
- end
26
-
27
- def expected_browser_class(browser)
28
- browser == :ie ? 'IE' : browser.capitalize
29
- end
30
-
31
- def halt_service(browser)
32
- allow(Selenium::WebDriver::Platform).to receive(:find_binary).and_return(true)
33
- allow(File).to receive(:file?).and_return(true)
34
- allow(File).to receive(:executable?).and_return(true)
35
- service_class(browser).driver_path = nil
36
- end
37
-
38
- supported_browsers = %i[chrome edge firefox ie safari]
39
-
40
- # Options:
41
- # :listener
42
- # :service (Built from Hash)
43
- # :http_client (Generated or Built from Hash)
44
- # :proxy (Built from Hash and added to :options)
45
- # :options (Generated or Built from Hash)
46
- # :capabilities (incompatible with options)
20
+ def service_class(browser)
21
+ Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Service")
22
+ end
47
23
 
48
- supported_browsers.each do |browser_symbol|
49
- it 'just browser has client & options not service' do
50
- capabilities = Watir::Capabilities.new(browser_symbol)
24
+ def options_class(browser)
25
+ Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Options")
26
+ end
51
27
 
52
- args = capabilities.to_args
53
- expect(args.last[:http_client]).to be_a Watir::HttpClient
54
- expect(args.last[:options]).to be_a options_class(browser_symbol)
55
- expect(args.last).not_to include(:service)
28
+ def expected_browser_class(browser)
29
+ browser == :ie ? 'IE' : browser.capitalize
56
30
  end
57
31
 
58
- it 'errors with url and service' do
59
- expect {
60
- Watir::Capabilities.new(browser_symbol,
61
- service: instance_double(Selenium::WebDriver::Service),
62
- url: 'https://example.com/wd/hub/')
63
- }.to raise_exception(ArgumentError, ':url and :service are not both allowed')
32
+ def halt_service(browser)
33
+ allow(Selenium::WebDriver::Platform).to receive(:find_binary).and_return(true)
34
+ allow(File).to receive(:file?).and_return(true)
35
+ allow(File).to receive(:executable?).and_return(true)
36
+ service_class(browser).driver_path = nil
64
37
  end
65
38
 
66
- it 'just options has client & options but not capabilities or service' do
67
- capabilities = Watir::Capabilities.new(options: options_class(browser_symbol).new)
39
+ supported_browsers = %i[chrome edge firefox ie safari]
68
40
 
69
- args = capabilities.to_args
41
+ # Options:
42
+ # :listener
43
+ # :service (Built from Hash)
44
+ # :http_client (Generated or Built from Hash)
45
+ # :proxy (Built from Hash and added to :options)
46
+ # :options (Generated or Built from Hash)
47
+ # :capabilities (incompatible with options)
70
48
 
71
- expect(args.last[:http_client]).to be_a Watir::HttpClient
72
- expect(args.last[:options]).to be_a options_class(browser_symbol)
73
- expect(args.last).not_to include(:service)
74
- end
49
+ supported_browsers.each do |browser_symbol|
50
+ it 'just browser has client & options not service' do
51
+ capabilities = described_class.new(browser_symbol)
75
52
 
76
- it 'just capabilities has client & capabilities but not service' do
77
- caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
78
- capabilities = Watir::Capabilities.new(capabilities: caps)
79
- args = []
80
- expect {
81
53
  args = capabilities.to_args
82
- }.to have_deprecated(:capabilities)
54
+ expect(args.last[:http_client]).to be_a HttpClient
55
+ expect(args.last[:options]).to be_a options_class(browser_symbol)
56
+ expect(args.last).not_to include(:service)
57
+ end
83
58
 
84
- expect(args.last[:http_client]).to be_a Watir::HttpClient
85
- expect(args.last[:capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
86
- expect(args.last[:capabilities].browser_name).to eq expected_browser(browser_symbol)
87
- expect(args.last).not_to include(:service)
88
- end
59
+ it 'errors with url and service' do
60
+ expect {
61
+ described_class.new(browser_symbol,
62
+ service: instance_double(Selenium::WebDriver::Service),
63
+ url: 'https://example.com/wd/hub/')
64
+ }.to raise_exception(ArgumentError, ':url and :service are not both allowed')
65
+ end
89
66
 
90
- describe 'service' do
91
- it 'uses provided service' do
92
- halt_service(browser_symbol)
67
+ it 'just options has client & options but not capabilities or service' do
68
+ capabilities = described_class.new(options: options_class(browser_symbol).new)
93
69
 
94
- service = service_class(browser_symbol).new(port: 1234)
95
- capabilities = Watir::Capabilities.new(browser_symbol, service: service)
96
70
  args = capabilities.to_args
97
- expect(args.first).to eq browser_symbol
98
- actual_service = args.last[:service]
99
- expect(actual_service.instance_variable_get(:@port)).to eq 1234
71
+
72
+ expect(args.last[:http_client]).to be_a HttpClient
73
+ expect(args.last[:options]).to be_a options_class(browser_symbol)
74
+ expect(args.last).not_to include(:service)
100
75
  end
101
76
 
102
- it 'builds service from a Hash' do
103
- halt_service(browser_symbol)
77
+ it 'just capabilities has client & capabilities but not service' do
78
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
79
+ capabilities = described_class.new(capabilities: caps)
80
+ args = []
81
+ expect {
82
+ args = capabilities.to_args
83
+ }.to have_deprecated(:capabilities)
104
84
 
105
- service = {port: 1234, path: '/path/to/driver', args: %w[--foo --bar]}
106
- capabilities = Watir::Capabilities.new(browser_symbol, service: service)
107
- args = capabilities.to_args
108
- expect(args.first).to eq browser_symbol
109
- actual_service = args.last[:service]
110
- expect(actual_service.instance_variable_get(:@port)).to eq 1234
111
- expect(actual_service.instance_variable_get(:@executable_path)).to eq '/path/to/driver'
112
- expect(actual_service.instance_variable_get(:@extra_args)).to include '--foo', '--bar'
85
+ expect(args.last[:http_client]).to be_a HttpClient
86
+ expect(args.last[:capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
87
+ expect(args.last[:capabilities].browser_name).to eq expected_browser(browser_symbol)
88
+ expect(args.last).not_to include(:service)
113
89
  end
114
90
 
115
- it 'is a bad argument to service' do
116
- capabilities = Watir::Capabilities.new(browser_symbol, service: 7)
91
+ describe 'service' do
92
+ it 'uses provided service' do
93
+ halt_service(browser_symbol)
94
+
95
+ service = service_class(browser_symbol).new(port: 1234)
96
+ capabilities = described_class.new(browser_symbol, service: service)
97
+ args = capabilities.to_args
98
+ expect(args.first).to eq browser_symbol
99
+ actual_service = args.last[:service]
100
+ expect(actual_service.instance_variable_get(:@port)).to eq 1234
101
+ end
102
+
103
+ it 'builds service from a Hash' do
104
+ halt_service(browser_symbol)
105
+
106
+ service = {port: 1234, path: '/path/to/driver', args: %w[--foo --bar]}
107
+ capabilities = described_class.new(browser_symbol, service: service)
108
+ args = capabilities.to_args
109
+ expect(args.first).to eq browser_symbol
110
+ actual_service = args.last[:service]
111
+ expect(actual_service.instance_variable_get(:@port)).to eq 1234
112
+ expect(actual_service.instance_variable_get(:@executable_path)).to eq '/path/to/driver'
113
+ expect(actual_service.instance_variable_get(:@extra_args)).to include '--foo', '--bar'
114
+ end
115
+
116
+ it 'is a bad argument to service' do
117
+ capabilities = described_class.new(browser_symbol, service: 7)
118
+
119
+ expect { capabilities.to_args }.to raise_exception(TypeError)
120
+ end
121
+ end
117
122
 
118
- expect { capabilities.to_args }.to raise_exception(TypeError)
123
+ describe 'http_client' do
124
+ it 'uses default HTTP Client' do
125
+ capabilities = described_class.new(browser_symbol)
126
+ args = capabilities.to_args
127
+ expect(args.last[:http_client]).to be_a HttpClient
128
+ end
129
+
130
+ it 'accepts an HTTP Client object' do
131
+ client = Selenium::WebDriver::Remote::Http::Default.new
132
+ capabilities = described_class.new(browser_symbol, http_client: client)
133
+ args = capabilities.to_args
134
+ expect(args.last[:http_client]).to eq client
135
+ end
136
+
137
+ it 'builds an HTTP Client from Hash' do
138
+ client_opts = {open_timeout: 10, read_timeout: 10}
139
+ capabilities = described_class.new(browser_symbol, http_client: client_opts)
140
+ args = capabilities.to_args
141
+ actual_client = args.last[:http_client]
142
+ expect(actual_client).to be_a HttpClient
143
+ expect(actual_client.instance_variable_get(:@read_timeout)).to eq 10
144
+ expect(actual_client.instance_variable_get(:@open_timeout)).to eq 10
145
+ end
146
+
147
+ it 'raises an exception if :client receives something other than Hash or Client object' do
148
+ expect {
149
+ described_class.new(browser_symbol, http_client: 7).to_args
150
+ }.to raise_exception(TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance')
151
+ end
119
152
  end
120
- end
121
153
 
122
- describe 'http_client' do
123
- it 'uses default HTTP Client' do
124
- capabilities = Watir::Capabilities.new(browser_symbol)
154
+ it 'uses a listener' do
155
+ listener = Selenium::WebDriver::Support::AbstractEventListener.new
156
+ capabilities = described_class.new(browser_symbol, listener: listener)
125
157
  args = capabilities.to_args
126
- expect(args.last[:http_client]).to be_a Watir::HttpClient
158
+ expect(args.last[:listener]).to eq listener
127
159
  end
128
160
 
129
- it 'accepts an HTTP Client object' do
130
- client = Selenium::WebDriver::Remote::Http::Default.new
131
- capabilities = Watir::Capabilities.new(browser_symbol, http_client: client)
161
+ it 'accepts both capabilities and Options' do
162
+ caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
163
+ opts = options_class(browser_symbol).new
164
+
165
+ expect {
166
+ described_class.new(browser_symbol, capabilities: caps, options: opts)
167
+ }.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
168
+ end
169
+
170
+ describe 'timeout options' do
171
+ it 'accepts page load and script timeouts in seconds' do
172
+ options = {page_load_timeout: 11,
173
+ script_timeout: 12}
174
+ capabilities = described_class.new(browser_symbol, options: options)
175
+ args = capabilities.to_args
176
+ actual_options = args.last[:options]
177
+ expect(actual_options.timeouts[:page_load]).to eq 11_000
178
+ expect(actual_options.timeouts[:script]).to eq 12_000
179
+ end
180
+
181
+ it 'has deprecated timeouts key with page load warning' do
182
+ options = {timeouts: {page_load: 11}}
183
+ capabilities = described_class.new(browser_symbol, options: options)
184
+ expect {
185
+ capabilities.to_args
186
+ }.to have_deprecated(:timeouts)
187
+ end
188
+
189
+ it 'has deprecated timeouts key with script warning' do
190
+ options = {timeouts: {script: 11}}
191
+ expect {
192
+ capabilities = described_class.new(browser_symbol, options: options)
193
+ capabilities.to_args
194
+ }.to have_deprecated(:timeouts)
195
+ end
196
+
197
+ it 'does not allow implicit wait timeout in timeouts hash' do
198
+ options = {timeouts: {implicit: 1}}
199
+ capabilities = described_class.new(browser_symbol, options: options)
200
+ expect {
201
+ capabilities.to_args
202
+ }.to raise_exception(ArgumentError, 'do not set implicit wait, Watir handles waiting automatically')
203
+ end
204
+ end
205
+
206
+ it 'unhandled prompt behavior defaults to ignore' do
207
+ capabilities = described_class.new(browser_symbol)
132
208
  args = capabilities.to_args
133
- expect(args.last[:http_client]).to eq client
209
+ actual_options = args.last[:options]
210
+ expect(actual_options.unhandled_prompt_behavior).to eq :ignore
134
211
  end
135
212
 
136
- it 'builds an HTTP Client from Hash' do
137
- client_opts = {open_timeout: 10, read_timeout: 10}
138
- capabilities = Watir::Capabilities.new(browser_symbol, http_client: client_opts)
213
+ it 'unhandled prompt behavior can be overridden' do
214
+ capabilities = described_class.new(browser_symbol, options: {unhandled_prompt_behavior: :accept_and_notify})
139
215
  args = capabilities.to_args
140
- actual_client = args.last[:http_client]
141
- expect(actual_client).to be_a Watir::HttpClient
142
- expect(actual_client.instance_variable_get(:@read_timeout)).to eq 10
143
- expect(actual_client.instance_variable_get(:@open_timeout)).to eq 10
216
+ actual_options = args.last[:options]
217
+ expect(actual_options.unhandled_prompt_behavior).to eq :accept_and_notify
144
218
  end
145
219
 
146
- it 'raises an exception if :client receives something other than Hash or Client object' do
147
- expect {
148
- Watir::Capabilities.new(browser_symbol, http_client: 7).to_args
149
- }.to raise_exception(TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance')
220
+ describe 'proxy' do
221
+ it 'adds Selenium Proxy to empty Options' do
222
+ proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
223
+ capabilities = described_class.new(browser_symbol, proxy: proxy)
224
+ args = capabilities.to_args
225
+ proxy = args.last[:options].proxy
226
+
227
+ expect(proxy).to be_a Selenium::WebDriver::Proxy
228
+ expect(proxy.type).to eq(:manual)
229
+ expect(proxy.http).to eq('127.0.0.1:8080')
230
+ expect(proxy.ssl).to eq('127.0.0.1:443')
231
+ end
232
+
233
+ it 'builds a Proxy from Hash for Options' do
234
+ proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
235
+ capabilities = described_class.new(browser_symbol, proxy: proxy)
236
+ args = capabilities.to_args
237
+ proxy = args.last[:options].proxy
238
+
239
+ expect(proxy).to be_a Selenium::WebDriver::Proxy
240
+ expect(proxy.type).to eq(:manual)
241
+ expect(proxy.http).to eq('127.0.0.1:8080')
242
+ expect(proxy.ssl).to eq('127.0.0.1:443')
243
+ end
244
+
245
+ it 'builds a Proxy from Hash and adds to Options' do
246
+ proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
247
+ options = {unhandled_prompt_behavior: :accept,
248
+ page_load_strategy: :eager}
249
+
250
+ capabilities = described_class.new(browser_symbol, options: options, proxy: proxy)
251
+ args = capabilities.to_args
252
+ actual_options = args.last[:options]
253
+
254
+ expect(actual_options.proxy).to be_a Selenium::WebDriver::Proxy
255
+ expect(actual_options.proxy.type).to eq(:manual)
256
+ expect(actual_options.proxy.http).to eq('127.0.0.1:8080')
257
+ expect(actual_options.proxy.ssl).to eq('127.0.0.1:443')
258
+ expect(actual_options.unhandled_prompt_behavior).to eq :accept
259
+ expect(actual_options.page_load_strategy).to eq :eager
260
+ end
150
261
  end
151
- end
152
262
 
153
- it 'uses a listener' do
154
- listener = Selenium::WebDriver::Support::AbstractEventListener.new
155
- capabilities = Watir::Capabilities.new(browser_symbol, listener: listener)
156
- args = capabilities.to_args
157
- expect(args.last[:listener]).to eq listener
158
- end
263
+ it 'errors on bad proxy key' do
264
+ proxy = {bad_key: 'foo'}
265
+ capabilities = described_class.new(browser_symbol, proxy: proxy)
159
266
 
160
- it 'accepts both capabilities and Options' do
161
- caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
162
- opts = options_class(browser_symbol).new
267
+ expect { capabilities.to_args }.to raise_error(ArgumentError, /unknown option/)
268
+ end
163
269
 
164
- expect {
165
- Watir::Capabilities.new(browser_symbol, capabilities: caps, options: opts)
166
- }.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
270
+ it 'errors on bad proxy object' do
271
+ capabilities = described_class.new(browser_symbol, proxy: 7)
272
+ expect {
273
+ capabilities.to_args
274
+ }.to raise_exception(TypeError, '7 needs to be Selenium Proxy or Hash instance')
275
+ end
167
276
  end
168
277
 
169
- describe 'timeout options' do
170
- it 'accepts page load and script timeouts in seconds' do
171
- options = {page_load_timeout: 11,
172
- script_timeout: 12}
173
- capabilities = Watir::Capabilities.new(browser_symbol, options: options)
278
+ # Options:
279
+ # :url (Required)
280
+ # :service (Errors)
281
+ # :listener
282
+ # :http_client (Generated or Built from Hash)
283
+ # :proxy (Built from Hash and added to :options)
284
+ # :options (Generated or Built from Hash)
285
+ # :capabilities (incompatible with options)
286
+
287
+ describe 'Remote execution' do
288
+ it 'with just url' do
289
+ capabilities = described_class.new(url: 'http://example.com')
174
290
  args = capabilities.to_args
291
+ expect(args.first).to eq :remote
175
292
  actual_options = args.last[:options]
176
- expect(actual_options.timeouts[:page_load]).to eq 11_000
177
- expect(actual_options.timeouts[:script]).to eq 12_000
293
+ expect(actual_options.browser_name).to eq 'chrome'
178
294
  end
179
295
 
180
- it 'has deprecated timeouts key with page load warning' do
181
- options = {timeouts: {page_load: 11}}
182
- capabilities = Watir::Capabilities.new(browser_symbol, options: options)
183
- expect {
184
- capabilities.to_args
185
- }.to have_deprecated(:timeouts)
186
- end
296
+ it 'just url & browser name has capabilities and client but not service' do
297
+ capabilities = described_class.new(:firefox,
298
+ url: 'https://example.com/wd/hub/')
299
+ args = capabilities.to_args
300
+ expect(args.first).to eq :remote
301
+ expect(args.last[:url]).to eq 'https://example.com/wd/hub/'
302
+ expect(args.last[:http_client]).to be_a HttpClient
187
303
 
188
- it 'has deprecated timeouts key with script warning' do
189
- options = {timeouts: {script: 11}}
190
- expect {
191
- capabilities = Watir::Capabilities.new(browser_symbol, options: options)
192
- capabilities.to_args
193
- }.to have_deprecated(:timeouts)
304
+ expect(args.last[:options]).to be_a Selenium::WebDriver::Firefox::Options
305
+ expect(args.last).not_to include(:service)
194
306
  end
195
307
 
196
- it 'does not allow implicit wait timeout in timeouts hash' do
197
- options = {timeouts: {implicit: 1}}
198
- capabilities = Watir::Capabilities.new(browser_symbol, options: options)
199
- expect {
200
- capabilities.to_args
201
- }.to raise_exception(ArgumentError, 'do not set implicit wait, Watir handles waiting automatically')
308
+ it 'accepts a listener' do
309
+ listener = Selenium::WebDriver::Support::AbstractEventListener.new
310
+ capabilities = described_class.new(:chrome,
311
+ url: 'http://example.com/wd/hub/',
312
+ listener: listener)
313
+ args = capabilities.to_args
314
+ expect(args.last[:listener]).to eq listener
202
315
  end
203
- end
204
316
 
205
- it 'unhandled prompt behavior defaults to ignore' do
206
- capabilities = Watir::Capabilities.new(browser_symbol)
207
- args = capabilities.to_args
208
- actual_options = args.last[:options]
209
- expect(actual_options.unhandled_prompt_behavior).to eq :ignore
210
- end
317
+ it 'accepts http client object' do
318
+ client = HttpClient.new
319
+ capabilities = described_class.new(:chrome,
320
+ url: 'https://example.com/wd/hub',
321
+ http_client: client)
322
+ args = capabilities.to_args
323
+ expect(args.first).to eq :remote
324
+ expect(args.last[:http_client]).to eq client
325
+ actual_options = args.last[:options]
326
+ expect(actual_options.browser_name).to eq 'chrome'
327
+ end
211
328
 
212
- it 'unhandled prompt behavior can be overridden' do
213
- capabilities = Watir::Capabilities.new(browser_symbol, options: {unhandled_prompt_behavior: :accept_and_notify})
214
- args = capabilities.to_args
215
- actual_options = args.last[:options]
216
- expect(actual_options.unhandled_prompt_behavior).to eq :accept_and_notify
217
- end
329
+ it 'accepts http client Hash' do
330
+ capabilities = described_class.new(:chrome,
331
+ url: 'https://example.com/wd/hub',
332
+ http_client: {read_timeout: 30})
333
+ args = capabilities.to_args
334
+ expect(args.first).to eq :remote
335
+ expect(args.last[:http_client].instance_variable_get(:@read_timeout)).to eq 30
336
+ actual_options = args.last[:options]
337
+ expect(actual_options.browser_name).to eq 'chrome'
338
+ end
218
339
 
219
- describe 'proxy' do
220
- it 'adds Selenium Proxy to empty Options' do
340
+ it 'accepts proxy object' do
221
341
  proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
222
- capabilities = Watir::Capabilities.new(browser_symbol, proxy: proxy)
342
+ capabilities = described_class.new(:chrome,
343
+ url: 'https://example.com/wd/hub',
344
+ proxy: proxy)
223
345
  args = capabilities.to_args
346
+ expect(args.first).to eq :remote
224
347
  proxy = args.last[:options].proxy
225
-
226
348
  expect(proxy).to be_a Selenium::WebDriver::Proxy
227
349
  expect(proxy.type).to eq(:manual)
228
350
  expect(proxy.http).to eq('127.0.0.1:8080')
229
351
  expect(proxy.ssl).to eq('127.0.0.1:443')
230
352
  end
231
353
 
232
- it 'builds a Proxy from Hash for Options' do
354
+ it 'accepts proxy Hash' do
233
355
  proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
234
- capabilities = Watir::Capabilities.new(browser_symbol, proxy: proxy)
356
+ capabilities = described_class.new(:chrome,
357
+ url: 'https://example.com/wd/hub',
358
+ proxy: proxy)
235
359
  args = capabilities.to_args
360
+ expect(args.first).to eq :remote
236
361
  proxy = args.last[:options].proxy
237
-
238
362
  expect(proxy).to be_a Selenium::WebDriver::Proxy
239
363
  expect(proxy.type).to eq(:manual)
240
364
  expect(proxy.http).to eq('127.0.0.1:8080')
241
365
  expect(proxy.ssl).to eq('127.0.0.1:443')
242
366
  end
243
367
 
244
- it 'builds a Proxy from Hash and adds to Options' do
245
- proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
246
- options = {unhandled_prompt_behavior: :accept,
247
- page_load_strategy: :eager}
248
-
249
- capabilities = Watir::Capabilities.new(browser_symbol, options: options, proxy: proxy)
368
+ it 'accepts options object' do
369
+ capabilities = described_class.new(:chrome,
370
+ url: 'https://example.com/wd/hub',
371
+ options: Selenium::WebDriver::Chrome::Options.new(args: ['--foo']))
250
372
  args = capabilities.to_args
373
+ expect(args.first).to eq :remote
251
374
  actual_options = args.last[:options]
252
-
253
- expect(actual_options.proxy).to be_a Selenium::WebDriver::Proxy
254
- expect(actual_options.proxy.type).to eq(:manual)
255
- expect(actual_options.proxy.http).to eq('127.0.0.1:8080')
256
- expect(actual_options.proxy.ssl).to eq('127.0.0.1:443')
257
- expect(actual_options.unhandled_prompt_behavior).to eq :accept
258
- expect(actual_options.page_load_strategy).to eq :eager
375
+ expect(actual_options.browser_name).to eq 'chrome'
376
+ expect(actual_options.args).to include('--foo')
259
377
  end
260
- end
261
-
262
- it 'errors on bad proxy key' do
263
- proxy = {bad_key: 'foo'}
264
- capabilities = Watir::Capabilities.new(browser_symbol, proxy: proxy)
265
-
266
- expect { capabilities.to_args }.to raise_error(ArgumentError, /unknown option/)
267
- end
268
-
269
- it 'errors on bad proxy object' do
270
- capabilities = Watir::Capabilities.new(browser_symbol, proxy: 7)
271
- expect {
272
- capabilities.to_args
273
- }.to raise_exception(TypeError, '7 needs to be Selenium Proxy or Hash instance')
274
- end
275
- end
276
-
277
- # Options:
278
- # :url (Required)
279
- # :service (Errors)
280
- # :listener
281
- # :http_client (Generated or Built from Hash)
282
- # :proxy (Built from Hash and added to :options)
283
- # :options (Generated or Built from Hash)
284
- # :capabilities (incompatible with options)
285
-
286
- describe 'Remote execution' do
287
- it 'with just url' do
288
- capabilities = Watir::Capabilities.new(url: 'http://example.com')
289
- args = capabilities.to_args
290
- expect(args.first).to eq :remote
291
- actual_options = args.last[:options]
292
- expect(actual_options.browser_name).to eq 'chrome'
293
- end
294
378
 
295
- it 'just url & browser name has capabilities and client but not service' do
296
- capabilities = Watir::Capabilities.new(:firefox,
297
- url: 'https://example.com/wd/hub/')
298
- args = capabilities.to_args
299
- expect(args.first).to eq :remote
300
- expect(args.last[:url]).to eq 'https://example.com/wd/hub/'
301
- expect(args.last[:http_client]).to be_a Watir::HttpClient
302
-
303
- expect(args.last[:options]).to be_a Selenium::WebDriver::Firefox::Options
304
- expect(args.last).not_to include(:service)
305
- end
306
-
307
- it 'accepts a listener' do
308
- listener = Selenium::WebDriver::Support::AbstractEventListener.new
309
- capabilities = Watir::Capabilities.new(:chrome,
310
- url: 'http://example.com/wd/hub/',
311
- listener: listener)
312
- args = capabilities.to_args
313
- expect(args.last[:listener]).to eq listener
314
- end
315
-
316
- it 'accepts http client object' do
317
- client = Watir::HttpClient.new
318
- capabilities = Watir::Capabilities.new(:chrome,
319
- url: 'https://example.com/wd/hub',
320
- http_client: client)
321
- args = capabilities.to_args
322
- expect(args.first).to eq :remote
323
- expect(args.last[:http_client]).to eq client
324
- actual_options = args.last[:options]
325
- expect(actual_options.browser_name).to eq 'chrome'
326
- end
327
-
328
- it 'accepts http client Hash' do
329
- capabilities = Watir::Capabilities.new(:chrome,
330
- url: 'https://example.com/wd/hub',
331
- http_client: {read_timeout: 30})
332
- args = capabilities.to_args
333
- expect(args.first).to eq :remote
334
- expect(args.last[:http_client].instance_variable_get(:@read_timeout)).to eq 30
335
- actual_options = args.last[:options]
336
- expect(actual_options.browser_name).to eq 'chrome'
337
- end
338
-
339
- it 'accepts proxy object' do
340
- proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
341
- capabilities = Watir::Capabilities.new(:chrome,
342
- url: 'https://example.com/wd/hub',
343
- proxy: proxy)
344
- args = capabilities.to_args
345
- expect(args.first).to eq :remote
346
- proxy = args.last[:options].proxy
347
- expect(proxy).to be_a Selenium::WebDriver::Proxy
348
- expect(proxy.type).to eq(:manual)
349
- expect(proxy.http).to eq('127.0.0.1:8080')
350
- expect(proxy.ssl).to eq('127.0.0.1:443')
351
- end
379
+ it 'accepts options hash' do
380
+ options = {prefs: {foo: 'bar'}}
381
+ capabilities = described_class.new(:chrome,
382
+ url: 'http://example.com',
383
+ options: options)
384
+ args = capabilities.to_args
385
+ expect(args.first).to eq :remote
386
+ expect(args.last[:url]).to eq 'http://example.com'
387
+ actual_options = args.last[:options]
388
+ expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
389
+ expect(actual_options.prefs).to eq(foo: 'bar')
390
+ end
352
391
 
353
- it 'accepts proxy Hash' do
354
- proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
355
- capabilities = Watir::Capabilities.new(:chrome,
356
- url: 'https://example.com/wd/hub',
357
- proxy: proxy)
358
- args = capabilities.to_args
359
- expect(args.first).to eq :remote
360
- proxy = args.last[:options].proxy
361
- expect(proxy).to be_a Selenium::WebDriver::Proxy
362
- expect(proxy.type).to eq(:manual)
363
- expect(proxy.http).to eq('127.0.0.1:8080')
364
- expect(proxy.ssl).to eq('127.0.0.1:443')
365
- end
392
+ it 'accepts capabilities object' do
393
+ caps = described_class.new(:chrome,
394
+ url: 'https://example.com/wd/hub',
395
+ capabilities: Selenium::WebDriver::Remote::Capabilities.chrome)
396
+ args = []
397
+ expect {
398
+ args = caps.to_args
399
+ }.to have_deprecated(:capabilities)
366
400
 
367
- it 'accepts options object' do
368
- capabilities = Watir::Capabilities.new(:chrome,
369
- url: 'https://example.com/wd/hub',
370
- options: Selenium::WebDriver::Chrome::Options.new(args: ['--foo']))
371
- args = capabilities.to_args
372
- expect(args.first).to eq :remote
373
- actual_options = args.last[:options]
374
- expect(actual_options.browser_name).to eq 'chrome'
375
- expect(actual_options.args).to include('--foo')
376
- end
401
+ expect(args.first).to eq :remote
402
+ actual_capabilities = args.last[:capabilities]
403
+ expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
404
+ expect(actual_capabilities.browser_name).to eq 'chrome'
405
+ end
377
406
 
378
- it 'accepts options hash' do
379
- options = {prefs: {foo: 'bar'}}
380
- capabilities = Watir::Capabilities.new(:chrome,
381
- url: 'http://example.com',
382
- options: options)
383
- args = capabilities.to_args
384
- expect(args.first).to eq :remote
385
- expect(args.last[:url]).to eq 'http://example.com'
386
- actual_options = args.last[:options]
387
- expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
388
- expect(actual_options.prefs).to eq(foo: 'bar')
389
- end
407
+ it 'accepts http client & capabilities objects' do
408
+ client = HttpClient.new
409
+ caps = described_class.new(:chrome,
410
+ url: 'https://example.com/wd/hub',
411
+ capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
412
+ http_client: client)
413
+ args = []
414
+ expect {
415
+ args = caps.to_args
416
+ }.to have_deprecated(:capabilities)
390
417
 
391
- it 'accepts capabilities object' do
392
- caps = Watir::Capabilities.new(:chrome,
393
- url: 'https://example.com/wd/hub',
394
- capabilities: Selenium::WebDriver::Remote::Capabilities.chrome)
395
- args = []
396
- expect {
397
- args = caps.to_args
398
- }.to have_deprecated(:capabilities)
418
+ expect(args.first).to eq :remote
419
+ expect(args.last[:http_client]).to eq client
420
+ actual_capabilities = args.last[:capabilities]
421
+ expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
422
+ expect(actual_capabilities.browser_name).to eq 'chrome'
423
+ end
399
424
 
400
- expect(args.first).to eq :remote
401
- actual_capabilities = args.last[:capabilities]
402
- expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
403
- expect(actual_capabilities.browser_name).to eq 'chrome'
404
- end
425
+ it 'accepts http client & proxy & options objects' do
426
+ client = HttpClient.new
427
+ proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
428
+ options = Selenium::WebDriver::Chrome::Options.new(prefs: {foo: 'bar'})
429
+ caps = described_class.new(:chrome,
430
+ url: 'https://example.com/wd/hub',
431
+ proxy: proxy,
432
+ options: options,
433
+ http_client: client)
405
434
 
406
- it 'accepts http client & capabilities objects' do
407
- client = Watir::HttpClient.new
408
- caps = Watir::Capabilities.new(:chrome,
409
- url: 'https://example.com/wd/hub',
410
- capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
411
- http_client: client)
412
- args = []
413
- expect {
414
435
  args = caps.to_args
415
- }.to have_deprecated(:capabilities)
416
-
417
- expect(args.first).to eq :remote
418
- expect(args.last[:http_client]).to eq client
419
- actual_capabilities = args.last[:capabilities]
420
- expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
421
- expect(actual_capabilities.browser_name).to eq 'chrome'
422
- end
423
-
424
- it 'accepts http client & proxy & options objects' do
425
- client = Watir::HttpClient.new
426
- proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
427
- options = Selenium::WebDriver::Chrome::Options.new(prefs: {foo: 'bar'})
428
- caps = Watir::Capabilities.new(:chrome,
429
- url: 'https://example.com/wd/hub',
430
- proxy: proxy,
431
- options: options,
432
- http_client: client)
433
-
434
- args = caps.to_args
435
- expect(args.first).to eq :remote
436
- expect(args.last[:http_client]).to eq client
437
- actual_options = args.last[:options]
438
- expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
439
- expect(actual_options.prefs).to eq(foo: 'bar')
440
- proxy = args.last[:options].proxy
441
- expect(proxy).to be_a Selenium::WebDriver::Proxy
442
- expect(proxy.type).to eq(:manual)
443
- expect(proxy.http).to eq('127.0.0.1:8080')
444
- expect(proxy.ssl).to eq('127.0.0.1:443')
445
- end
446
-
447
- it 'raises exception when both options & capabilities defined' do
448
- options = {prefs: {foo: 'bar'}}
449
-
450
- expect {
451
- Watir::Capabilities.new(:chrome,
452
- url: 'https://example.com/wd/hub',
453
- capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
454
- options: options)
455
- }.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
456
- end
457
-
458
- it 'allows headless to be set in chrome' do
459
- capabilities = Watir::Capabilities.new(:chrome,
460
- headless: true,
461
- url: 'http://example.com')
462
- args = capabilities.to_args
463
- actual_options = args.last[:options]
464
- expect(actual_options.args).to include '--headless', '--disable-gpu'
465
- end
466
-
467
- it 'allows headless to be set in firefox' do
468
- capabilities = Watir::Capabilities.new(:firefox,
469
- headless: true,
470
- url: 'http://example.com')
471
- args = capabilities.to_args
472
-
473
- expect(args.last[:options].args).to include '-headless'
474
- end
436
+ expect(args.first).to eq :remote
437
+ expect(args.last[:http_client]).to eq client
438
+ actual_options = args.last[:options]
439
+ expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
440
+ expect(actual_options.prefs).to eq(foo: 'bar')
441
+ proxy = args.last[:options].proxy
442
+ expect(proxy).to be_a Selenium::WebDriver::Proxy
443
+ expect(proxy.type).to eq(:manual)
444
+ expect(proxy.http).to eq('127.0.0.1:8080')
445
+ expect(proxy.ssl).to eq('127.0.0.1:443')
446
+ end
475
447
 
476
- it 'supports multiple vendor capabilities' do
477
- sauce_options = {'sauce:options': {username: ENV.fetch('SAUCE_USERNAME', nil),
478
- access_key: ENV.fetch('SAUCE_ACCESS_KEY', nil)}}
479
- other_options = {'other:options': {foo: 'bar'}}
448
+ it 'raises exception when both options & capabilities defined' do
449
+ options = {prefs: {foo: 'bar'}}
480
450
 
481
- capabilities = Watir::Capabilities.new(:chrome,
482
- options: sauce_options.merge(other_options),
483
- url: 'https://ondemand.us-west-1.saucelabs.com')
451
+ expect {
452
+ described_class.new(:chrome,
453
+ url: 'https://example.com/wd/hub',
454
+ capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
455
+ options: options)
456
+ }.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
457
+ end
484
458
 
485
- generated_options = capabilities.to_args.last[:options]
486
- expect(generated_options).to be_a(Selenium::WebDriver::Chrome::Options)
487
- expect(generated_options.unhandled_prompt_behavior).to eq :ignore
488
- expect(generated_options.instance_variable_get(:@options)[:'sauce:options']).to eq sauce_options[:'sauce:options']
489
- expect(generated_options.instance_variable_get(:@options)[:'other:options']).to eq other_options[:'other:options']
490
- end
491
- end
459
+ it 'allows headless to be set in chrome' do
460
+ capabilities = described_class.new(:chrome,
461
+ headless: true,
462
+ url: 'http://example.com')
463
+ args = capabilities.to_args
464
+ actual_options = args.last[:options]
465
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
466
+ end
492
467
 
493
- describe 'chrome' do
494
- it 'by default uses chrome, has client, options, but not capabilities' do
495
- capabilities = Watir::Capabilities.new
496
- args = capabilities.to_args
497
- expect(args.last[:http_client]).to be_a Watir::HttpClient
498
- expect(args.last[:options]).to be_a Selenium::WebDriver::Chrome::Options
499
- expect(args.last).not_to include(:service)
500
- end
468
+ it 'allows headless to be set in firefox' do
469
+ capabilities = described_class.new(:firefox,
470
+ headless: true,
471
+ url: 'http://example.com')
472
+ args = capabilities.to_args
501
473
 
502
- it 'sets headless by creating options' do
503
- capabilities = Watir::Capabilities.new(:chrome, headless: true)
504
- args = capabilities.to_args
505
- actual_options = args.last[:options]
506
- expect(actual_options.args).to include '--headless', '--disable-gpu'
507
- end
474
+ expect(args.last[:options].args).to include '-headless'
475
+ end
508
476
 
509
- it 'sets headless in existing options class' do
510
- capabilities = Watir::Capabilities.new(:chrome,
511
- options: Selenium::WebDriver::Chrome::Options.new,
512
- headless: true)
513
- args = capabilities.to_args
514
- actual_options = args.last[:options]
515
- expect(actual_options.args).to include '--headless', '--disable-gpu'
477
+ it 'supports multiple vendor capabilities' do
478
+ sauce_options = {'sauce:options': {username: ENV.fetch('SAUCE_USERNAME', nil),
479
+ access_key: ENV.fetch('SAUCE_ACCESS_KEY', nil)}}
480
+ other_options = {'other:options': {foo: 'bar'}}
481
+
482
+ capabilities = described_class.new(:chrome,
483
+ options: sauce_options.merge(other_options),
484
+ url: 'https://ondemand.us-west-1.saucelabs.com')
485
+
486
+ generated_options = capabilities.to_args.last[:options]
487
+ expect(generated_options).to be_a(Selenium::WebDriver::Chrome::Options)
488
+ expect(generated_options.unhandled_prompt_behavior).to eq :ignore
489
+ actual_options = generated_options.instance_variable_get(:@options)
490
+ expect(actual_options[:'sauce:options']).to eq sauce_options[:'sauce:options']
491
+ expect(actual_options[:'other:options']).to eq other_options[:'other:options']
492
+ end
516
493
  end
517
494
 
518
- it 'sets headless when existing options is a Hash' do
519
- options = {args: ['--foo']}
520
- capabilities = Watir::Capabilities.new(:chrome,
521
- options: options,
522
- headless: true)
523
- args = capabilities.to_args
524
- actual_options = args.last[:options]
525
- expect(actual_options.args).to include '--headless', '--disable-gpu', '--foo'
526
- end
495
+ describe 'chrome' do
496
+ it 'by default uses chrome, has client, options, but not capabilities' do
497
+ capabilities = described_class.new
498
+ args = capabilities.to_args
499
+ expect(args.last[:http_client]).to be_a HttpClient
500
+ expect(args.last[:options]).to be_a Selenium::WebDriver::Chrome::Options
501
+ expect(args.last).not_to include(:service)
502
+ end
527
503
 
528
- it 'generates options from Hash' do
529
- options = {args: %w[--foo --bar]}
530
- capabilities = Watir::Capabilities.new(:chrome, options: options)
531
- args = capabilities.to_args
532
- actual_options = args.last[:options]
533
- expect(actual_options).to be_a Selenium::WebDriver::Chrome::Options
534
- expect(actual_options.args).to include '--foo', '--bar'
535
- end
504
+ it 'sets headless by creating options' do
505
+ capabilities = described_class.new(:chrome, headless: true)
506
+ args = capabilities.to_args
507
+ actual_options = args.last[:options]
508
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
509
+ end
536
510
 
537
- it 'accepts browser and w3c capabilities in options Hash' do
538
- opts = {page_load_strategy: 'eager',
539
- args: %w[--foo --bar]}
540
- capabilities = Watir::Capabilities.new(:chrome,
541
- options: opts)
542
- args = capabilities.to_args
543
- actual_options = args.last[:options]
544
- expect(actual_options.page_load_strategy).to eq 'eager'
545
- expect(actual_options.args).to include '--foo', '--bar'
546
- end
547
- end
511
+ it 'sets headless in existing options class' do
512
+ capabilities = described_class.new(:chrome,
513
+ options: Selenium::WebDriver::Chrome::Options.new,
514
+ headless: true)
515
+ args = capabilities.to_args
516
+ actual_options = args.last[:options]
517
+ expect(actual_options.args).to include '--headless', '--disable-gpu'
518
+ end
548
519
 
549
- describe 'firefox' do
550
- it 'puts Profile inside Options as Hash' do
551
- profile = Selenium::WebDriver::Firefox::Profile.new
552
- options = {args: ['--foo'], profile: profile}
520
+ it 'sets headless when existing options is a Hash' do
521
+ options = {args: ['--foo']}
522
+ capabilities = described_class.new(:chrome,
523
+ options: options,
524
+ headless: true)
525
+ args = capabilities.to_args
526
+ actual_options = args.last[:options]
527
+ expect(actual_options.args).to include '--headless', '--disable-gpu', '--foo'
528
+ end
553
529
 
554
- capabilities = Watir::Capabilities.new(:firefox, options: options)
530
+ it 'generates options from Hash' do
531
+ options = {args: %w[--foo --bar]}
532
+ capabilities = described_class.new(:chrome, options: options)
533
+ args = capabilities.to_args
534
+ actual_options = args.last[:options]
535
+ expect(actual_options).to be_a Selenium::WebDriver::Chrome::Options
536
+ expect(actual_options.args).to include '--foo', '--bar'
537
+ end
555
538
 
556
- actual_options = capabilities.to_args.last[:options]
557
- expect(actual_options.args).to include '--foo'
558
- expect(actual_options.profile).to eq profile
539
+ it 'accepts browser and w3c capabilities in options Hash' do
540
+ opts = {page_load_strategy: 'eager',
541
+ args: %w[--foo --bar]}
542
+ capabilities = described_class.new(:chrome,
543
+ options: opts)
544
+ args = capabilities.to_args
545
+ actual_options = args.last[:options]
546
+ expect(actual_options.page_load_strategy).to eq 'eager'
547
+ expect(actual_options.args).to include '--foo', '--bar'
548
+ end
559
549
  end
560
550
 
561
- it 'puts Profile inside Hash options' do
562
- profile = Selenium::WebDriver::Firefox::Profile.new
563
- options = {args: ['--foo'], profile: profile}
551
+ describe 'firefox' do
552
+ it 'puts Profile inside Options as Hash' do
553
+ profile = Selenium::WebDriver::Firefox::Profile.new
554
+ options = {args: ['--foo'], profile: profile}
564
555
 
565
- capabilities = Watir::Capabilities.new(:firefox, options: options)
556
+ capabilities = described_class.new(:firefox, options: options)
566
557
 
567
- actual_options = capabilities.to_args.last[:options]
568
- expect(actual_options.args).to include '--foo'
569
- expect(actual_options.profile).to eq profile
570
- end
558
+ actual_options = capabilities.to_args.last[:options]
559
+ expect(actual_options.args).to include '--foo'
560
+ expect(actual_options.profile).to eq profile
561
+ end
571
562
 
572
- it 'sets headless by creating options' do
573
- capabilities = Watir::Capabilities.new(:firefox, headless: true)
574
- args = capabilities.to_args
575
- actual_options = args.last[:options]
576
- expect(actual_options.args).to include '-headless'
577
- end
563
+ it 'sets headless by creating options' do
564
+ capabilities = described_class.new(:firefox, headless: true)
565
+ args = capabilities.to_args
566
+ actual_options = args.last[:options]
567
+ expect(actual_options.args).to include '-headless'
568
+ end
578
569
 
579
- it 'sets headless in existing options class' do
580
- capabilities = Watir::Capabilities.new(:firefox,
581
- options: Selenium::WebDriver::Firefox::Options.new,
582
- headless: true)
583
- args = capabilities.to_args
584
- actual_options = args.last[:options]
585
- expect(actual_options.args).to include '-headless'
586
- end
570
+ it 'sets headless in existing options class' do
571
+ capabilities = described_class.new(:firefox,
572
+ options: Selenium::WebDriver::Firefox::Options.new,
573
+ headless: true)
574
+ args = capabilities.to_args
575
+ actual_options = args.last[:options]
576
+ expect(actual_options.args).to include '-headless'
577
+ end
587
578
 
588
- it 'sets headless when existing options is a Hash' do
589
- options = {args: ['-foo']}
590
- capabilities = Watir::Capabilities.new(:firefox,
591
- options: options,
592
- headless: true)
593
- args = capabilities.to_args
594
- actual_options = args.last[:options]
595
- expect(actual_options.args).to include '-headless', '-foo'
596
- end
579
+ it 'sets headless when existing options is a Hash' do
580
+ options = {args: ['-foo']}
581
+ capabilities = described_class.new(:firefox,
582
+ options: options,
583
+ headless: true)
584
+ args = capabilities.to_args
585
+ actual_options = args.last[:options]
586
+ expect(actual_options.args).to include '-headless', '-foo'
587
+ end
597
588
 
598
- it 'generates Options instance from Hash' do
599
- options = {args: %w[--foo --bar]}
600
- capabilities = Watir::Capabilities.new(:firefox, options: options)
601
- args = capabilities.to_args
602
- actual_options = args.last[:options]
603
- expect(actual_options).to be_a Selenium::WebDriver::Firefox::Options
604
- expect(actual_options.args).to include '--foo', '--bar'
605
- end
589
+ it 'generates Options instance from Hash' do
590
+ options = {args: %w[--foo --bar]}
591
+ capabilities = described_class.new(:firefox, options: options)
592
+ args = capabilities.to_args
593
+ actual_options = args.last[:options]
594
+ expect(actual_options).to be_a Selenium::WebDriver::Firefox::Options
595
+ expect(actual_options.args).to include '--foo', '--bar'
596
+ end
606
597
 
607
- it 'accepts browser and w3c capabilities in options Hash' do
608
- opts = {page_load_strategy: 'eager',
609
- args: %w[--foo --bar]}
610
- capabilities = Watir::Capabilities.new(:firefox,
611
- options: opts)
612
- args = capabilities.to_args
613
- actual_options = args.last[:options]
614
- expect(actual_options.args).to include '--foo', '--bar'
615
- expect(actual_options.page_load_strategy).to eq 'eager'
598
+ it 'accepts browser and w3c capabilities in options Hash' do
599
+ opts = {page_load_strategy: 'eager',
600
+ args: %w[--foo --bar]}
601
+ capabilities = described_class.new(:firefox,
602
+ options: opts)
603
+ args = capabilities.to_args
604
+ actual_options = args.last[:options]
605
+ expect(actual_options.args).to include '--foo', '--bar'
606
+ expect(actual_options.page_load_strategy).to eq 'eager'
607
+ end
616
608
  end
617
- end
618
609
 
619
- describe 'safari' do
620
- it 'sets Technology Preview' do
621
- halt_service(:safari)
610
+ describe 'safari' do
611
+ it 'sets Technology Preview' do
612
+ halt_service(:safari)
622
613
 
623
- Watir::Capabilities.new(:safari, technology_preview: true).to_args
614
+ described_class.new(:safari, technology_preview: true).to_args
624
615
 
625
- expect(Selenium::WebDriver::Safari.technology_preview?).to eq true
626
- end
616
+ expect(Selenium::WebDriver::Safari.technology_preview?).to be true
617
+ end
627
618
 
628
- it 'generates options from Hash' do
629
- options = {automatic_inspection: true}
630
- capabilities = Watir::Capabilities.new(:safari, options: options)
631
- args = capabilities.to_args
632
- actual_options = args.last[:options]
633
- expect(actual_options).to be_a Selenium::WebDriver::Safari::Options
634
- expect(actual_options.automatic_inspection).to eq true
635
- end
619
+ it 'generates options from Hash' do
620
+ options = {automatic_inspection: true}
621
+ capabilities = described_class.new(:safari, options: options)
622
+ args = capabilities.to_args
623
+ actual_options = args.last[:options]
624
+ expect(actual_options).to be_a Selenium::WebDriver::Safari::Options
625
+ expect(actual_options.automatic_inspection).to be true
626
+ end
636
627
 
637
- it 'accepts browser and w3c capabilities in options Hash' do
638
- opts = {page_load_strategy: 'eager',
639
- automatic_inspection: true}
640
- capabilities = Watir::Capabilities.new(:safari,
641
- options: opts)
642
- args = capabilities.to_args
643
- actual_options = args.last[:options]
644
- expect(actual_options.automatic_inspection).to eq true
645
- expect(actual_options.page_load_strategy).to eq 'eager'
628
+ it 'accepts browser and w3c capabilities in options Hash' do
629
+ opts = {page_load_strategy: 'eager',
630
+ automatic_inspection: true}
631
+ capabilities = described_class.new(:safari,
632
+ options: opts)
633
+ args = capabilities.to_args
634
+ actual_options = args.last[:options]
635
+ expect(actual_options.automatic_inspection).to be true
636
+ expect(actual_options.page_load_strategy).to eq 'eager'
637
+ end
646
638
  end
647
- end
648
639
 
649
- describe 'ie' do
650
- it 'generates Options instance from Hash with args' do
651
- options = {args: %w[--foo --bar]}
652
- capabilities = Watir::Capabilities.new(:ie, options: options)
653
- args = capabilities.to_args
654
- actual_options = args.last[:options]
655
- expect(actual_options).to be_a Selenium::WebDriver::IE::Options
656
- expect(actual_options.args).to include '--foo', '--bar'
657
- end
640
+ describe 'ie' do
641
+ it 'generates Options instance from Hash with args' do
642
+ options = {args: %w[--foo --bar]}
643
+ capabilities = described_class.new(:ie, options: options)
644
+ args = capabilities.to_args
645
+ actual_options = args.last[:options]
646
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
647
+ expect(actual_options.args).to include '--foo', '--bar'
648
+ end
658
649
 
659
- it 'generates Options instance from Hash with valid option' do
660
- options = {browser_attach_timeout: true}
661
- capabilities = Watir::Capabilities.new(:ie, options: options)
662
- args = capabilities.to_args
663
- actual_options = args.last[:options]
664
- expect(actual_options).to be_a Selenium::WebDriver::IE::Options
665
- expect(actual_options.options[:browser_attach_timeout]).to eq true
666
- end
650
+ it 'generates Options instance from Hash with valid option' do
651
+ options = {browser_attach_timeout: true}
652
+ capabilities = described_class.new(:ie, options: options)
653
+ args = capabilities.to_args
654
+ actual_options = args.last[:options]
655
+ expect(actual_options).to be_a Selenium::WebDriver::IE::Options
656
+ expect(actual_options.options[:browser_attach_timeout]).to be true
657
+ end
667
658
 
668
- it 'accepts browser and w3c capabilities in options Hash' do
669
- opts = {page_load_strategy: 'eager',
670
- args: ['--foo']}
671
- capabilities = Watir::Capabilities.new(:ie,
672
- options: opts)
673
- args = capabilities.to_args
674
- actual_options = args.last[:options]
675
- expect(actual_options.args).to include '--foo'
676
- expect(actual_options.page_load_strategy).to eq 'eager'
659
+ it 'accepts browser and w3c capabilities in options Hash' do
660
+ opts = {page_load_strategy: 'eager',
661
+ args: ['--foo']}
662
+ capabilities = described_class.new(:ie,
663
+ options: opts)
664
+ args = capabilities.to_args
665
+ actual_options = args.last[:options]
666
+ expect(actual_options.args).to include '--foo'
667
+ expect(actual_options.page_load_strategy).to eq 'eager'
668
+ end
677
669
  end
678
670
  end
679
671
  end