watir 6.16.1 → 6.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +32 -107
  3. data/.travis.yml +24 -21
  4. data/CHANGES.md +34 -0
  5. data/Gemfile +3 -1
  6. data/Rakefile +3 -3
  7. data/appveyor.yml +2 -1
  8. data/lib/watir-webdriver.rb +1 -1
  9. data/lib/watir.rb +0 -1
  10. data/lib/watir/adjacent.rb +8 -10
  11. data/lib/watir/after_hooks.rb +6 -3
  12. data/lib/watir/browser.rb +5 -13
  13. data/lib/watir/capabilities.rb +9 -6
  14. data/lib/watir/cookies.rb +1 -1
  15. data/lib/watir/element_collection.rb +1 -1
  16. data/lib/watir/elements/element.rb +59 -59
  17. data/lib/watir/elements/file_field.rb +1 -0
  18. data/lib/watir/elements/iframe.rb +6 -9
  19. data/lib/watir/elements/link.rb +0 -9
  20. data/lib/watir/elements/radio.rb +1 -1
  21. data/lib/watir/elements/select.rb +2 -2
  22. data/lib/watir/generator/base/spec_extractor.rb +4 -4
  23. data/lib/watir/js_execution.rb +1 -1
  24. data/lib/watir/legacy_wait.rb +1 -1
  25. data/lib/watir/locators/button/matcher.rb +2 -2
  26. data/lib/watir/locators/cell/selector_builder.rb +1 -1
  27. data/lib/watir/locators/element/locator.rb +27 -13
  28. data/lib/watir/locators/element/matcher.rb +5 -2
  29. data/lib/watir/locators/element/selector_builder.rb +31 -25
  30. data/lib/watir/locators/element/selector_builder/xpath.rb +42 -13
  31. data/lib/watir/locators/row/selector_builder.rb +2 -2
  32. data/lib/watir/locators/text_field/matcher.rb +4 -3
  33. data/lib/watir/locators/text_field/selector_builder/xpath.rb +3 -1
  34. data/lib/watir/logger.rb +5 -2
  35. data/lib/watir/version.rb +1 -1
  36. data/lib/watir/window.rb +1 -1
  37. data/lib/watirspec.rb +1 -1
  38. data/lib/watirspec/guards.rb +1 -1
  39. data/lib/watirspec/rake_tasks.rb +2 -0
  40. data/lib/watirspec/runner.rb +4 -0
  41. data/spec/unit/container_spec.rb +1 -1
  42. data/spec/unit/logger_spec.rb +5 -7
  43. data/spec/unit/selector_builder/button_spec.rb +16 -15
  44. data/spec/unit/selector_builder/element_spec.rb +83 -14
  45. data/spec/unit/selector_builder/text_field_spec.rb +14 -14
  46. data/spec/watirspec/after_hooks_spec.rb +66 -88
  47. data/spec/watirspec/alert_spec.rb +69 -79
  48. data/spec/watirspec/browser_spec.rb +48 -46
  49. data/spec/watirspec/cookies_spec.rb +52 -37
  50. data/spec/watirspec/drag_and_drop_spec.rb +14 -38
  51. data/spec/watirspec/elements/button_spec.rb +2 -0
  52. data/spec/watirspec/elements/buttons_spec.rb +1 -1
  53. data/spec/watirspec/elements/checkbox_spec.rb +24 -18
  54. data/spec/watirspec/elements/date_field_spec.rb +18 -9
  55. data/spec/watirspec/elements/date_time_field_spec.rb +3 -4
  56. data/spec/watirspec/elements/div_spec.rb +64 -54
  57. data/spec/watirspec/elements/element_spec.rb +60 -78
  58. data/spec/watirspec/elements/elements_spec.rb +12 -3
  59. data/spec/watirspec/elements/filefield_spec.rb +25 -50
  60. data/spec/watirspec/elements/form_spec.rb +6 -8
  61. data/spec/watirspec/elements/frame_spec.rb +10 -13
  62. data/spec/watirspec/elements/iframe_spec.rb +18 -14
  63. data/spec/watirspec/elements/iframes_spec.rb +2 -2
  64. data/spec/watirspec/elements/link_spec.rb +18 -9
  65. data/spec/watirspec/elements/links_spec.rb +11 -3
  66. data/spec/watirspec/elements/option_spec.rb +15 -17
  67. data/spec/watirspec/elements/select_list_spec.rb +66 -80
  68. data/spec/watirspec/elements/text_field_spec.rb +8 -4
  69. data/spec/watirspec/elements/tr_spec.rb +0 -9
  70. data/spec/watirspec/html/forms_with_input_elements.html +1 -0
  71. data/spec/watirspec/html/iframes.html +3 -0
  72. data/spec/watirspec/html/non_control_elements.html +4 -4
  73. data/spec/watirspec/html/right_click.html +12 -0
  74. data/spec/watirspec/html/wait.html +1 -1
  75. data/spec/watirspec/relaxed_locate_spec.rb +16 -20
  76. data/spec/watirspec/support/rspec_matchers.rb +7 -6
  77. data/spec/watirspec/user_editable_spec.rb +1 -1
  78. data/spec/watirspec/wait_spec.rb +13 -17
  79. data/spec/watirspec/window_switching_spec.rb +162 -163
  80. data/spec/watirspec_helper.rb +7 -5
  81. data/watir.gemspec +4 -5
  82. metadata +14 -16
  83. data/lib/watir/elements/area.rb +0 -10
