watir 6.5.0 → 6.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +58 -21
- data/CHANGES.md +11 -0
- data/Rakefile +3 -5
- data/lib/watir.rb +14 -2
- data/lib/watir/adjacent.rb +20 -27
- data/lib/watir/alert.rb +1 -1
- data/lib/watir/attribute_helper.rb +1 -1
- data/lib/watir/browser.rb +6 -3
- data/lib/watir/capabilities.rb +95 -0
- data/lib/watir/cookies.rb +5 -6
- data/lib/watir/element_collection.rb +17 -0
- data/lib/watir/elements/element.rb +12 -15
- data/lib/watir/elements/iframe.rb +1 -1
- data/lib/watir/elements/option.rb +5 -6
- data/lib/watir/elements/select.rb +52 -36
- data/lib/watir/legacy_wait.rb +2 -2
- data/lib/watir/locators/button/selector_builder.rb +10 -7
- data/lib/watir/locators/element/locator.rb +2 -2
- data/lib/watir/locators/element/selector_builder.rb +10 -4
- data/lib/watir/locators/element/selector_builder/xpath.rb +22 -3
- data/lib/watir/logger.rb +109 -0
- data/lib/watir/wait.rb +6 -6
- data/lib/watirspec.rb +1 -1
- data/lib/watirspec/guards.rb +4 -4
- data/lib/watirspec/implementation.rb +13 -5
- data/lib/watirspec/remote_server.rb +38 -0
- data/lib/watirspec/runner.rb +2 -2
- data/lib/watirspec/server.rb +1 -1
- data/spec/browser_spec.rb +101 -17
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +1 -1
- data/spec/logger_spec.rb +46 -0
- data/spec/watirspec/adjacent_spec.rb +45 -0
- data/spec/watirspec/after_hooks_spec.rb +45 -40
- data/spec/watirspec/alert_spec.rb +20 -14
- data/spec/watirspec/browser_spec.rb +71 -77
- data/spec/watirspec/cookies_spec.rb +13 -16
- data/spec/watirspec/drag_and_drop_spec.rb +6 -6
- data/spec/watirspec/elements/button_spec.rb +14 -7
- data/spec/watirspec/elements/collections_spec.rb +18 -1
- data/spec/watirspec/elements/dd_spec.rb +4 -2
- data/spec/watirspec/elements/del_spec.rb +12 -10
- data/spec/watirspec/elements/div_spec.rb +17 -13
- data/spec/watirspec/elements/dl_spec.rb +4 -2
- data/spec/watirspec/elements/form_spec.rb +8 -6
- data/spec/watirspec/elements/frame_spec.rb +27 -19
- data/spec/watirspec/elements/iframe_spec.rb +28 -17
- data/spec/watirspec/elements/ins_spec.rb +12 -10
- data/spec/watirspec/elements/option_spec.rb +17 -33
- data/spec/watirspec/elements/select_list_spec.rb +111 -97
- data/spec/watirspec/elements/span_spec.rb +12 -10
- data/spec/watirspec/elements/table_spec.rb +13 -11
- data/spec/watirspec/elements/tbody_spec.rb +13 -11
- data/spec/watirspec/elements/td_spec.rb +6 -4
- data/spec/watirspec/elements/text_field_spec.rb +19 -17
- data/spec/watirspec/elements/tr_spec.rb +12 -8
- data/spec/watirspec/html/javascript/helpers.js +2 -2
- data/spec/watirspec/html/nested_elements.html +5 -5
- data/spec/watirspec/relaxed_locate_spec.rb +13 -19
- data/spec/watirspec/wait_spec.rb +279 -301
- data/spec/watirspec/window_switching_spec.rb +190 -174
- data/spec/watirspec_helper.rb +64 -122
- data/support/doctest_helper.rb +4 -0
- data/watir.gemspec +2 -2
- metadata +15 -4
@@ -1,70 +1,70 @@
|
|
1
1
|
require "watirspec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
3
|
+
describe "Browser" do
|
4
|
+
before do
|
5
|
+
url = WatirSpec.url_for("window_switching.html")
|
6
|
+
browser.goto url
|
7
|
+
browser.a(id: "open").click
|
8
|
+
Watir::Wait.until { browser.windows.size == 2 }
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
after do
|
12
|
+
browser.window(index: 0).use
|
13
|
+
browser.windows[1..-1].each(&:close)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
describe "#windows" do
|
17
|
+
it "returns an array of window handles" do
|
18
|
+
wins = browser.windows
|
19
|
+
expect(wins).to_not be_empty
|
20
|
+
wins.each { |win| expect(win).to be_kind_of(Watir::Window) }
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
it "only returns windows matching the given selector" do
|
24
|
+
expect(browser.windows(title: "closeable window").size).to eq 1
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
it "raises ArgumentError if the selector is invalid" do
|
28
|
+
expect { browser.windows(name: "foo") }.to raise_error(ArgumentError)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
31
|
+
it "returns an empty array if no window matches the selector" do
|
32
|
+
expect(browser.windows(title: "noop")).to eq []
|
35
33
|
end
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
describe "#window" do
|
37
|
+
it "finds window by :url" do
|
38
|
+
w = browser.window(url: /closeable\.html/).use
|
39
|
+
expect(w).to be_kind_of(Watir::Window)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
it "finds window by :title" do
|
43
|
+
w = browser.window(title: "closeable window").use
|
44
|
+
expect(w).to be_kind_of(Watir::Window)
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
it "finds window by :index" do
|
48
|
+
w = browser.window(index: 1).use
|
49
|
+
expect(w).to be_kind_of(Watir::Window)
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it "should not find incorrect handle" do
|
53
|
+
expect(browser.window(handle: 'bar')).to_not be_present
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
it "returns the current window if no argument is given" do
|
57
|
+
expect(browser.window.url).to match(/window_switching\.html/)
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
it "stores the reference to a window when no argument is given" do
|
61
|
+
original_window = browser.window
|
62
|
+
browser.window(index: 1).use
|
63
|
+
expect(original_window.url).to match(/window_switching\.html/)
|
64
|
+
end
|
66
65
|
|
67
|
-
|
66
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
|
67
|
+
not_compliant_on :headless do
|
68
68
|
it "it executes the given block in the window" do
|
69
69
|
browser.window(title: "closeable window") do
|
70
70
|
link = browser.a(id: "close")
|
@@ -75,39 +75,41 @@ not_compliant_on :safari do
|
|
75
75
|
expect(browser.windows.size).to eq 1
|
76
76
|
end
|
77
77
|
end
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
it "raises ArgumentError if the selector is invalid" do
|
81
|
+
expect { browser.window(name: "foo") }.to raise_error(ArgumentError)
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
it "raises a NoMatchingWindowFoundException error if no window matches the selector" do
|
85
|
+
expect { browser.window(title: "noop").use }.to raise_no_matching_window_exception
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
it "raises a NoMatchingWindowFoundException error if there's no window at the given index" do
|
89
|
+
expect { browser.window(index: 100).use }.to raise_no_matching_window_exception
|
90
|
+
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
end
|
92
|
+
it "raises NoMatchingWindowFoundException error when attempting to use a window with an incorrect handle" do
|
93
|
+
expect { browser.window(handle: 'bar').use }.to raise_no_matching_window_exception
|
94
94
|
end
|
95
95
|
end
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
describe "Window" do
|
99
|
+
context 'multiple windows' do
|
100
|
+
before do
|
101
|
+
browser.goto WatirSpec.url_for("window_switching.html")
|
102
|
+
browser.a(id: "open").click
|
103
|
+
Watir::Wait.until { browser.windows.size == 2 }
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
after do
|
107
|
+
browser.window(index: 0).use
|
108
|
+
browser.windows[1..-1].each(&:close)
|
109
|
+
end
|
109
110
|
|
110
|
-
|
111
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1280517", :firefox do
|
112
|
+
not_compliant_on :safari do
|
111
113
|
describe "#close" do
|
112
114
|
it "closes a window" do
|
113
115
|
browser.a(id: "open").click
|
@@ -116,100 +118,102 @@ not_compliant_on :safari do
|
|
116
118
|
browser.window(title: "closeable window").close
|
117
119
|
expect(browser.windows.size).to eq 2
|
118
120
|
end
|
121
|
+
end
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
+
it "closes the current window" do
|
124
|
+
browser.a(id: "open").click
|
125
|
+
Watir::Wait.until { browser.windows.size == 3 }
|
123
126
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
127
|
+
window = browser.window(title: "closeable window").use
|
128
|
+
window.close
|
129
|
+
expect(browser.windows.size).to eq 2
|
128
130
|
end
|
129
131
|
end
|
132
|
+
end
|
130
133
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
134
|
+
describe "#use" do
|
135
|
+
it "switches to the window" do
|
136
|
+
browser.window(title: "closeable window").use
|
137
|
+
expect(browser.title).to eq "closeable window"
|
136
138
|
end
|
139
|
+
end
|
137
140
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
141
|
+
describe "#current?" do
|
142
|
+
it "returns true if it is the current window" do
|
143
|
+
expect(browser.window(title: browser.title)).to be_current
|
144
|
+
end
|
142
145
|
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
+
it "returns false if it is not the current window" do
|
147
|
+
expect(browser.window(title: "closeable window")).to_not be_current
|
146
148
|
end
|
149
|
+
end
|
147
150
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
151
|
+
describe "#title" do
|
152
|
+
it "returns the title of the window" do
|
153
|
+
titles = browser.windows.map(&:title)
|
154
|
+
expect(titles.size).to eq 2
|
152
155
|
|
153
|
-
|
154
|
-
|
156
|
+
expect(titles.sort).to eq ["window switching", "closeable window"].sort
|
157
|
+
end
|
155
158
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
end
|
159
|
+
it "does not change the current window" do
|
160
|
+
expect(browser.title).to eq "window switching"
|
161
|
+
expect(browser.windows.find { |w| w.title == "closeable window" }).to_not be_nil
|
162
|
+
expect(browser.title).to eq "window switching"
|
161
163
|
end
|
164
|
+
end
|
162
165
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
166
|
+
describe "#url" do
|
167
|
+
it "returns the url of the window" do
|
168
|
+
expect(browser.windows.select { |w| w.url =~ (/window_switching\.html/) }.size).to eq 1
|
169
|
+
expect(browser.windows.select { |w| w.url =~ (/closeable\.html$/) }.size).to eq 1
|
170
|
+
end
|
168
171
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
end
|
172
|
+
it "does not change the current window" do
|
173
|
+
expect(browser.url).to match(/window_switching\.html/)
|
174
|
+
expect(browser.windows.find { |w| w.url =~ (/closeable\.html/) }).to_not be_nil
|
175
|
+
expect(browser.url).to match(/window_switching/)
|
174
176
|
end
|
177
|
+
end
|
175
178
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
179
|
+
describe "#eql?" do
|
180
|
+
it "knows when two windows are equal" do
|
181
|
+
expect(browser.window).to eq browser.window(index: 0)
|
182
|
+
end
|
180
183
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
+
it "knows when two windows are not equal" do
|
185
|
+
win1 = browser.window(index: 0)
|
186
|
+
win2 = browser.window(index: 1)
|
184
187
|
|
185
|
-
|
186
|
-
end
|
188
|
+
expect(win1).to_not eq win2
|
187
189
|
end
|
190
|
+
end
|
188
191
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
192
|
+
not_compliant_on :relaxed_locate do
|
193
|
+
describe "#wait_until &:present?" do
|
194
|
+
it "times out waiting for a non-present window" do
|
195
|
+
expect {
|
196
|
+
browser.window(title: "noop").wait_until(timeout: 0.5, &:present?)
|
197
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
196
198
|
end
|
197
199
|
end
|
198
200
|
end
|
201
|
+
end
|
199
202
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
context "with a closed window" do
|
204
|
+
before do
|
205
|
+
browser.goto WatirSpec.url_for("window_switching.html")
|
206
|
+
browser.a(id: "open").click
|
207
|
+
Watir::Wait.until { browser.windows.size == 2 }
|
208
|
+
end
|
206
209
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
210
|
+
after do
|
211
|
+
browser.window(index: 0).use
|
212
|
+
browser.windows[1..-1].each(&:close)
|
213
|
+
end
|
211
214
|
|
212
|
-
|
215
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
|
216
|
+
not_compliant_on :headless do
|
213
217
|
describe "#exists?" do
|
214
218
|
it "returns false if previously referenced window is closed" do
|
215
219
|
window = browser.window(title: "closeable window")
|
@@ -227,16 +231,18 @@ not_compliant_on :safari do
|
|
227
231
|
end
|
228
232
|
end
|
229
233
|
end
|
234
|
+
end
|
230
235
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
236
|
+
describe "#current?" do
|
237
|
+
it "returns false if the referenced window is closed" do
|
238
|
+
original_window = browser.window
|
239
|
+
browser.window(title: "closeable window").use
|
240
|
+
original_window.close
|
241
|
+
expect(original_window).to_not be_current
|
238
242
|
end
|
243
|
+
end
|
239
244
|
|
245
|
+
not_compliant_on :safari, :headless do
|
240
246
|
describe "#eql?" do
|
241
247
|
it "should return false when checking equivalence to a closed window" do
|
242
248
|
original_window = browser.window
|
@@ -246,7 +252,9 @@ not_compliant_on :safari do
|
|
246
252
|
expect(other_window == original_window).to be false
|
247
253
|
end
|
248
254
|
end
|
255
|
+
end
|
249
256
|
|
257
|
+
not_compliant_on :headless do
|
250
258
|
describe "#use" do
|
251
259
|
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
|
252
260
|
it "raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed" do
|
@@ -267,8 +275,10 @@ not_compliant_on :safari do
|
|
267
275
|
end
|
268
276
|
end
|
269
277
|
end
|
278
|
+
end
|
270
279
|
|
271
|
-
|
280
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
|
281
|
+
not_compliant_on :headless do
|
272
282
|
context "with current window closed" do
|
273
283
|
before do
|
274
284
|
browser.goto WatirSpec.url_for("window_switching.html")
|
@@ -334,34 +344,38 @@ not_compliant_on :safari do
|
|
334
344
|
end
|
335
345
|
end
|
336
346
|
end
|
347
|
+
end
|
337
348
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
349
|
+
context "manipulating size and position" do
|
350
|
+
before do
|
351
|
+
browser.goto WatirSpec.url_for("window_switching.html")
|
352
|
+
end
|
342
353
|
|
343
|
-
|
354
|
+
compliant_on :chrome do
|
355
|
+
not_compliant_on :headless do
|
344
356
|
it "should get the size of the current window" do
|
345
357
|
size = browser.window.size
|
346
358
|
|
347
359
|
expect(size.width).to be > 0
|
348
360
|
expect(size.height).to be > 0
|
349
361
|
end
|
362
|
+
end
|
350
363
|
|
351
|
-
|
352
|
-
|
364
|
+
it "should get the position of the current window" do
|
365
|
+
pos = browser.window.position
|
353
366
|
|
354
|
-
|
355
|
-
|
356
|
-
end
|
367
|
+
expect(pos.x).to be >= 0
|
368
|
+
expect(pos.y).to be >= 0
|
357
369
|
end
|
370
|
+
end
|
358
371
|
|
372
|
+
not_compliant_on :headless do
|
359
373
|
bug "https://github.com/SeleniumHQ/selenium/issues/2856", %i(remote firefox) do
|
360
374
|
it "should resize the window" do
|
361
375
|
initial_size = browser.window.size
|
362
376
|
browser.window.resize_to(
|
363
|
-
|
364
|
-
|
377
|
+
initial_size.width - 20,
|
378
|
+
initial_size.height - 20
|
365
379
|
)
|
366
380
|
|
367
381
|
new_size = browser.window.size
|
@@ -370,22 +384,24 @@ not_compliant_on :safari do
|
|
370
384
|
expect(new_size.height).to eq initial_size.height - 20
|
371
385
|
end
|
372
386
|
end
|
387
|
+
end
|
373
388
|
|
374
|
-
|
375
|
-
|
376
|
-
|
389
|
+
not_compliant_on :firefox, :headless do
|
390
|
+
it "should move the window" do
|
391
|
+
initial_pos = browser.window.position
|
377
392
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
393
|
+
browser.window.move_to(
|
394
|
+
initial_pos.x + 2,
|
395
|
+
initial_pos.y + 2
|
396
|
+
)
|
382
397
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
end
|
398
|
+
new_pos = browser.window.position
|
399
|
+
expect(new_pos.x).to eq initial_pos.x + 2
|
400
|
+
expect(new_pos.y).to eq initial_pos.y + 2
|
387
401
|
end
|
402
|
+
end
|
388
403
|
|
404
|
+
not_compliant_on :headless do
|
389
405
|
compliant_on :window_manager do
|
390
406
|
bug "https://github.com/SeleniumHQ/selenium/issues/2856", %i(remote firefox) do
|
391
407
|
it "should maximize the window" do
|