watir 6.5.0 → 6.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +58 -21
  3. data/CHANGES.md +11 -0
  4. data/Rakefile +3 -5
  5. data/lib/watir.rb +14 -2
  6. data/lib/watir/adjacent.rb +20 -27
  7. data/lib/watir/alert.rb +1 -1
  8. data/lib/watir/attribute_helper.rb +1 -1
  9. data/lib/watir/browser.rb +6 -3
  10. data/lib/watir/capabilities.rb +95 -0
  11. data/lib/watir/cookies.rb +5 -6
  12. data/lib/watir/element_collection.rb +17 -0
  13. data/lib/watir/elements/element.rb +12 -15
  14. data/lib/watir/elements/iframe.rb +1 -1
  15. data/lib/watir/elements/option.rb +5 -6
  16. data/lib/watir/elements/select.rb +52 -36
  17. data/lib/watir/legacy_wait.rb +2 -2
  18. data/lib/watir/locators/button/selector_builder.rb +10 -7
  19. data/lib/watir/locators/element/locator.rb +2 -2
  20. data/lib/watir/locators/element/selector_builder.rb +10 -4
  21. data/lib/watir/locators/element/selector_builder/xpath.rb +22 -3
  22. data/lib/watir/logger.rb +109 -0
  23. data/lib/watir/wait.rb +6 -6
  24. data/lib/watirspec.rb +1 -1
  25. data/lib/watirspec/guards.rb +4 -4
  26. data/lib/watirspec/implementation.rb +13 -5
  27. data/lib/watirspec/remote_server.rb +38 -0
  28. data/lib/watirspec/runner.rb +2 -2
  29. data/lib/watirspec/server.rb +1 -1
  30. data/spec/browser_spec.rb +101 -17
  31. data/spec/element_locator_spec.rb +1 -1
  32. data/spec/element_spec.rb +1 -1
  33. data/spec/logger_spec.rb +46 -0
  34. data/spec/watirspec/adjacent_spec.rb +45 -0
  35. data/spec/watirspec/after_hooks_spec.rb +45 -40
  36. data/spec/watirspec/alert_spec.rb +20 -14
  37. data/spec/watirspec/browser_spec.rb +71 -77
  38. data/spec/watirspec/cookies_spec.rb +13 -16
  39. data/spec/watirspec/drag_and_drop_spec.rb +6 -6
  40. data/spec/watirspec/elements/button_spec.rb +14 -7
  41. data/spec/watirspec/elements/collections_spec.rb +18 -1
  42. data/spec/watirspec/elements/dd_spec.rb +4 -2
  43. data/spec/watirspec/elements/del_spec.rb +12 -10
  44. data/spec/watirspec/elements/div_spec.rb +17 -13
  45. data/spec/watirspec/elements/dl_spec.rb +4 -2
  46. data/spec/watirspec/elements/form_spec.rb +8 -6
  47. data/spec/watirspec/elements/frame_spec.rb +27 -19
  48. data/spec/watirspec/elements/iframe_spec.rb +28 -17
  49. data/spec/watirspec/elements/ins_spec.rb +12 -10
  50. data/spec/watirspec/elements/option_spec.rb +17 -33
  51. data/spec/watirspec/elements/select_list_spec.rb +111 -97
  52. data/spec/watirspec/elements/span_spec.rb +12 -10
  53. data/spec/watirspec/elements/table_spec.rb +13 -11
  54. data/spec/watirspec/elements/tbody_spec.rb +13 -11
  55. data/spec/watirspec/elements/td_spec.rb +6 -4
  56. data/spec/watirspec/elements/text_field_spec.rb +19 -17
  57. data/spec/watirspec/elements/tr_spec.rb +12 -8
  58. data/spec/watirspec/html/javascript/helpers.js +2 -2
  59. data/spec/watirspec/html/nested_elements.html +5 -5
  60. data/spec/watirspec/relaxed_locate_spec.rb +13 -19
  61. data/spec/watirspec/wait_spec.rb +279 -301
  62. data/spec/watirspec/window_switching_spec.rb +190 -174
  63. data/spec/watirspec_helper.rb +64 -122
  64. data/support/doctest_helper.rb +4 -0
  65. data/watir.gemspec +2 -2
  66. metadata +15 -4