@@ -25,15 +25,19 @@ describe 'TextField' do
25
25
  expect(browser.text_field(label: /Without for/)).to exist
26
26
  expect(browser.text_field(label: 'With hidden text')).to exist
27
27
  expect(browser.text_field(label: 'With text')).not_to exist
28
- expect(browser.text_field(visible_label: 'With hidden text')).not_to exist
29
- expect(browser.text_field(visible_label: 'With text')).to exist
30
28
 
31
29
  # These will work after text is deprecated for visible_text
32
30
  # expect(browser.text_field(label: /With hidden text/)).to exist
33
31
  # expect(browser.text_field(label: /With text/)).not_to exist
32
+ end
34
33
 
35
- expect(browser.text_field(visible_label: /With text/)).to exist
36
- expect(browser.text_field(visible_label: /With hidden text/)).not_to exist
34
+ bug 'Safari is not filtering out hidden text', :safari do
35
+ it 'returns true in spite of hidden text' do
36
+ expect(browser.text_field(visible_label: 'With hidden text')).not_to exist
37
+ expect(browser.text_field(visible_label: 'With text')).to exist
38
+ expect(browser.text_field(visible_label: /With text/)).to exist
39
+ expect(browser.text_field(visible_label: /With hidden text/)).not_to exist
40
+ end
37
41
  end
38
42
 
39
43
  it 'locates value of text_field using text locators' do
@@ -29,15 +29,6 @@ describe 'TableRow' do
29
29
  end
30
30
  end
31
31
 
32
- describe '#click' do
33
- not_compliant_on :internet_explorer, :chrome, :firefox do
34
- it "fires the row's onclick event" do
35
- browser.tr(id: 'inner_first').click
36
- expect(messages).to include('tr')
37
- end
38
- end
39
- end
40
-
41
32
  bug 'Safari does not strip text', :safari do
42
33
  describe '#[]' do
43
34
  let(:table) { browser.table(id: 'outer') }
@@ -133,6 +133,7 @@
133
133
  <input type="BuTTon" name="new_user_button_preview" id="new_user_button_preview" alt="Create a new user" value="Preview" data-locator="preview"/>
134
134
  <button name="new_user_button_2" type="submit" value="button_2" data-locator="Benjamin">Button 2</button>
135
135
  <button name="new_user_button_3" value="button_3" data-locator="No Type">Button 3</button>
136
+ <button name="new_user_button_4" value="button_4" data-locator="child text"> Button 4 <span> With Child Text </span> </button>
136
137
  <input type="image" class="image" name="new_user_image" src="images/button.png" alt="Submittable button" data-locator="submittable button"/>
137
138
  <input type="submit" name="new_user_submit_disabled" id="disabled_button" value="Disabled" disabled="disabled" data-locator="disabled" />
138
139
  <input type="checkbox" name="new_user_submit_disabled" id="toggle_button_checkbox" onclick="var elem = document.getElementById('disabled_button'); elem.disabled = !elem.disabled" />
