watir 7.0.0.beta1 → 7.0.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +7 -3
- data/.rubocop.yml +2 -7
- data/CHANGES.md +32 -0
- data/lib/watir/browser.rb +21 -7
- data/lib/watir/capabilities.rb +52 -7
- data/lib/watir/elements/date_field.rb +4 -1
- data/lib/watir/elements/date_time_field.rb +4 -1
- data/lib/watir/elements/element.rb +32 -3
- data/lib/watir/elements/font.rb +1 -0
- data/lib/watir/elements/iframe.rb +0 -1
- data/lib/watir/elements/radio.rb +2 -2
- data/lib/watir/elements/select.rb +63 -40
- data/lib/watir/has_window.rb +2 -0
- data/lib/watir/locators.rb +4 -0
- data/lib/watir/locators/element/matcher.rb +1 -1
- data/lib/watir/locators/element/selector_builder.rb +0 -3
- data/lib/watir/locators/element/selector_builder/xpath.rb +2 -1
- data/lib/watir/locators/option/matcher.rb +24 -0
- data/lib/watir/locators/option/selector_builder.rb +8 -0
- data/lib/watir/locators/option/selector_builder/xpath.rb +37 -0
- data/lib/watir/logger.rb +3 -74
- data/lib/watir/radio_set.rb +1 -0
- data/lib/watir/screenshot.rb +2 -8
- data/lib/watir/user_editable.rb +10 -3
- data/lib/watir/version.rb +1 -1
- data/lib/watir/window.rb +15 -4
- data/lib/watir/window_collection.rb +9 -0
- data/lib/watirspec.rb +4 -2
- data/lib/watirspec/guards.rb +1 -1
- data/lib/watirspec/remote_server.rb +2 -6
- data/lib/watirspec/server.rb +1 -1
- data/spec/spec_helper.rb +0 -10
- data/spec/unit/capabilities_spec.rb +198 -48
- data/spec/unit/match_elements/element_spec.rb +11 -0
- data/spec/watirspec/after_hooks_spec.rb +22 -45
- data/spec/watirspec/browser_spec.rb +185 -206
- data/spec/watirspec/cookies_spec.rb +47 -52
- data/spec/watirspec/drag_and_drop_spec.rb +5 -7
- data/spec/watirspec/elements/area_spec.rb +1 -5
- data/spec/watirspec/elements/button_spec.rb +4 -8
- data/spec/watirspec/elements/checkbox_spec.rb +2 -4
- data/spec/watirspec/elements/date_field_spec.rb +13 -16
- data/spec/watirspec/elements/date_time_field_spec.rb +14 -13
- data/spec/watirspec/elements/dd_spec.rb +3 -4
- data/spec/watirspec/elements/del_spec.rb +10 -12
- data/spec/watirspec/elements/div_spec.rb +41 -50
- data/spec/watirspec/elements/dl_spec.rb +4 -12
- data/spec/watirspec/elements/element_spec.rb +155 -89
- data/spec/watirspec/elements/elements_spec.rb +8 -9
- data/spec/watirspec/elements/filefield_spec.rb +5 -7
- data/spec/watirspec/elements/form_spec.rb +1 -1
- data/spec/watirspec/elements/forms_spec.rb +3 -5
- data/spec/watirspec/elements/frame_spec.rb +17 -22
- data/spec/watirspec/elements/iframe_spec.rb +21 -27
- data/spec/watirspec/elements/ins_spec.rb +10 -12
- data/spec/watirspec/elements/link_spec.rb +24 -26
- data/spec/watirspec/elements/links_spec.rb +8 -9
- data/spec/watirspec/elements/radio_spec.rb +11 -14
- data/spec/watirspec/elements/select_list_spec.rb +248 -117
- data/spec/watirspec/elements/span_spec.rb +10 -12
- data/spec/watirspec/elements/table_nesting_spec.rb +31 -34
- data/spec/watirspec/elements/table_spec.rb +11 -13
- data/spec/watirspec/elements/tbody_spec.rb +10 -12
- data/spec/watirspec/elements/td_spec.rb +4 -6
- data/spec/watirspec/elements/text_field_spec.rb +10 -12
- data/spec/watirspec/elements/tr_spec.rb +5 -7
- data/spec/watirspec/support/rspec_matchers.rb +1 -1
- data/spec/watirspec/user_editable_spec.rb +26 -28
- data/spec/watirspec/wait_spec.rb +255 -258
- data/spec/watirspec/window_switching_spec.rb +199 -200
- data/spec/watirspec_helper.rb +34 -31
- data/watir.gemspec +1 -1
- metadata +7 -8
- data/spec/implementation_spec.rb +0 -24
- data/spec/unit/logger_spec.rb +0 -81
@@ -332,6 +332,17 @@ describe Watir::Locators::Element::Matcher do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
context 'when matching Regular Expressions' do
|
335
|
+
it 'with white space' do
|
336
|
+
allow(browser).to receive(:execute_script).and_return("\n match this \n", 'no', 'match this')
|
337
|
+
|
338
|
+
elements = [wd_element,
|
339
|
+
wd_element,
|
340
|
+
wd_element]
|
341
|
+
@values_to_match = {text: /^match this$/}
|
342
|
+
|
343
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
344
|
+
end
|
345
|
+
|
335
346
|
it 'with tag_name' do
|
336
347
|
elements = [wd_element(tag_name: 'div'),
|
337
348
|
wd_element(tag_name: 'span'),
|
@@ -85,14 +85,12 @@ describe 'Browser::AfterHooks' do
|
|
85
85
|
expect(@yield).to be true
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
expect(@yield).to be true
|
95
|
-
end
|
88
|
+
it 'runs after_hooks after Element#submit' do
|
89
|
+
browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
|
90
|
+
@page_after_hook = proc { @yield = browser.div(id: 'messages').text == 'submit' }
|
91
|
+
browser.after_hooks.add @page_after_hook
|
92
|
+
browser.form(id: 'new_user').submit
|
93
|
+
expect(@yield).to be true
|
96
94
|
end
|
97
95
|
|
98
96
|
it 'runs after_hooks after Element#double_click' do
|
@@ -115,28 +113,6 @@ describe 'Browser::AfterHooks' do
|
|
115
113
|
expect(@yield).to be true
|
116
114
|
end
|
117
115
|
|
118
|
-
it 'runs after_hooks after FramedDriver#switch!' do
|
119
|
-
browser.goto(WatirSpec.url_for('iframes.html'))
|
120
|
-
@page_after_hook = proc { @yield = browser.title == 'Iframes' }
|
121
|
-
browser.after_hooks.add @page_after_hook
|
122
|
-
|
123
|
-
browser.iframe.element(css: '#senderElement').exists?
|
124
|
-
|
125
|
-
expect(@yield).to be true
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'runs after_hooks after Browser#ensure_context if not @default_context' do
|
129
|
-
browser.goto(WatirSpec.url_for('iframes.html'))
|
130
|
-
browser.iframe.element(css: '#senderElement').locate
|
131
|
-
|
132
|
-
@page_after_hook = proc { @yield = browser.title == 'Iframes' }
|
133
|
-
browser.after_hooks.add @page_after_hook
|
134
|
-
|
135
|
-
browser.locate
|
136
|
-
|
137
|
-
expect(@yield).to be true
|
138
|
-
end
|
139
|
-
|
140
116
|
it 'runs after_hooks after Alert#ok' do
|
141
117
|
browser.goto(WatirSpec.url_for('alerts.html'))
|
142
118
|
@page_after_hook = proc { @yield = browser.title == 'Alerts' }
|
@@ -187,21 +163,22 @@ describe 'Browser::AfterHooks' do
|
|
187
163
|
browser.alert.ok
|
188
164
|
end
|
189
165
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
166
|
+
it 'does not raise error when running error checks on closed window',
|
167
|
+
except: {browser: :safari,
|
168
|
+
reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
|
169
|
+
exclude: {browser: :firefox,
|
170
|
+
platform: :windows,
|
171
|
+
reason: 'https://github.com/mozilla/geckodriver/issues/1847'} do
|
172
|
+
url = WatirSpec.url_for('window_switching.html')
|
173
|
+
@page_after_hook = proc { browser.url }
|
174
|
+
browser.after_hooks.add @page_after_hook
|
175
|
+
browser.goto url
|
176
|
+
browser.a(id: 'open').click
|
177
|
+
|
178
|
+
window = browser.window(title: 'closeable window')
|
179
|
+
window.use
|
180
|
+
expect { browser.a(id: 'close').click }.to_not raise_error
|
181
|
+
browser.original_window.use
|
205
182
|
end
|
206
183
|
end
|
207
184
|
|
@@ -2,36 +2,56 @@ require 'watirspec_helper'
|
|
2
2
|
|
3
3
|
describe 'Browser' do
|
4
4
|
describe '#exists?' do
|
5
|
-
after do
|
6
|
-
browser.original_window.use
|
7
|
-
browser.windows.reject(&:current?).each(&:close)
|
8
|
-
end
|
9
|
-
|
10
5
|
it 'returns true if we are at a page' do
|
11
6
|
browser.goto(WatirSpec.url_for('non_control_elements.html'))
|
12
7
|
expect(browser).to exist
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
it 'returns false if window is closed',
|
11
|
+
except: {browser: :safari,
|
12
|
+
reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
|
13
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
14
|
+
browser.a(id: 'open').click
|
15
|
+
browser.windows.wait_until(size: 2)
|
16
|
+
browser.window(title: 'closeable window').use
|
17
|
+
browser.a(id: 'close').click
|
18
|
+
browser.windows.wait_until(size: 1)
|
19
|
+
expect(browser.exists?).to be false
|
20
|
+
ensure
|
21
|
+
browser.windows.restore!
|
25
22
|
end
|
26
23
|
|
27
24
|
it 'returns false after Browser#close' do
|
28
25
|
browser.close
|
29
26
|
expect(browser).to_not exist
|
30
|
-
$browser = WatirSpec.new_browser
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
34
|
-
#
|
30
|
+
describe '#closed?' do
|
31
|
+
it 'returns false if not closed' do
|
32
|
+
expect(browser).to_not be_closed
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns false if window is closed but browser is not',
|
36
|
+
except: {browser: :safari,
|
37
|
+
reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
|
38
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
39
|
+
browser.a(id: 'open').click
|
40
|
+
browser.windows.wait_until(size: 2)
|
41
|
+
browser.window(title: 'closeable window').use
|
42
|
+
browser.a(id: 'close').click
|
43
|
+
browser.windows.wait_until(size: 1)
|
44
|
+
expect(browser).to_not be_closed
|
45
|
+
ensure
|
46
|
+
browser.windows.restore!
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns false after Browser#close' do
|
50
|
+
browser.close
|
51
|
+
expect(browser).to be_closed
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
35
55
|
describe '#html' do
|
36
56
|
it 'returns the DOM of the page as an HTML string' do
|
37
57
|
browser.goto(WatirSpec.url_for('right_click.html'))
|
@@ -40,14 +60,7 @@ describe 'Browser' do
|
|
40
60
|
expect(html).to match(/^<html/)
|
41
61
|
expect(html).to include('<meta ')
|
42
62
|
expect(html).to include(' content="text/html; charset=utf-8"')
|
43
|
-
|
44
|
-
not_compliant_on :internet_explorer do
|
45
|
-
expect(html).to include(' http-equiv="content-type"')
|
46
|
-
end
|
47
|
-
|
48
|
-
deviates_on :internet_explorer do
|
49
|
-
expect(html).to include(' http-equiv=content-type')
|
50
|
-
end
|
63
|
+
expect(html).to match(/http-equiv=("|)content-type/)
|
51
64
|
end
|
52
65
|
end
|
53
66
|
|
@@ -59,12 +72,8 @@ describe 'Browser' do
|
|
59
72
|
end
|
60
73
|
|
61
74
|
describe '#status' do
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
# for IE9, this needs to be enabled in
|
66
|
-
# View => Toolbars -> Status bar
|
67
|
-
it 'returns the current value of window.status' do
|
75
|
+
it 'returns the current value of window.status',
|
76
|
+
except: {browser: :ie, reason: 'Status bar not enabled by default'} do
|
68
77
|
browser.goto(WatirSpec.url_for('non_control_elements.html'))
|
69
78
|
|
70
79
|
browser.execute_script "window.status = 'All done!';"
|
@@ -72,11 +81,9 @@ describe 'Browser' do
|
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
expect(browser.name).to eq(WatirSpec.implementation.browser_name)
|
79
|
-
end
|
84
|
+
describe '#name' do
|
85
|
+
it 'returns browser name' do
|
86
|
+
expect(browser.name).to eq(WatirSpec.implementation.browser_name)
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
@@ -112,12 +119,11 @@ describe 'Browser' do
|
|
112
119
|
expect(browser.text.strip).to eq 'This is text/plain'
|
113
120
|
end
|
114
121
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
122
|
+
it 'returns text of top most browsing context', except: {browser: :safari,
|
123
|
+
reason: 'Safari does not strip text'} do
|
124
|
+
browser.goto(WatirSpec.url_for('nested_iframes.html'))
|
125
|
+
browser.iframe(id: 'two').h3.exists?
|
126
|
+
expect(browser.text).to eq 'Top Layer'
|
121
127
|
end
|
122
128
|
end
|
123
129
|
|
@@ -150,201 +156,181 @@ describe 'Browser' do
|
|
150
156
|
|
151
157
|
# TODO: Temporarily disabling this before moving it to unit tests
|
152
158
|
xdescribe '#new' do
|
153
|
-
|
154
|
-
|
155
|
-
let(:url) { 'http://localhost:4544/wd/hub/' }
|
156
|
-
|
157
|
-
before(:all) do
|
158
|
-
@original = WatirSpec.implementation.clone
|
159
|
-
|
160
|
-
require 'watirspec/remote_server'
|
161
|
-
args = ["-Dwebdriver.chrome.driver=#{Webdrivers::Chromedriver.driver_path}",
|
162
|
-
"-Dwebdriver.gecko.driver=#{Webdrivers::Geckodriver.driver_path}"]
|
163
|
-
WatirSpec::RemoteServer.new.start(4544, args: args)
|
164
|
-
browser.close
|
165
|
-
end
|
159
|
+
context 'with parameters', except: {remote: true} do
|
160
|
+
let(:url) { 'http://localhost:4544/wd/hub/' }
|
166
161
|
|
167
|
-
|
168
|
-
|
169
|
-
end
|
162
|
+
before(:all) do
|
163
|
+
@original = WatirSpec.implementation.clone
|
170
164
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
165
|
+
require 'watirspec/remote_server'
|
166
|
+
args = ["-Dwebdriver.chrome.driver=#{Webdrivers::Chromedriver.driver_path}",
|
167
|
+
"-Dwebdriver.gecko.driver=#{Webdrivers::Geckodriver.driver_path}"]
|
168
|
+
WatirSpec::RemoteServer.new.start(4544, args: args)
|
169
|
+
browser.close
|
170
|
+
end
|
175
171
|
|
176
|
-
|
177
|
-
|
178
|
-
|
172
|
+
before(:each) do
|
173
|
+
@opts = WatirSpec.implementation.browser_args.last
|
174
|
+
end
|
179
175
|
|
180
|
-
|
181
|
-
|
182
|
-
|
176
|
+
after(:each) do
|
177
|
+
@new_browser.close
|
178
|
+
WatirSpec.implementation = @original.clone
|
179
|
+
end
|
183
180
|
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
it 'uses remote client based on provided url' do
|
182
|
+
@opts[:url] = url
|
183
|
+
@new_browser = WatirSpec.new_browser
|
187
184
|
|
188
|
-
|
189
|
-
|
190
|
-
|
185
|
+
server_url = @new_browser.driver.instance_variable_get('@bridge').http.instance_variable_get('@server_url')
|
186
|
+
expect(server_url).to eq URI.parse(url)
|
187
|
+
end
|
191
188
|
|
192
|
-
|
189
|
+
it 'sets client timeout' do
|
190
|
+
@opts.merge!(url: url, open_timeout: 44, read_timeout: 47)
|
191
|
+
@new_browser = WatirSpec.new_browser
|
193
192
|
|
194
|
-
|
195
|
-
expect(http.read_timeout).to eq 47
|
196
|
-
end
|
193
|
+
http = @new_browser.driver.instance_variable_get('@bridge').http
|
197
194
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
@opts[:http_client] = http_client
|
202
|
-
@new_browser = WatirSpec.new_browser
|
195
|
+
expect(http.open_timeout).to eq 44
|
196
|
+
expect(http.read_timeout).to eq 47
|
197
|
+
end
|
203
198
|
|
204
|
-
|
205
|
-
|
199
|
+
it 'accepts http_client' do
|
200
|
+
http_client = Selenium::WebDriver::Remote::Http::Default.new
|
201
|
+
@opts[:url] = url
|
202
|
+
@opts[:http_client] = http_client
|
203
|
+
@new_browser = WatirSpec.new_browser
|
206
204
|
|
207
|
-
|
208
|
-
|
209
|
-
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
210
|
-
@opts[:url] = url
|
211
|
-
@opts[:desired_capabilities] = caps
|
205
|
+
expect(@new_browser.driver.instance_variable_get('@bridge').http).to eq http_client
|
206
|
+
end
|
212
207
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
208
|
+
it 'accepts Remote::Capabilities instance as :desired_capabilities', only: {browser: :firefox} do
|
209
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
210
|
+
@opts[:url] = url
|
211
|
+
@opts[:desired_capabilities] = caps
|
212
|
+
|
213
|
+
msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
|
214
|
+
expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
|
215
|
+
expect(@new_browser.driver.capabilities.accept_insecure_certs).to eq true
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'accepts individual driver capabilities', only: {browser: :firefox} do
|
219
|
+
@opts[:accept_insecure_certs] = true
|
220
|
+
@new_browser = WatirSpec.new_browser
|
221
|
+
|
222
|
+
expect(@new_browser.driver.capabilities[:accept_insecure_certs]).to eq true
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'accepts profile', only: {browser: :firefox} do
|
226
|
+
home_page = WatirSpec.url_for('special_chars.html')
|
227
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
228
|
+
profile['browser.startup.homepage'] = home_page
|
229
|
+
profile['browser.startup.page'] = 1
|
230
|
+
@opts[:profile] = profile
|
231
|
+
|
232
|
+
@new_browser = WatirSpec.new_browser
|
233
|
+
|
234
|
+
expect(@new_browser.url).to eq home_page
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'chrome arguments', only: {browser: :chrome} do
|
238
|
+
it 'accepts browser options' do
|
239
|
+
@opts[:options] = {emulation: {userAgent: 'foo;bar'}}
|
218
240
|
|
219
|
-
|
220
|
-
it 'accepts individual driver capabilities' do
|
221
|
-
@opts[:accept_insecure_certs] = true
|
222
|
-
@new_browser = WatirSpec.new_browser
|
241
|
+
@new_browser = WatirSpec.new_browser
|
223
242
|
|
224
|
-
|
225
|
-
|
243
|
+
ua = @new_browser.execute_script 'return window.navigator.userAgent'
|
244
|
+
expect(ua).to eq('foo;bar')
|
226
245
|
end
|
227
246
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
247
|
+
it 'uses remote client when specifying remote' do
|
248
|
+
opts = {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
249
|
+
url: url}
|
250
|
+
WatirSpec.implementation.browser_args = [:remote, opts]
|
251
|
+
msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
|
252
|
+
expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
|
253
|
+
server_url = @new_browser.driver.instance_variable_get('@bridge').http.instance_variable_get('@server_url')
|
254
|
+
expect(server_url).to eq URI.parse(url)
|
255
|
+
end
|
235
256
|
|
236
|
-
|
257
|
+
it 'accepts switches argument' do
|
258
|
+
@opts.delete :args
|
259
|
+
@opts[:switches] = ['--window-size=600,700']
|
237
260
|
|
238
|
-
|
239
|
-
|
261
|
+
@new_browser = WatirSpec.new_browser
|
262
|
+
size = @new_browser.window.size
|
263
|
+
expect(size['height']).to eq 700
|
264
|
+
expect(size['width']).to eq 600
|
240
265
|
end
|
241
266
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
it 'uses remote client when specifying remote' do
|
253
|
-
opts = {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
254
|
-
url: url}
|
255
|
-
WatirSpec.implementation.browser_args = [:remote, opts]
|
256
|
-
msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
|
257
|
-
expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
|
258
|
-
server_url = @new_browser.driver.instance_variable_get('@bridge').http.instance_variable_get('@server_url')
|
259
|
-
expect(server_url).to eq URI.parse(url)
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'accepts switches argument' do
|
263
|
-
@opts.delete :args
|
264
|
-
@opts[:switches] = ['--window-size=600,700']
|
265
|
-
|
266
|
-
@new_browser = WatirSpec.new_browser
|
267
|
-
size = @new_browser.window.size
|
268
|
-
expect(size['height']).to eq 700
|
269
|
-
expect(size['width']).to eq 600
|
270
|
-
end
|
271
|
-
|
272
|
-
not_compliant_on :headless do
|
273
|
-
it 'accepts Chrome::Options instance as :options' do
|
274
|
-
chrome_opts = Selenium::WebDriver::Chrome::Options.new(emulation: {userAgent: 'foo;bar'})
|
275
|
-
@opts.delete :args
|
276
|
-
@opts[:options] = chrome_opts
|
277
|
-
|
278
|
-
@new_browser = WatirSpec.new_browser
|
279
|
-
|
280
|
-
ua = @new_browser.execute_script 'return window.navigator.userAgent'
|
281
|
-
expect(ua).to eq('foo;bar')
|
282
|
-
end
|
283
|
-
end
|
267
|
+
it 'accepts Chrome::Options instance as :options', except: {headless: true} do
|
268
|
+
chrome_opts = Selenium::WebDriver::Chrome::Options.new(emulation: {userAgent: 'foo;bar'})
|
269
|
+
@opts.delete :args
|
270
|
+
@opts[:options] = chrome_opts
|
271
|
+
|
272
|
+
@new_browser = WatirSpec.new_browser
|
273
|
+
|
274
|
+
ua = @new_browser.execute_script 'return window.navigator.userAgent'
|
275
|
+
expect(ua).to eq('foo;bar')
|
284
276
|
end
|
285
277
|
end
|
278
|
+
end
|
286
279
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
@opts = WatirSpec.implementation.browser_args.last
|
293
|
-
browser_name = WatirSpec.implementation.browser_args.first
|
280
|
+
it 'takes service as argument', only: {browser: :chrome} do
|
281
|
+
@original = WatirSpec.implementation.clone
|
282
|
+
browser.close
|
283
|
+
@opts = WatirSpec.implementation.browser_args.last
|
284
|
+
browser_name = WatirSpec.implementation.browser_args.first
|
294
285
|
|
295
|
-
|
286
|
+
service = Selenium::WebDriver::Service.send(browser_name, port: '2314', args: ['foo'])
|
296
287
|
|
297
|
-
|
298
|
-
|
288
|
+
@opts.merge!(service: service,
|
289
|
+
listener: LocalConfig::SelectorListener.new)
|
299
290
|
|
300
|
-
|
291
|
+
@new_browser = WatirSpec.new_browser
|
301
292
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
293
|
+
bridge = @new_browser.wd.instance_variable_get('@bridge')
|
294
|
+
expect(bridge).to be_a Selenium::WebDriver::Support::EventFiringBridge
|
295
|
+
service = @new_browser.wd.instance_variable_get('@service')
|
296
|
+
expect(service.instance_variable_get('@extra_args')).to eq ['foo']
|
297
|
+
expect(service.instance_variable_get('@port')).to eq 2314
|
307
298
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
end
|
313
|
-
end
|
299
|
+
@new_browser.close
|
300
|
+
ensure
|
301
|
+
WatirSpec.implementation = @original.clone
|
302
|
+
end
|
314
303
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
304
|
+
it 'takes a driver instance as argument' do
|
305
|
+
mock_driver = double(Selenium::WebDriver::Driver)
|
306
|
+
expect(Selenium::WebDriver::Driver).to receive(:===).with(mock_driver).and_return(true)
|
307
|
+
expect { Watir::Browser.new(mock_driver) }.to_not raise_error
|
308
|
+
end
|
320
309
|
|
321
|
-
|
322
|
-
|
323
|
-
end
|
310
|
+
it 'raises ArgumentError for invalid args' do
|
311
|
+
expect { Watir::Browser.new(Object.new) }.to raise_error(ArgumentError)
|
324
312
|
end
|
325
313
|
end
|
326
314
|
|
327
315
|
describe '.start' do
|
328
316
|
it 'goes to the given URL and return an instance of itself' do
|
329
317
|
browser.close
|
318
|
+
sleep 1
|
330
319
|
driver, args = WatirSpec.implementation.browser_args
|
331
320
|
b = Watir::Browser.start(WatirSpec.url_for('non_control_elements.html'), driver, args.dup)
|
332
321
|
|
333
322
|
expect(b).to be_instance_of(Watir::Browser)
|
334
323
|
expect(b.title).to eq 'Non-control elements'
|
335
324
|
b.close
|
336
|
-
$browser = WatirSpec.new_browser
|
337
325
|
end
|
338
326
|
end
|
339
327
|
|
340
328
|
describe '#goto' do
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
expect(browser.url).to match(%r{http://#{url}/?})
|
347
|
-
end
|
329
|
+
it 'adds http:// to URLs with no URL scheme specified' do
|
330
|
+
url = WatirSpec.host[%r{http://(.*)}, 1]
|
331
|
+
expect(url).to_not be_nil
|
332
|
+
browser.goto(url)
|
333
|
+
expect(browser.url).to match(%r{http://#{url}/?})
|
348
334
|
end
|
349
335
|
|
350
336
|
it 'goes to the given url without raising errors' do
|
@@ -355,21 +341,18 @@ describe 'Browser' do
|
|
355
341
|
expect { browser.goto('about:blank') }.to_not raise_error
|
356
342
|
end
|
357
343
|
|
358
|
-
|
359
|
-
|
360
|
-
expect { browser.goto('data:text/html;content-type=utf-8,foobar') }.to_not raise_error
|
361
|
-
end
|
344
|
+
it 'goes to a data URL scheme address without raising errors' do
|
345
|
+
expect { browser.goto('data:text/html;content-type=utf-8,foobar') }.to_not raise_error
|
362
346
|
end
|
363
347
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
end
|
348
|
+
it "goes to internal Chrome URL 'chrome://settings/browser' without raising errors",
|
349
|
+
exclusive: {browser: %i[chrome edge]} do
|
350
|
+
expect { browser.goto('chrome://settings/browser') }.to_not raise_error
|
368
351
|
end
|
369
352
|
|
370
353
|
it 'updates the page when location is changed with setTimeout + window.location' do
|
371
354
|
browser.goto(WatirSpec.url_for('timeout_window_location.html'))
|
372
|
-
|
355
|
+
browser.wait_while { |b| b.url.include? 'timeout_window_location.html' }
|
373
356
|
expect(browser.url).to include('non_control_elements.html')
|
374
357
|
end
|
375
358
|
end
|
@@ -378,10 +361,7 @@ describe 'Browser' do
|
|
378
361
|
it 'refreshes the page' do
|
379
362
|
browser.goto(WatirSpec.url_for('non_control_elements.html'))
|
380
363
|
|
381
|
-
|
382
|
-
browser.div(id: 'best_language').scroll.to
|
383
|
-
end
|
384
|
-
|
364
|
+
browser.div(id: 'best_language').scroll.to
|
385
365
|
browser.div(id: 'best_language').click
|
386
366
|
expect(browser.div(id: 'best_language').text).to include('Ruby!')
|
387
367
|
browser.refresh
|
@@ -501,7 +481,6 @@ describe 'Browser' do
|
|
501
481
|
browser.close
|
502
482
|
|
503
483
|
expect { browser.dl(id: 'experience-list').id }.to raise_error(Watir::Exception::Error, 'browser was closed')
|
504
|
-
$browser = WatirSpec.new_browser
|
505
484
|
end
|
506
485
|
|
507
486
|
describe '#ready_state' do
|
@@ -531,8 +510,8 @@ describe 'Browser' do
|
|
531
510
|
expect(browser.ready_state).to eq 'complete'
|
532
511
|
|
533
512
|
browser.close
|
513
|
+
ensure
|
534
514
|
WatirSpec.implementation = @original.clone
|
535
|
-
$browser = WatirSpec.new_browser
|
536
515
|
end
|
537
516
|
end
|
538
517
|
|