watir 6.17.0 → 6.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/actions/enable-safari/action.yml +11 -0
- data/.github/actions/install-chrome/action.yml +11 -0
- data/.github/workflows/linux.yml +61 -0
- data/.github/workflows/mac.yml +55 -0
- data/.github/workflows/unit.yml +31 -0
- data/.github/workflows/windows.yml +39 -0
- data/.rubocop_todo.yml +36 -0
- data/CHANGES.md +14 -0
- data/LICENSE +2 -2
- data/README.md +9 -10
- data/Rakefile +1 -1
- data/lib/watir.rb +1 -0
- data/lib/watir/adjacent.rb +1 -1
- data/lib/watir/alert.rb +1 -0
- data/lib/watir/attribute_helper.rb +2 -0
- data/lib/watir/browser.rb +2 -2
- data/lib/watir/cookies.rb +2 -0
- data/lib/watir/element_collection.rb +21 -6
- data/lib/watir/elements/element.rb +10 -10
- data/lib/watir/elements/html_elements.rb +0 -1
- data/lib/watir/elements/iframe.rb +2 -1
- data/lib/watir/elements/select.rb +20 -5
- data/lib/watir/generator/html/generator.rb +1 -1
- data/lib/watir/has_window.rb +17 -15
- data/lib/watir/js_execution.rb +2 -2
- data/lib/watir/js_snippets.rb +2 -2
- data/lib/watir/locators.rb +1 -3
- data/lib/watir/locators/element/selector_builder.rb +1 -1
- data/lib/watir/logger.rb +2 -18
- data/lib/watir/radio_set.rb +2 -2
- data/lib/watir/user_editable.rb +6 -2
- data/lib/watir/version.rb +1 -1
- data/lib/watir/wait.rb +2 -0
- data/lib/watir/wait/timer.rb +1 -1
- data/lib/watir/window.rb +7 -3
- data/lib/watir/window_collection.rb +105 -0
- data/lib/watirspec.rb +1 -0
- data/lib/watirspec/implementation.rb +3 -5
- data/lib/watirspec/runner.rb +1 -1
- data/lib/watirspec/server.rb +1 -1
- data/spec/spec_helper.rb +2 -7
- data/spec/unit/match_elements/element_spec.rb +17 -15
- data/spec/unit/unit_helper.rb +2 -4
- data/spec/watirspec/after_hooks_spec.rb +15 -11
- data/spec/watirspec/browser_spec.rb +3 -2
- data/spec/watirspec/elements/element_spec.rb +14 -11
- data/spec/watirspec/elements/filefield_spec.rb +2 -2
- data/spec/watirspec/elements/iframe_spec.rb +5 -7
- data/spec/watirspec/elements/link_spec.rb +5 -3
- data/spec/watirspec/elements/select_list_spec.rb +156 -37
- data/spec/watirspec/html/wait.html +5 -5
- data/spec/watirspec/html/window_switching.html +10 -0
- data/spec/watirspec/legacy_wait_spec.rb +216 -0
- data/spec/watirspec/support/rspec_matchers.rb +10 -7
- data/spec/watirspec/wait_spec.rb +257 -301
- data/spec/watirspec/window_switching_spec.rb +282 -160
- data/spec/watirspec_helper.rb +10 -15
- data/support/doctest_helper.rb +0 -2
- data/watir.gemspec +2 -2
- metadata +25 -13
- data/.travis.yml +0 -87
- data/appveyor.yml +0 -13
- data/spec/watirspec/relaxed_locate_spec.rb +0 -109
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'watirspec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Watir::Browser do
|
4
4
|
before do
|
5
|
-
|
6
|
-
browser.goto url
|
5
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
7
6
|
browser.a(id: 'open').click
|
8
|
-
|
7
|
+
browser.windows.wait_until(size: 2)
|
9
8
|
end
|
10
9
|
|
11
10
|
after do
|
@@ -14,14 +13,15 @@ describe 'Browser' do
|
|
14
13
|
end
|
15
14
|
|
16
15
|
describe '#windows' do
|
17
|
-
it 'returns
|
18
|
-
|
19
|
-
expect(wins).to_not be_empty
|
20
|
-
wins.each { |win| expect(win).to be_kind_of(Watir::Window) }
|
16
|
+
it 'returns a WindowCollection' do
|
17
|
+
expect(browser.windows).to be_a(Watir::WindowCollection)
|
21
18
|
end
|
22
19
|
|
23
|
-
it '
|
24
|
-
browser.
|
20
|
+
it 'stores Window instances' do
|
21
|
+
expect(browser.windows(title: 'closeable window')).to all(be_a(Watir::Window))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'filters windows to match the given selector' do
|
25
25
|
expect(browser.windows(title: 'closeable window').size).to eq 1
|
26
26
|
end
|
27
27
|
|
@@ -30,24 +30,31 @@ describe 'Browser' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns an empty array if no window matches the selector' do
|
33
|
-
expect(browser.windows(title: 'noop')).to
|
33
|
+
expect(browser.windows(title: 'noop')).to be_empty
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#window' do
|
38
38
|
it 'finds window by :url' do
|
39
|
-
|
40
|
-
expect(w).to be_kind_of(Watir::Window)
|
39
|
+
expect(browser.window(url: /closeable\.html/).use).to be_a(Watir::Window)
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'finds window by :title' do
|
44
|
-
|
45
|
-
expect(w).to be_kind_of(Watir::Window)
|
43
|
+
expect(browser.window(title: 'closeable window').use).to be_a(Watir::Window)
|
46
44
|
end
|
47
45
|
|
48
46
|
it 'finds window by :index' do
|
49
|
-
|
50
|
-
|
47
|
+
expect {
|
48
|
+
expect(browser.window(index: 1).use).to be_a(Watir::Window)
|
49
|
+
}.to have_deprecated_window_index
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'finds window by :element' do
|
53
|
+
expect(browser.window(element: browser.a(id: 'close')).use).to be_a(Watir::Window)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'finds window by multiple values' do
|
57
|
+
expect(browser.window(title: 'closeable window', url: /closeable\.html/).use).to be_a(Watir::Window)
|
51
58
|
end
|
52
59
|
|
53
60
|
it 'should not find incorrect handle' do
|
@@ -66,13 +73,13 @@ describe 'Browser' do
|
|
66
73
|
|
67
74
|
bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
|
68
75
|
it 'it executes the given block in the window' do
|
69
|
-
browser.window(title: 'closeable window')
|
76
|
+
browser.window(title: 'closeable window') do
|
70
77
|
link = browser.a(id: 'close')
|
71
78
|
expect(link).to exist
|
72
79
|
link.click
|
73
|
-
|
80
|
+
end
|
74
81
|
|
75
|
-
expect
|
82
|
+
expect { browser.windows.wait_until(size: 1) }.to_not raise_error
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
@@ -85,21 +92,57 @@ describe 'Browser' do
|
|
85
92
|
end
|
86
93
|
|
87
94
|
it "raises a NoMatchingWindowFoundException error if there's no window at the given index" do
|
88
|
-
expect {
|
95
|
+
expect {
|
96
|
+
expect { browser.window(index: 100).use }.to raise_no_matching_window_exception
|
97
|
+
}.to have_deprecated_window_index
|
89
98
|
end
|
90
99
|
|
91
100
|
it 'raises NoMatchingWindowFoundException error when attempting to use a window with an incorrect handle' do
|
92
101
|
expect { browser.window(handle: 'bar').use }.to raise_no_matching_window_exception
|
93
102
|
end
|
94
103
|
end
|
104
|
+
|
105
|
+
describe '#switch_window' do
|
106
|
+
it 'switches to second window' do
|
107
|
+
original_window = browser.window
|
108
|
+
browser.switch_window
|
109
|
+
new_window = browser.window
|
110
|
+
|
111
|
+
expect(original_window).to_not eq new_window
|
112
|
+
expect(browser.windows).to include(original_window, new_window)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns an instance of Window' do
|
116
|
+
expect(browser.switch_window).to be_a(Watir::Window)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'times out if there is no second window' do
|
120
|
+
browser.windows.reject(&:current?).each(&:close)
|
121
|
+
message = /waiting for true condition on (.*) title="window switching">$/
|
122
|
+
expect { browser.switch_window }.to raise_timeout_exception(message)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'provides previous window value to #original_window' do
|
126
|
+
browser.switch_window
|
127
|
+
expect(browser.original_window).to_not be_nil
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'waits for second window' do
|
131
|
+
browser.windows.reject(&:current?).each(&:close)
|
132
|
+
expect {
|
133
|
+
browser.a(id: 'delayed').click
|
134
|
+
browser.switch_window
|
135
|
+
}.to execute_when_satisfied(min: 1)
|
136
|
+
end
|
137
|
+
end
|
95
138
|
end
|
96
139
|
|
97
|
-
describe
|
140
|
+
describe Watir::Window do
|
98
141
|
context 'multiple windows' do
|
99
142
|
before do
|
100
143
|
browser.goto WatirSpec.url_for('window_switching.html')
|
101
144
|
browser.a(id: 'open').click
|
102
|
-
|
145
|
+
browser.windows.wait_until(size: 2)
|
103
146
|
end
|
104
147
|
|
105
148
|
after do
|
@@ -110,7 +153,8 @@ describe 'Window' do
|
|
110
153
|
bug 'Focus is on newly opened window instead of the first', :safari do
|
111
154
|
it 'allows actions on first window after opening second' do
|
112
155
|
browser.a(id: 'open').click
|
113
|
-
|
156
|
+
|
157
|
+
expect { browser.windows.wait_until(size: 3) }.to_not raise_timeout_exception
|
114
158
|
end
|
115
159
|
end
|
116
160
|
|
@@ -119,20 +163,21 @@ describe 'Window' do
|
|
119
163
|
it 'closes a window' do
|
120
164
|
browser.window(title: 'window switching').use
|
121
165
|
browser.a(id: 'open').click
|
122
|
-
|
166
|
+
browser.windows.wait_until(size: 3)
|
167
|
+
|
168
|
+
Watir::Window.new(browser, title: 'closeable window').close
|
123
169
|
|
124
|
-
browser.
|
125
|
-
expect(browser.windows.size).to eq 2
|
170
|
+
expect { browser.windows.wait_until(size: 2) }.to_not raise_timeout_exception
|
126
171
|
end
|
127
172
|
|
128
173
|
bug 'Focus is on newly opened window instead of the first', :safari do
|
129
174
|
it 'closes the current window' do
|
130
175
|
browser.a(id: 'open').click
|
131
|
-
|
176
|
+
browser.windows.wait_until(size: 3)
|
132
177
|
|
133
|
-
|
134
|
-
|
135
|
-
expect
|
178
|
+
Watir::Window.new(browser, title: 'closeable window').use.close
|
179
|
+
|
180
|
+
expect { browser.windows.wait_until(size: 2) }.to_not raise_timeout_exception
|
136
181
|
end
|
137
182
|
end
|
138
183
|
end
|
@@ -140,194 +185,179 @@ describe 'Window' do
|
|
140
185
|
|
141
186
|
describe '#use' do
|
142
187
|
it 'switches to the window' do
|
143
|
-
|
188
|
+
Watir::Window.new(browser, title: 'closeable window').use
|
144
189
|
expect(browser.title).to eq 'closeable window'
|
145
190
|
end
|
146
191
|
end
|
147
192
|
|
148
193
|
describe '#current?' do
|
149
194
|
it 'returns true if it is the current window' do
|
150
|
-
expect(
|
195
|
+
expect(Watir::Window.new(browser, title: browser.title)).to be_current
|
151
196
|
end
|
152
197
|
|
153
198
|
it 'returns false if it is not the current window' do
|
154
|
-
expect(
|
199
|
+
expect(Watir::Window.new(browser, title: 'closeable window')).to_not be_current
|
155
200
|
end
|
156
201
|
end
|
157
202
|
|
158
203
|
describe '#title' do
|
159
204
|
it 'returns the title of the window' do
|
160
205
|
titles = browser.windows.map(&:title)
|
161
|
-
expect(titles.size).to eq 2
|
162
|
-
|
163
|
-
expect(titles.sort).to eq ['window switching', 'closeable window'].sort
|
164
|
-
end
|
165
206
|
|
166
|
-
|
167
|
-
expect(
|
168
|
-
expect(browser.windows.find { |w| w.title == 'closeable window' }).to_not be_nil
|
169
|
-
expect(browser.title).to eq 'window switching'
|
207
|
+
expect(titles.size).to eq 2
|
208
|
+
expect(titles).to include 'window switching', 'closeable window'
|
170
209
|
end
|
171
210
|
end
|
172
211
|
|
173
212
|
describe '#url' do
|
174
213
|
it 'returns the url of the window' do
|
175
|
-
|
176
|
-
expect(browser.windows.select { |w| w.url =~ /closeable\.html$/ }.size).to eq 1
|
177
|
-
end
|
214
|
+
urls = browser.windows.map(&:url)
|
178
215
|
|
179
|
-
|
180
|
-
expect(
|
181
|
-
expect(browser.windows.find { |w| w.url =~ /closeable\.html/ }).to_not be_nil
|
182
|
-
expect(browser.url).to match(/window_switching/)
|
216
|
+
expect(urls.size).to eq 2
|
217
|
+
expect(urls).to(include(/window_switching\.html/, /closeable\.html$/))
|
183
218
|
end
|
184
219
|
end
|
185
220
|
|
186
221
|
describe '#eql?' do
|
187
222
|
it 'knows when two windows are equal' do
|
188
|
-
|
223
|
+
win1 = Watir::Window.new browser, {}
|
224
|
+
win2 = Watir::Window.new browser, title: 'window switching'
|
225
|
+
|
226
|
+
expect(win1).to eq win2
|
189
227
|
end
|
190
228
|
|
191
229
|
it 'knows when two windows are not equal' do
|
192
|
-
win1 = browser
|
193
|
-
win2 = browser
|
230
|
+
win1 = Watir::Window.new browser, title: 'closeable window'
|
231
|
+
win2 = Watir::Window.new browser, title: 'window switching'
|
194
232
|
|
195
233
|
expect(win1).to_not eq win2
|
196
234
|
end
|
197
235
|
end
|
198
236
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
237
|
+
describe '#handle' do
|
238
|
+
it 'does not find if not matching' do
|
239
|
+
expect(browser.window(title: 'noop').handle).to be_nil
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'finds window by :url' do
|
243
|
+
expect(browser.window(url: /closeable\.html/).handle).to_not be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'finds window by :title' do
|
247
|
+
expect(browser.window(title: 'closeable window').handle).to_not be_nil
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'finds window by :index' do
|
251
|
+
expect {
|
252
|
+
expect(browser.window(index: 1).handle).to_not be_nil
|
253
|
+
}.to have_deprecated_window_index
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'finds window by :element' do
|
257
|
+
expect(browser.window(element: browser.a(id: 'close')).handle).to_not be_nil
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'finds window by multiple values' do
|
261
|
+
expect(browser.window(url: /closeable\.html/, title: 'closeable window').handle).to_not be_nil
|
206
262
|
end
|
207
263
|
end
|
208
264
|
end
|
209
265
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
266
|
+
bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
|
267
|
+
context 'with a closed window' do
|
268
|
+
before do
|
269
|
+
@original_window = browser.window
|
270
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
271
|
+
browser.a(id: 'open').click
|
272
|
+
browser.windows.wait_until(size: 2)
|
273
|
+
@handles = browser.driver.window_handles
|
274
|
+
@closed_window = browser.window(title: 'closeable window').use
|
275
|
+
browser.a(id: 'close').click
|
276
|
+
browser.windows.wait_until(size: 1)
|
277
|
+
end
|
216
278
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
279
|
+
after do
|
280
|
+
browser.original_window.use
|
281
|
+
browser.windows.reject(&:current?).each(&:close)
|
282
|
+
end
|
221
283
|
|
222
|
-
bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
|
223
284
|
describe '#exists?' do
|
224
285
|
it 'returns false if previously referenced window is closed' do
|
225
|
-
|
226
|
-
window.use
|
227
|
-
browser.a(id: 'close').click
|
228
|
-
Watir::Wait.until { browser.windows.size == 1 }
|
229
|
-
expect(window).to_not be_present
|
286
|
+
expect(@closed_window).to_not be_present
|
230
287
|
end
|
231
288
|
|
232
289
|
it 'returns false if closed window is referenced' do
|
233
|
-
browser.window(title: 'closeable window').use
|
234
|
-
browser.a(id: 'close').click
|
235
|
-
Watir::Wait.until { browser.windows.size == 1 }
|
236
290
|
expect(browser.window).to_not exist
|
237
291
|
end
|
292
|
+
end
|
238
293
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
handles = browser.windows.map { |w| w.instance_variable_get('@handle') }
|
243
|
-
|
244
|
-
browser.a(id: 'close').click
|
245
|
-
Watir::Wait.until { browser.windows.size == 1 }
|
246
|
-
allow(browser.wd).to receive(:window_handles).and_return(handles, [original_handle])
|
247
|
-
expect(browser.window(title: 'closeable window')).to_not exist
|
294
|
+
describe '#current?' do
|
295
|
+
it 'returns false if the referenced window is closed' do
|
296
|
+
expect(@original_window).to_not be_current
|
248
297
|
end
|
249
298
|
end
|
250
|
-
end
|
251
|
-
describe '#current?' do
|
252
|
-
it 'returns false if the referenced window is closed' do
|
253
|
-
original_window = browser.window
|
254
|
-
browser.window(title: 'closeable window').use
|
255
|
-
original_window.close
|
256
|
-
expect(original_window).to_not be_current
|
257
|
-
end
|
258
|
-
end
|
259
299
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
other_window.use
|
265
|
-
original_window.close
|
266
|
-
expect(other_window == original_window).to be false
|
300
|
+
describe '#eql?' do
|
301
|
+
it 'should return false when checking equivalence to a closed window' do
|
302
|
+
expect(browser.window).not_to eq @closed_widow
|
303
|
+
end
|
267
304
|
end
|
268
|
-
end
|
269
305
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
original_window.close
|
275
|
-
expect { original_window.use }.to raise_no_matching_window_exception
|
276
|
-
end
|
306
|
+
describe '#use' do
|
307
|
+
it 'raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed' do
|
308
|
+
expect { @closed_window.use }.to raise_no_matching_window_exception
|
309
|
+
end
|
277
310
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
Watir::Wait.until { browser.windows.size == 1 }
|
283
|
-
expect { browser.window.use }.to raise_no_matching_window_exception
|
311
|
+
bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
|
312
|
+
it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
|
313
|
+
expect { browser.window.use }.to raise_no_matching_window_exception
|
314
|
+
end
|
284
315
|
end
|
285
316
|
end
|
286
|
-
end
|
287
317
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
msg = 'browser window was closed'
|
294
|
-
expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
|
318
|
+
bug 'https://github.com/mozilla/geckodriver/issues/1847', :firefox do
|
319
|
+
it 'raises an exception when using an element on a closed window' do
|
320
|
+
msg = 'browser window was closed'
|
321
|
+
expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
|
322
|
+
end
|
295
323
|
end
|
296
|
-
end
|
297
324
|
|
298
|
-
bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
|
299
325
|
it 'raises an exception when locating a closed window' do
|
300
|
-
browser.window(title: 'closeable window').use
|
301
|
-
handles = browser.windows.map(&:handle)
|
302
|
-
browser.a(id: 'close').click
|
303
|
-
allow(browser.wd).to receive(:window_handles).and_return(handles, [browser.original_window.handle])
|
304
326
|
expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
|
305
327
|
end
|
306
328
|
end
|
329
|
+
end
|
307
330
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
331
|
+
context 'with a closed window on a delay' do
|
332
|
+
after do
|
333
|
+
browser.original_window.use
|
334
|
+
browser.windows.reject(&:current?).each(&:close)
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'raises an exception when locating a window closed during lookup' do
|
338
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
339
|
+
browser.a(id: 'open').click
|
340
|
+
browser.windows.wait_until(size: 2)
|
341
|
+
browser.window(title: 'closeable window').use
|
342
|
+
browser.a(id: 'close-delay').click
|
312
343
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
344
|
+
begin
|
345
|
+
module Watir
|
346
|
+
class Browser
|
347
|
+
alias title_old title
|
317
348
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
end
|
349
|
+
def title
|
350
|
+
sleep 0.5
|
351
|
+
title_old
|
322
352
|
end
|
323
353
|
end
|
354
|
+
end
|
324
355
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
end
|
356
|
+
expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
|
357
|
+
ensure
|
358
|
+
module Watir
|
359
|
+
class Browser
|
360
|
+
alias title title_old
|
331
361
|
end
|
332
362
|
end
|
333
363
|
end
|
@@ -339,10 +369,10 @@ describe 'Window' do
|
|
339
369
|
before do
|
340
370
|
browser.goto WatirSpec.url_for('window_switching.html')
|
341
371
|
browser.a(id: 'open').click
|
342
|
-
|
372
|
+
browser.windows.wait_until(size: 2)
|
343
373
|
browser.window(title: 'closeable window').use
|
344
374
|
browser.a(id: 'close').click
|
345
|
-
|
375
|
+
browser.windows.wait_until(size: 1)
|
346
376
|
end
|
347
377
|
|
348
378
|
after do
|
@@ -352,7 +382,9 @@ describe 'Window' do
|
|
352
382
|
|
353
383
|
describe '#present?' do
|
354
384
|
it 'should find window by index' do
|
355
|
-
expect
|
385
|
+
expect {
|
386
|
+
expect(browser.window(index: 0)).to be_present
|
387
|
+
}.to have_deprecated_window_index
|
356
388
|
end
|
357
389
|
|
358
390
|
it 'should find window by url' do
|
@@ -362,12 +394,16 @@ describe 'Window' do
|
|
362
394
|
it 'should find window by title' do
|
363
395
|
expect(browser.window(title: 'window switching')).to be_present
|
364
396
|
end
|
397
|
+
|
398
|
+
it 'should find window by element' do
|
399
|
+
expect(browser.window(element: browser.link(id: 'open'))).to be_present
|
400
|
+
end
|
365
401
|
end
|
366
402
|
|
367
403
|
describe '#use' do
|
368
404
|
context 'switching windows without blocks' do
|
369
405
|
it 'by index' do
|
370
|
-
browser.window(index: 0).use
|
406
|
+
expect { browser.window(index: 0).use }.to have_deprecated_window_index
|
371
407
|
expect(browser.title).to be == 'window switching'
|
372
408
|
end
|
373
409
|
|
@@ -380,11 +416,18 @@ describe 'Window' do
|
|
380
416
|
browser.window(title: 'window switching').use
|
381
417
|
expect(browser.url).to match(/window_switching\.html/)
|
382
418
|
end
|
419
|
+
|
420
|
+
it 'by element' do
|
421
|
+
browser.window(element: browser.link(id: 'open')).use
|
422
|
+
expect(browser.url).to match(/window_switching\.html/)
|
423
|
+
end
|
383
424
|
end
|
384
425
|
|
385
426
|
context 'Switching windows with blocks' do
|
386
427
|
it 'by index' do
|
387
|
-
|
428
|
+
expect {
|
429
|
+
browser.window(index: 0).use { expect(browser.title).to be == 'window switching' }
|
430
|
+
}.to have_deprecated_window_index
|
388
431
|
end
|
389
432
|
|
390
433
|
it 'by url' do
|
@@ -394,6 +437,11 @@ describe 'Window' do
|
|
394
437
|
it 'by title' do
|
395
438
|
browser.window(title: 'window switching').use { expect(browser.url).to match(/window_switching\.html/) }
|
396
439
|
end
|
440
|
+
|
441
|
+
it 'by element' do
|
442
|
+
element = browser.link(id: 'open')
|
443
|
+
browser.window(element: element).use { expect(browser.url).to match(/window_switching\.html/) }
|
444
|
+
end
|
397
445
|
end
|
398
446
|
end
|
399
447
|
end
|
@@ -449,18 +497,92 @@ describe 'Window' do
|
|
449
497
|
it 'should maximize the window' do
|
450
498
|
initial_size = browser.window.size
|
451
499
|
browser.window.resize_to(
|
452
|
-
initial_size.width,
|
453
|
-
initial_size.height -
|
500
|
+
initial_size.width - 40,
|
501
|
+
initial_size.height - 40
|
454
502
|
)
|
503
|
+
browser.wait_until { |b| b.window.size != initial_size }
|
504
|
+
new_size = browser.window.size
|
455
505
|
|
456
506
|
browser.window.maximize
|
457
|
-
browser.wait_until {
|
507
|
+
browser.wait_until { |b| b.window.size != new_size }
|
458
508
|
|
459
|
-
|
460
|
-
expect(
|
461
|
-
expect(
|
509
|
+
final_size = browser.window.size
|
510
|
+
expect(final_size.width).to be >= new_size.width
|
511
|
+
expect(final_size.height).to be > (new_size.height)
|
462
512
|
end
|
463
513
|
end
|
464
514
|
end
|
465
515
|
end
|
466
516
|
end
|
517
|
+
|
518
|
+
describe Watir::WindowCollection do
|
519
|
+
before do
|
520
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
521
|
+
browser.a(id: 'open').click
|
522
|
+
browser.windows.wait_until(size: 2)
|
523
|
+
end
|
524
|
+
|
525
|
+
after do
|
526
|
+
browser.original_window.use
|
527
|
+
browser.windows.reject(&:current?).each(&:close)
|
528
|
+
end
|
529
|
+
|
530
|
+
describe '#new' do
|
531
|
+
it 'returns all windows by default' do
|
532
|
+
windows = Watir::WindowCollection.new(browser)
|
533
|
+
|
534
|
+
expect(windows.size).to eq 2
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'filters available windows by url' do
|
538
|
+
windows = Watir::WindowCollection.new(browser, url: /closeable\.html/)
|
539
|
+
|
540
|
+
expect(windows.size).to eq 1
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'filters available windows by title' do
|
544
|
+
windows = Watir::WindowCollection.new(browser, title: /closeable/)
|
545
|
+
|
546
|
+
expect(windows.size).to eq 1
|
547
|
+
end
|
548
|
+
|
549
|
+
it 'filters available windows by element' do
|
550
|
+
windows = Watir::WindowCollection.new(browser, element: browser.element(id: 'close'))
|
551
|
+
|
552
|
+
expect(windows.size).to eq 1
|
553
|
+
end
|
554
|
+
|
555
|
+
it 'raises ArgumentError if unrecognized locator' do
|
556
|
+
expect {
|
557
|
+
Watir::WindowCollection.new(browser, foo: /closeable/)
|
558
|
+
}.to raise_error(ArgumentError)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
describe '#size' do
|
563
|
+
it 'counts the number of matching windows' do
|
564
|
+
expect(Watir::WindowCollection.new(browser).size).to eq 2
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
describe '#[]' do
|
569
|
+
it 'returns window instance at provided index' do
|
570
|
+
windows = Watir::WindowCollection.new(browser)
|
571
|
+
|
572
|
+
expect {
|
573
|
+
expect(windows).to all(be_an(Watir::Window))
|
574
|
+
expect(windows.first).to_not eq windows.last
|
575
|
+
}.to have_deprecated_window_index
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
describe '#eq?' do
|
580
|
+
it 'compares the equivalence of window handles' do
|
581
|
+
windows1 = Watir::WindowCollection.new(browser, title: //)
|
582
|
+
windows2 = Watir::WindowCollection.new(browser, url: //)
|
583
|
+
|
584
|
+
expect(windows1).to eq windows2
|
585
|
+
expect(windows1.to_a.map(&:handle)).to eq windows2.to_a.map(&:handle)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|