@@ -8,5 +8,8 @@
8
8
  <h1>Iframes</h1>
9
9
  <iframe src="iframe_1.html" id="iframe_1" name="iframe1" class="half"></iframe>
10
10
  <iframe src="frame_2.html" id="iframe_2" name="iframe2" class="half"></iframe>
11
+ <div class="wrapper">
12
+ <iframe src="nested_elements.html" id="iframe_3" name="iframe3"></iframe>
13
+ </div>
11
14
  </body>
12
15
  </html>
@@ -132,9 +132,9 @@
132
132
  </div>
133
133
  <div custom-attribute=custom>Custom</div>
134
134
  <div id="visible_text">
135
- <a id="all_visible_text">all visible</a>
136
- <a id="some_visible_text">some visible<span style="display:none;"> some hidden</span></a>
137
- <a id="no_visible_text" style="display:none;">none visible</a>
138
- </div>
135
+ <a id="all_visible_text">all visible</a>
136
+ <a id="some_visible_text">some visible<span style="display:none;"> some hidden</span></a>
137
+ <a id="no_visible_text" style="display:none;">none visible</a>
138
+ </div>
139
139
  </body>
140
140
  </html>
@@ -3,9 +3,21 @@
3
3
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
4
  <title>Right Click Test</title>
5
5
  <script src="javascript/helpers.js" type="text/javascript" charset="utf-8"></script>
6
+ <script src="javascript/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
6
7
  </head>
8
+ <script>
9
+ $(document).ready(function() {
10
+ $(document).on("contextmenu", "#click-logger", function(evt){
11
+ $("#log").append("<p>control=" + evt.ctrlKey + " alt=" + evt.altKey + "</p>");
12
+ return false;
13
+ });
14
+ });
15
+ </script>
7
16
  <body>
8
17
  <div id="messages"></div>
9
18
  <div id="click" oncontextmenu='WatirSpec.addMessage("right-clicked"); return false'>Right click!</div>
19
+ <br />
20
+ <div id="click-logger">Right click with modifiers!</div>
21
+ <div id="log"></div>
10
22
  </body>
11
23
  </html>
@@ -64,7 +64,7 @@
64
64
  <a id="add_foobar" href="#" onclick="setTimeoutAddDisplay('foobar', 'bar', 1000);">add foobar</a>
65
65
  <a id="readd_bar" href="#" onclick="setTimeoutRemove('bar', 500); setTimeoutAddDisplay('bar', 'foo', 1000);">re-add bar</a>
66
66
  <div id="buttons">
67
- <button id="btn" type="button" onclick="setDisabled('btn', true, 0)" disabled>Click To Disable!</button>
67
+ <button id="btn" type="button" onclick="setDisabled('btn', true, 0);" disabled>Click To Disable!</button>
68
68
  <a id="enable_btn" href="#" onclick="setDisabled('btn', false, 500);">enable btn</a>
69
69
  <button id="btn2" style="display:none;" type="button" disabled>Hidden and Disabled</button>
70
70
  <a id="show_and_enable_btn" href="#" onclick="setTimeoutDisplay('btn2', 'block', 500); setDisabled('btn2', false, 1000);">
@@ -35,20 +35,18 @@ describe 'Watir#relaxed_locate?' do
35
35
  end
36
36
 
37
37
  context 'when acting on an element that eventually becomes present' do
38
- bug 'https://github.com/SeleniumHQ/selenium/issues/4380', %i[remote firefox] do
39
- it 'waits until present and then takes action' do
40
- start_time = ::Time.now
41
- browser.a(id: 'show_bar').click
42
- expect { browser.div(id: 'bar').click }.to_not raise_exception
43
- expect(::Time.now - start_time).to be < Watir.default_timeout
44
- end
45
-
46
- it 'waits until text field is displayed and then takes action' do
47
- start_time = ::Time.now
48
- browser.a(id: 'show_textfield').click
49
- expect { browser.text_field(id: 'textfield').set 'Foo' }.to_not raise_exception
50
- expect(::Time.now - start_time).to be < Watir.default_timeout
51
- end
38
+ it 'waits until present and then takes action' do
39
+ start_time = ::Time.now
40
+ browser.a(id: 'show_bar').click
41
+ expect { browser.div(id: 'bar').click }.to_not raise_exception
42
+ expect(::Time.now - start_time).to be < Watir.default_timeout
43
+ end
44
+
45
+ it 'waits until text field is displayed and then takes action' do
46
+ start_time = ::Time.now
47
+ browser.a(id: 'show_textfield').click
48
+ expect { browser.text_field(id: 'textfield').set 'Foo' }.to_not raise_exception
49
+ expect(::Time.now - start_time).to be < Watir.default_timeout
52
50
  end