@@ -1,70 +1,70 @@
1
1
  require "watirspec_helper"
2
2
 
3
- not_compliant_on :safari do
4
- describe "Browser" do
5
- before do
6
- url = WatirSpec.url_for("window_switching.html")
7
- browser.goto url
8
- browser.a(id: "open").click
9
- Watir::Wait.until { browser.windows.size == 2 }
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
- after do
13
- browser.window(index: 0).use
14
- browser.windows[1..-1].each(&:close)
15
- end
11
+ after do
12
+ browser.window(index: 0).use
13
+ browser.windows[1..-1].each(&:close)
14
+ end
16
15
 
17
- describe "#windows" do
18
- it "returns an array of window handles" do
19
- wins = browser.windows
20
- expect(wins).to_not be_empty
21
- wins.each { |win| expect(win).to be_kind_of(Watir::Window) }
22
- end
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
- it "only returns windows matching the given selector" do
25
- expect(browser.windows(title: "closeable window").size).to eq 1
26
- end
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
- it "raises ArgumentError if the selector is invalid" do
29
- expect { browser.windows(name: "foo") }.to raise_error(ArgumentError)
30
- end
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
- it "returns an empty array if no window matches the selector" do
33
- expect(browser.windows(title: "noop")).to eq []
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
- describe "#window" do
38
- it "finds window by :url" do
39
- w = browser.window(url: /closeable\.html/).use
40
- expect(w).to be_kind_of(Watir::Window)
41
- end
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
- it "finds window by :title" do
44
- w = browser.window(title: "closeable window").use
45
- expect(w).to be_kind_of(Watir::Window)
46
- end
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
- it "finds window by :index" do
49
- w = browser.window(index: 1).use
50
- expect(w).to be_kind_of(Watir::Window)
51
- end
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
- it "should not find incorrect handle" do
54
- expect(browser.window(handle: 'bar')).to_not be_present
55
- end
52
+ it "should not find incorrect handle" do
53
+ expect(browser.window(handle: 'bar')).to_not be_present
54
+ end
56
55
 
57
- it "returns the current window if no argument is given" do
58
- expect(browser.window.url).to match(/window_switching\.html/)
59
- end
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
- it "stores the reference to a window when no argument is given" do
62
- original_window = browser.window
63
- browser.window(index: 1).use
64
- expect(original_window.url).to match(/window_switching\.html/)
65
- end
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
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
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
- it "raises ArgumentError if the selector is invalid" do
80
- expect { browser.window(name: "foo") }.to raise_error(ArgumentError)
81
- end
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
- it "raises a NoMatchingWindowFoundException error if no window matches the selector" do
84
- expect { browser.window(title: "noop").use }.to raise_no_matching_window_exception
85
- end
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
- it "raises a NoMatchingWindowFoundException error if there's no window at the given index" do
88
- expect { browser.window(index: 100).use }.to raise_no_matching_window_exception
89
- end
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
- it "raises NoMatchingWindowFoundException error when attempting to use a window with an incorrect handle" do
92
- expect { browser.window(handle: 'bar').use }.to raise_no_matching_window_exception
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
- describe "Window" do
98
- context 'multiple windows' do
99
- before do
100
- browser.goto WatirSpec.url_for("window_switching.html")
101
- browser.a(id: "open").click
102
- Watir::Wait.until { browser.windows.size == 2 }
103
- end
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
- after do
106
- browser.window(index: 0).use
107
- browser.windows[1..-1].each(&:close)
108
- end
106
+ after do
107
+ browser.window(index: 0).use
108
+ browser.windows[1..-1].each(&:close)
109
+ end
109
110
 
110
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1280517", :firefox do
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
- it "closes the current window" do
121
- browser.a(id: "open").click
122
- Watir::Wait.until { browser.windows.size == 3 }
123
+ it "closes the current window" do
124
+ browser.a(id: "open").click
125
+ Watir::Wait.until { browser.windows.size == 3 }
123
126
 