53
51
  end
54
52
 
@@ -63,12 +61,10 @@ describe 'Watir#relaxed_locate?' do
63
61
  end
64
62
 
65
63
  it 'ensures all checks happen once even if time has expired' do
66
- begin
67
- Watir.default_timeout = -1
68
- expect { browser.link.click }.to_not raise_exception
69
- ensure
70
- Watir.default_timeout = 30
71
- end
64
+ Watir.default_timeout = -1
65
+ expect { browser.link.click }.to_not raise_exception
66
+ ensure
67
+ Watir.default_timeout = 30
72
68
  end
73
69
 
74
70
  it 'does not wait for parent element to be present when querying child element' do
@@ -8,6 +8,7 @@ if defined?(RSpec)
8
8
  visible_text
9
9
  link_text
10
10
  text_regexp
11
+ scroll_into_view
11
12
  stale_exists
12
13
  stale_visible
13
14
  stale_present
@@ -62,10 +63,10 @@ if defined?(RSpec)
62
63
  begin
63
64
  actual.call
64
65
  false
65
- rescue exception => ex
66
- return true if message.nil? || ex.message.match(message)
66
+ rescue exception => e
67
+ return true if message.nil? || e.message.match(message)
67
68
 
68
- raise exception, "expected '#{message}' to be included in: '#{ex.message}'"
69
+ raise exception, "expected '#{message}' to be included in: '#{e.message}'"
69
70
  ensure
70
71
  Watir.default_timeout = original_timeout
71
72
  end
@@ -88,10 +89,10 @@ if defined?(RSpec)
88
89
  start_time = ::Time.now
89
90
  actual.call
90
91
  false
91
- rescue exception => ex
92
+ rescue exception => e
92
93
  finish_time = ::Time.now
93
- unless message.nil? || ex.message.match(message)
94
- raise exception, "expected '#{message}' to be included in: '#{ex.message}'"
94
+ unless message.nil? || e.message.match(message)
95
+ raise exception, "expected '#{message}' to be included in: '#{e.message}'"
95
96
  end
96
97
 
97
98
  @time_difference = finish_time - start_time
@@ -5,7 +5,7 @@ describe Watir::UserEditable do
5
5
  browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
6
6
  end
7
7
 
8
- not_compliant_on :safari do
8
+ bug 'incorrectly clears first', :safari do
9
9
  describe '#append' do
10
10
  it 'appends the text to the text field' do
11
11
  browser.text_field(name: 'new_user_occupation').append(' Append This')
@@ -112,11 +112,13 @@ describe Watir::Element do
112
112
  }.to have_deprecated_wait_until_present
113
113
  end
114
114
 
115
- it 'waits until the element re-appears' do
116
- browser.link(id: 'readd_bar').click
117
- expect {
118
- expect { browser.div(id: 'bar').wait_until_present }.to_not raise_exception
119
- }.to have_deprecated_wait_until_present
115
+ bug 'Safari does not recognize date type', :safari do
116
+ it 'waits until the element re-appears' do
117
+ browser.link(id: 'readd_bar').click
118
+ expect {
119
+ expect { browser.div(id: 'bar').wait_until_present }.to_not raise_exception
120
+ }.to have_deprecated_wait_until_present
121
+ end
120
122
  end
121
123
 
122
124
  it "times out if the element doesn't appear" do
@@ -269,14 +271,6 @@ describe Watir::Element do
269
271
  expect(element.wait_while(&:present?)).to eq element
270
272
  end
271
273
 
272
- not_compliant_on :safari do
273
- it 'accepts self in block' do
274
- element = browser.div(id: 'foo')
275
- browser.a(id: 'hide_foo').click
276
- expect { element.wait_while { |el| el.text == 'foo' } }.to_not raise_exception
277
- end
278
- end
279
-
280
274
  it 'accepts any values in block' do
281
275
  element = browser.div(id: 'foo')
282
276
  expect { element.wait_while { false } }.to_not raise_exception
@@ -298,10 +292,12 @@ describe Watir::Element do
298
292
  end
299
293
 
300
294
  context 'accepts keywords instead of block' do
301
- it 'accepts text keyword' do
302
- element = browser.div(id: 'foo')
303
- browser.a(id: 'hide_foo').click
304
- expect { element.wait_while(text: 'foo') }.to_not raise_exception
295
+ bug 'Safari does not recognize date type', :safari do
296
+ it 'accepts text keyword' do
297
+ element = browser.div(id: 'foo')
298
+ browser.a(id: 'hide_foo').click
299
+ expect { element.wait_while(text: 'foo') }.to_not raise_exception
300
+ end
305
301
  end
306
302
 
307
303
  it 'accepts regular expression value' do
@@ -60,21 +60,19 @@ describe 'Browser' do
60
60
 
61
61
  it 'stores the reference to a window when no argument is given' do
62
62
  original_window = browser.window
63
- browser.window(index: 1).use
63
+ browser.window(title: 'closeable window').use
64
64
  expect(original_window.url).to match(/window_switching\.html/)
65
65
  end
66
66
 
67
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
68
- not_compliant_on :headless do
69
- it 'it executes the given block in the window' do
70
- browser.window(title: 'closeable window') {
71
- link = browser.a(id: 'close')
72
- expect(link).to exist
73
- link.click
74
- }.wait_while(&:present?)
67
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
68
+ it 'it executes the given block in the window' do
69
+ browser.window(title: 'closeable window') {
70
+ link = browser.a(id: 'close')
71
+ expect(link).to exist
72
+ link.click
73
+ }.wait_while(&:present?)
75
74
 
76
- expect(browser.windows.size).to eq 1
77
- end
75
+ expect(browser.windows.size).to eq 1
78
76
  end
79
77
  end
80
78
 
@@ -109,24 +107,34 @@ describe 'Window' do
109
107
  browser.windows.reject(&:current?).each(&:close)
110
108
  end
111
109
 
112
- not_compliant_on :safari, %i[firefox linux] do
110
+ bug 'Focus is on newly opened window instead of the first', :safari do
111
+ it 'allows actions on first window after opening second' do
112
+ browser.a(id: 'open').click
113
+ expect { browser.wait_until { |b| b.windows.size == 3 } }.to_not raise_exception
114
+ end
115
+ end
116
+
117
+ not_compliant_on %i[firefox linux] do
113
118
  describe '#close' do
114
119
  it 'closes a window' do
120
+ browser.window(title: 'window switching').use
115
121
  browser.a(id: 'open').click
116
122
  Watir::Wait.until { browser.windows.size == 3 }
117
123
 
118
124
  browser.window(title: 'closeable window').close
119
125
  expect(browser.windows.size).to eq 2
120
126
  end
121
- end
122
127
 
123
- it 'closes the current window' do
124
- browser.a(id: 'open').click
125
- Watir::Wait.until { browser.windows.size == 3 }
128
+ bug 'Focus is on newly opened window instead of the first', :safari do
129
+ it 'closes the current window' do
130
+ browser.a(id: 'open').click
131
+ Watir::Wait.until { browser.windows.size == 3 }
126
132
 
127
- window = browser.window(title: 'closeable window').use
128
- window.close
129
- expect(browser.windows.size).to eq 2
133
+ window = browser.window(title: 'closeable window').use
134
+ window.close
135
+ expect(browser.windows.size).to eq 2
136
+ end
137
+ end
130
138
  end
131
139
  end
132
140
 
@@ -177,12 +185,12 @@ describe 'Window' do
177
185
 
178
186
  describe '#eql?' do
179
187
  it 'knows when two windows are equal' do
180
- expect(browser.window).to eq browser.window(index: 0)
188
+ expect(browser.window).to eq browser.window(title: 'window switching')
181
189
  end
182
190
 
183
191
  it 'knows when two windows are not equal' do