124
- window = browser.window(title: "closeable window").use
125
- window.close
126
- expect(browser.windows.size).to eq 2
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
- describe "#use" do
132
- it "switches to the window" do
133
- browser.window(title: "closeable window").use
134
- expect(browser.title).to eq "closeable window"
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
- describe "#current?" do
139
- it "returns true if it is the current window" do
140
- expect(browser.window(title: browser.title)).to be_current
141
- end
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
- it "returns false if it is not the current window" do
144
- expect(browser.window(title: "closeable window")).to_not be_current
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
- describe "#title" do
149
- it "returns the title of the window" do
150
- titles = browser.windows.map(&:title)
151
- expect(titles.size).to eq 2
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
- expect(titles.sort).to eq ["window switching", "closeable window"].sort
154
- end
156
+ expect(titles.sort).to eq ["window switching", "closeable window"].sort
157
+ end
155
158
 
156
- it "does not change the current window" do
157
- expect(browser.title).to eq "window switching"
158
- expect(browser.windows.find { |w| w.title == "closeable window" }).to_not be_nil
159
- expect(browser.title).to eq "window switching"
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
- describe "#url" do
164
- it "returns the url of the window" do
165
- expect(browser.windows.select { |w| w.url =~ (/window_switching\.html/) }.size).to eq 1
166
- expect(browser.windows.select { |w| w.url =~ (/closeable\.html$/) }.size).to eq 1
167
- end
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
- it "does not change the current window" do
170
- expect(browser.url).to match(/window_switching\.html/)
171
- expect(browser.windows.find { |w| w.url =~ (/closeable\.html/) }).to_not be_nil
172
- expect(browser.url).to match(/window_switching/)
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
- describe "#eql?" do
177
- it "knows when two windows are equal" do
178
- expect(browser.window).to eq browser.window(index: 0)
179
- end
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
- it "knows when two windows are not equal" do
182
- win1 = browser.window(index: 0)
183
- win2 = browser.window(index: 1)
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
- expect(win1).to_not eq win2
186
- end
188
+ expect(win1).to_not eq win2
187
189
  end
190
+ end
188
191
 
189
- not_compliant_on :relaxed_locate do
190
- describe "#wait_until &:present?" do
191
- it "times out waiting for a non-present window" do
192
- expect {
193
- browser.window(title: "noop").wait_until(timeout: 0.5, &:present?)
194
- }.to raise_error(Watir::Wait::TimeoutError)
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
- context "with a closed window" do
201
- before do
202
- browser.goto WatirSpec.url_for("window_switching.html")
203
- browser.a(id: "open").click
204
- Watir::Wait.until { browser.windows.size == 2 }
205
- end
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
- after do
208
- browser.window(index: 0).use
209
- browser.windows[1..-1].each(&:close)
210
- end
210
+ after do
211
+ browser.window(index: 0).use
212
+ browser.windows[1..-1].each(&:close)
213
+ end
211
214
 
212
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
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
- describe "#current?" do
232
- it "returns false if the referenced window is closed" do
233
- original_window = browser.window
234
- browser.window(title: "closeable window").use
235
- original_window.close
236
- expect(original_window).to_not be_current
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
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
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
- context "manipulating size and position" do
339
- before do
340
- browser.goto WatirSpec.url_for("window_switching.html")
341
- end
349
+ context "manipulating size and position" do
350
+ before do
351
+ browser.goto WatirSpec.url_for("window_switching.html")
352
+ end
342
353
 
343
- compliant_on :ff_legacy, :chrome do
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
- it "should get the position of the current window" do
352
- pos = browser.window.position
364
+ it "should get the position of the current window" do
365
+ pos = browser.window.position
353
366
 
354
- expect(pos.x).to be >= 0
355
- expect(pos.y).to be >= 0
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
- initial_size.width - 20,
364
- initial_size.height - 20
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
- not_compliant_on :firefox do
375
- it "should move the window" do
376
- initial_pos = browser.window.position
389
+ not_compliant_on :firefox, :headless do
390
+ it "should move the window" do
391
+ initial_pos = browser.window.position
377
392
 
378
- browser.window.move_to(
379
- initial_pos.x + 2,
380
- initial_pos.y + 2
381
- )
393
+ browser.window.move_to(
394
+ initial_pos.x + 2,
395
+ initial_pos.y + 2
396
+ )
382
397
 
383
- new_pos = browser.window.position
384
- expect(new_pos.x).to eq initial_pos.x + 2
385
- expect(new_pos.y).to eq initial_pos.y + 2
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