184
- win1 = browser.window(index: 0)
185
- win2 = browser.window(index: 1)
192
+ win1 = browser.window(title: 'window switching')
193
+ win2 = browser.window(title: 'closeable window')
186
194
 
187
195
  expect(win1).to_not eq win2
188
196
  end
@@ -211,38 +219,35 @@ describe 'Window' do
211
219
  browser.windows.reject(&:current?).each(&:close)
212
220
  end
213
221
 
214
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
215
- not_compliant_on :headless do
216
- describe '#exists?' do
217
- it 'returns false if previously referenced window is closed' do
218
- window = browser.window(title: 'closeable window')
219
- window.use
220
- browser.a(id: 'close').click
221
- Watir::Wait.until { browser.windows.size == 1 }
222
- expect(window).to_not be_present
223
- end
222
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
223
+ describe '#exists?' do
224
+ it 'returns false if previously referenced window is closed' do
225
+ window = browser.window(title: 'closeable window')
226
+ window.use
227
+ browser.a(id: 'close').click
228
+ Watir::Wait.until { browser.windows.size == 1 }
229
+ expect(window).to_not be_present
230
+ end
224
231
 
225
- it 'returns false if closed window is referenced' do
226
- browser.window(title: 'closeable window').use
227
- browser.a(id: 'close').click
228
- Watir::Wait.until { browser.windows.size == 1 }
229
- expect(browser.window).to_not exist
230
- end
232
+ 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
+ expect(browser.window).to_not exist
237
+ end
231
238
 
232
- it 'returns false if window closes during iteration' do
233
- browser.window(title: 'closeable window').use
234
- original_handle = browser.original_window.instance_variable_get('@handle')
235
- handles = browser.windows.map { |w| w.instance_variable_get('@handle') }
239
+ it 'returns false if window closes during iteration' do
240
+ browser.window(title: 'closeable window').use
241
+ original_handle = browser.original_window.instance_variable_get('@handle')
242
+ handles = browser.windows.map { |w| w.instance_variable_get('@handle') }
236
243
 
237
- browser.a(id: 'close').click
238
- Watir::Wait.until { browser.windows.size == 1 }
239
- allow(browser.wd).to receive(:window_handles).and_return(handles, [original_handle])
240
- expect(browser.window(title: 'closeable window')).to_not exist
241
- end
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
242
248
  end
243
249
  end
244
250
  end
245
-
246
251
  describe '#current?' do
247
252
  it 'returns false if the referenced window is closed' do
248
253
  original_window = browser.window
@@ -252,170 +257,168 @@ describe 'Window' do
252
257
  end
253
258
  end
254
259
 
255
- not_compliant_on :safari, :headless do
256
- describe '#eql?' do
257
- it 'should return false when checking equivalence to a closed window' do
258
- original_window = browser.window
259
- other_window = browser.window(index: 1)
260
- other_window.use
261
- original_window.close
262
- expect(other_window == original_window).to be false
263
- end
260
+ describe '#eql?' do
261
+ it 'should return false when checking equivalence to a closed window' do
262
+ original_window = browser.window
263
+ other_window = browser.window(title: 'closeable window')
264
+ other_window.use
265
+ original_window.close
266
+ expect(other_window == original_window).to be false
264
267
  end
265
268
  end
266
269
 
267
- not_compliant_on :headless do
268
- describe '#use' do
269
- it 'raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed' do
270
- original_window = browser.window
271
- browser.window(index: 1).use
272
- original_window.close
273
- expect { original_window.use }.to raise_no_matching_window_exception
274
- end
270
+ describe '#use' do
271
+ it 'raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed' do
272
+ original_window = browser.window
273
+ browser.window(title: 'closeable window').use
274
+ original_window.close
275
+ expect { original_window.use }.to raise_no_matching_window_exception
276
+ end
275
277
 
276
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
277
- it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
278
- browser.window(title: 'closeable window').use
279
- browser.a(id: 'close').click
280
- Watir::Wait.until { browser.windows.size == 1 }
281
- expect { browser.window.use }.to raise_no_matching_window_exception
282
- end
278
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
279
+ it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
280
+ browser.window(title: 'closeable window').use
281
+ browser.a(id: 'close').click
282
+ Watir::Wait.until { browser.windows.size == 1 }
283
+ expect { browser.window.use }.to raise_no_matching_window_exception
283
284
  end
284
285
  end
285
286
  end
286
287
 
287
- it 'raises an exception when using an element on a closed window' do
288
- window = browser.window(title: 'closeable window')
289
- window.use
290
- browser.a(id: 'close').click
291
- msg = 'browser window was closed'
292
- expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
288
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
289
+ it 'raises an exception when using an element on a closed window' do
290
+ window = browser.window(title: 'closeable window')
291
+ window.use
292
+ browser.a(id: 'close').click
293
+ msg = 'browser window was closed'
294
+ expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
295
+ end
293
296
  end
294
297
 
295
- it 'raises an exception when locating a closed window' do
296
- browser.window(title: 'closeable window').use
297
- handles = browser.windows.map(&:handle)
298
- browser.a(id: 'close').click
299
- allow(browser.wd).to receive(:window_handles).and_return(handles, [browser.original_window.handle])
300
- expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
298
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
299
+ 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
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
305
+ end
301
306
  end
302
307
 
303
- it 'raises an exception when locating a window closed during lookup' do
304
- browser.window(title: 'closeable window').use
305
- browser.a(id: 'close-delay').click
308
+ bug 'https://github.com/mozilla/geckodriver/issues/1770', :firefox do
309
+ it 'raises an exception when locating a window closed during lookup' do
310
+ browser.window(title: 'closeable window').use
311
+ browser.a(id: 'close-delay').click
306
312
 
307
- begin
308
- module Watir
309
- class Browser
310
- alias title_old title
313
+ begin
314
+ module Watir
315
+ class Browser
316
+ alias title_old title
311
317
 
312
- def title
313
- sleep 0.5
314
- title_old
318
+ def title
319
+ sleep 0.5
320
+ title_old
321
+ end
315
322
  end
316
323
  end
317
- end
318
324
 
319
- expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
320
- ensure
321
- module Watir
322
- class Browser
323
- alias title title_old
325
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
326
+ ensure
327
+ module Watir
328
+ class Browser
329
+ alias title title_old
330
+ end
324
331
  end
325
332
  end
326
333
  end
327
334
  end
328
335
  end
329
336
 
330
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
331
- not_compliant_on :headless do
332
- context 'with current window closed' do
333
- before do
334
- browser.goto WatirSpec.url_for('window_switching.html')
335
- browser.a(id: 'open').click
336
- Watir::Wait.until { browser.windows.size == 2 }
337
- browser.window(title: 'closeable window').use
338
- browser.a(id: 'close').click
339
- Watir::Wait.until { browser.windows.size == 1 }
337
+ bug 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException', :safari do
338
+ context 'with current window closed' do
339
+ before do
340
+ browser.goto WatirSpec.url_for('window_switching.html')
341
+ browser.a(id: 'open').click
342
+ Watir::Wait.until { browser.windows.size == 2 }
343
+ browser.window(title: 'closeable window').use
344
+ browser.a(id: 'close').click
345
+ Watir::Wait.until { browser.windows.size == 1 }
346
+ end
347
+
348
+ after do
349
+ browser.original_window.use
350
+ browser.windows.reject(&:current?).each(&:close)
351
+ end
352
+
353
+ describe '#present?' do
354
+ it 'should find window by index' do
355
+ expect(browser.window(index: 0)).to be_present
340
356
  end
341
357
 
342
- after do
343
- browser.window(index: 0).use
344
- browser.windows[1..-1].each(&:close)
358
+ it 'should find window by url' do
359
+ expect(browser.window(url: /window_switching\.html/)).to be_present
345
360
  end
346
361
 
347
- describe '#present?' do
348
- it 'should find window by index' do
349
- expect(browser.window(index: 0)).to be_present
362
+ it 'should find window by title' do
363
+ expect(browser.window(title: 'window switching')).to be_present
364
+ end
365
+ end
366
+
367
+ describe '#use' do
368
+ context 'switching windows without blocks' do
369
+ it 'by index' do
370
+ browser.window(index: 0).use
371
+ expect(browser.title).to be == 'window switching'
350
372
  end
351
373
 
352
- it 'should find window by url' do
353
- expect(browser.window(url: /window_switching\.html/)).to be_present
374
+ it 'by url' do
375
+ browser.window(url: /window_switching\.html/).use
376
+ expect(browser.title).to be == 'window switching'
354
377
  end
355
378
 
356
- it 'should find window by title' do
357
- expect(browser.window(title: 'window switching')).to be_present
379
+ it 'by title' do
380
+ browser.window(title: 'window switching').use
381
+ expect(browser.url).to match(/window_switching\.html/)
358
382
  end
359
383
  end
360
384
 
361
- describe '#use' do
362
- context 'switching windows without blocks' do
363
- it 'by index' do
364
- browser.window(index: 0).use
365
- expect(browser.title).to be == 'window switching'
366
- end
367
-
368
- it 'by url' do
369
- browser.window(url: /window_switching\.html/).use
370
- expect(browser.title).to be == 'window switching'
371
- end
372
-
373
- it 'by title' do
374
- browser.window(title: 'window switching').use
375
- expect(browser.url).to match(/window_switching\.html/)
376
- end
385
+ context 'Switching windows with blocks' do
386
+ it 'by index' do
387
+ browser.window(index: 0).use { expect(browser.title).to be == 'window switching' }
377
388
  end
378
389
 
379
- context 'Switching windows with blocks' do
380
- it 'by index' do
381
- browser.window(index: 0).use { expect(browser.title).to be == 'window switching' }
382
- end
383
-
384
- it 'by url' do
385
- browser.window(url: /window_switching\.html/).use { expect(browser.title).to be == 'window switching' }
386
- end
390
+ it 'by url' do
391
+ browser.window(url: /window_switching\.html/).use { expect(browser.title).to be == 'window switching' }
392
+ end
387
393
 
388
- it 'by title' do
389
- browser.window(title: 'window switching').use { expect(browser.url).to match(/window_switching\.html/) }
390
- end
394
+ it 'by title' do
395
+ browser.window(title: 'window switching').use { expect(browser.url).to match(/window_switching\.html/) }
391
396
  end
392
397
  end
393
398
  end
394
399
  end
395
400
  end
396
401
 
397
- context 'manipulating size and position' do
398
- before do
399
- browser.goto WatirSpec.url_for('window_switching.html')
400
- end
402
+ not_compliant_on :headless do
403
+ context 'manipulating size and position' do
404
+ before do
405
+ browser.goto WatirSpec.url_for('window_switching.html')
406
+ end
401
407
 
402
- not_compliant_on :headless do
403
408
  it 'should get the size of the current window' do
404
409
  size = browser.window.size
405
410
 
406
411
  expect(size.width).to eq browser.execute_script('return window.outerWidth;')
407
412
  expect(size.height).to eq browser.execute_script('return window.outerHeight;')
408
413
  end
409
- end
410
414
 
411
- it 'should get the position of the current window' do
412
- pos = browser.window.position
415
+ it 'should get the position of the current window' do
416
+ pos = browser.window.position
413
417
 
414
- expect(pos.x).to eq browser.execute_script('return window.screenX;')
415
- expect(pos.y).to eq browser.execute_script('return window.screenY;')
416
- end
418
+ expect(pos.x).to eq browser.execute_script('return window.screenX;')
419
+ expect(pos.y).to eq browser.execute_script('return window.screenY;')
420
+ end
417
421
 
418
- not_compliant_on :headless do
419
422
  it 'should resize the window' do
420
423
  initial_size = browser.window.size
421
424
  browser.window.resize_to(
@@ -428,9 +431,7 @@ describe 'Window' do
428
431
  expect(new_size.width).to eq initial_size.width - 20
429
432
  expect(new_size.height).to eq initial_size.height - 20
430
433
  end
431
- end
432
434
 
433
- not_compliant_on :headless, %i[remote firefox] do
434
435
  it 'should move the window' do
435
436
  initial_pos = browser.window.position
436
437
 
@@ -443,9 +444,7 @@ describe 'Window' do
443
444
  expect(new_pos.x).to eq initial_pos.x + 2
444
445
  expect(new_pos.y).to eq initial_pos.y + 2
445
446
  end
446
- end
447
447
 
448
- not_compliant_on :headless do
449
448
  compliant_on :window_manager do
450
449
  it 'should maximize the window' do
451
450
  initial_size = browser.window.size