watir 6.16.5 → 6.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +5 -5
  2. data/.github/actions/enable-safari/action.yml +11 -0
  3. data/.github/actions/install-chrome/action.yml +11 -0
  4. data/.github/workflows/linux.yml +61 -0
  5. data/.github/workflows/mac.yml +55 -0
  6. data/.github/workflows/unit.yml +37 -0
  7. data/.github/workflows/windows.yml +39 -0
  8. data/.rubocop.yml +32 -107
  9. data/.rubocop_todo.yml +36 -0
  10. data/CHANGES.md +52 -0
  11. data/Gemfile +3 -1
  12. data/LICENSE +2 -2
  13. data/README.md +9 -10
  14. data/Rakefile +4 -4
  15. data/lib/watir/adjacent.rb +8 -10
  16. data/lib/watir/after_hooks.rb +4 -4
  17. data/lib/watir/alert.rb +1 -0
  18. data/lib/watir/attribute_helper.rb +2 -0
  19. data/lib/watir/browser.rb +7 -3
  20. data/lib/watir/capabilities.rb +245 -97
  21. data/lib/watir/cookies.rb +3 -1
  22. data/lib/watir/element_collection.rb +21 -6
  23. data/lib/watir/elements/element.rb +66 -53
  24. data/lib/watir/elements/file_field.rb +1 -0
  25. data/lib/watir/elements/html_elements.rb +0 -1
  26. data/lib/watir/elements/iframe.rb +4 -3
  27. data/lib/watir/elements/link.rb +0 -9
  28. data/lib/watir/elements/radio.rb +1 -1
  29. data/lib/watir/elements/select.rb +22 -7
  30. data/lib/watir/generator/base/spec_extractor.rb +4 -4
  31. data/lib/watir/generator/html/generator.rb +1 -1
  32. data/lib/watir/has_window.rb +17 -15
  33. data/lib/watir/http_client.rb +17 -0
  34. data/lib/watir/js_execution.rb +3 -3
  35. data/lib/watir/js_snippets.rb +2 -2
  36. data/lib/watir/legacy_wait.rb +1 -1
  37. data/lib/watir/locators/element/selector_builder/xpath.rb +50 -15
  38. data/lib/watir/locators/element/selector_builder.rb +12 -13
  39. data/lib/watir/locators/text_field/selector_builder/xpath.rb +3 -1
  40. data/lib/watir/locators.rb +1 -3
  41. data/lib/watir/logger.rb +7 -20
  42. data/lib/watir/radio_set.rb +2 -2
  43. data/lib/watir/user_editable.rb +6 -2
  44. data/lib/watir/version.rb +1 -1
  45. data/lib/watir/wait/timer.rb +1 -1
  46. data/lib/watir/wait.rb +2 -0
  47. data/lib/watir/window.rb +8 -4
  48. data/lib/watir/window_collection.rb +114 -0
  49. data/lib/watir-webdriver.rb +1 -1
  50. data/lib/watir.rb +3 -1
  51. data/lib/watirspec/guards.rb +1 -1
  52. data/lib/watirspec/implementation.rb +3 -5
  53. data/lib/watirspec/rake_tasks.rb +2 -0
  54. data/lib/watirspec/runner.rb +6 -2
  55. data/lib/watirspec/server.rb +1 -1
  56. data/lib/watirspec.rb +2 -1
  57. data/spec/spec_helper.rb +2 -7
  58. data/spec/unit/capabilities_spec.rb +1234 -18
  59. data/spec/unit/container_spec.rb +1 -1
  60. data/spec/unit/logger_spec.rb +5 -7
  61. data/spec/unit/match_elements/element_spec.rb +17 -15
  62. data/spec/unit/selector_builder/button_spec.rb +16 -15
  63. data/spec/unit/selector_builder/element_spec.rb +58 -9
  64. data/spec/unit/selector_builder/text_field_spec.rb +14 -14
  65. data/spec/unit/unit_helper.rb +2 -4
  66. data/spec/watirspec/after_hooks_spec.rb +58 -68
  67. data/spec/watirspec/alert_spec.rb +69 -79
  68. data/spec/watirspec/browser_spec.rb +51 -48
  69. data/spec/watirspec/cookies_spec.rb +52 -37
  70. data/spec/watirspec/drag_and_drop_spec.rb +14 -38
  71. data/spec/watirspec/elements/button_spec.rb +2 -0
  72. data/spec/watirspec/elements/buttons_spec.rb +1 -1
  73. data/spec/watirspec/elements/checkbox_spec.rb +8 -4
  74. data/spec/watirspec/elements/date_field_spec.rb +18 -9
  75. data/spec/watirspec/elements/date_time_field_spec.rb +3 -4
  76. data/spec/watirspec/elements/div_spec.rb +62 -54
  77. data/spec/watirspec/elements/element_spec.rb +73 -88
  78. data/spec/watirspec/elements/elements_spec.rb +12 -3
  79. data/spec/watirspec/elements/filefield_spec.rb +25 -50
  80. data/spec/watirspec/elements/form_spec.rb +6 -8
  81. data/spec/watirspec/elements/frame_spec.rb +10 -13
  82. data/spec/watirspec/elements/iframe_spec.rb +12 -9
  83. data/spec/watirspec/elements/iframes_spec.rb +2 -2
  84. data/spec/watirspec/elements/link_spec.rb +23 -12
  85. data/spec/watirspec/elements/links_spec.rb +11 -3
  86. data/spec/watirspec/elements/option_spec.rb +15 -17
  87. data/spec/watirspec/elements/select_list_spec.rb +222 -117
  88. data/spec/watirspec/elements/text_field_spec.rb +8 -4
  89. data/spec/watirspec/elements/tr_spec.rb +0 -9
  90. data/spec/watirspec/html/forms_with_input_elements.html +1 -0
  91. data/spec/watirspec/html/iframes.html +3 -0
  92. data/spec/watirspec/html/non_control_elements.html +4 -4
  93. data/spec/watirspec/html/right_click.html +12 -0
  94. data/spec/watirspec/html/special_chars.html +3 -0
  95. data/spec/watirspec/html/wait.html +6 -6
  96. data/spec/watirspec/html/window_switching.html +10 -0
  97. data/spec/watirspec/legacy_wait_spec.rb +216 -0
  98. data/spec/watirspec/special_chars_spec.rb +10 -0
  99. data/spec/watirspec/support/rspec_matchers.rb +33 -14
  100. data/spec/watirspec/user_editable_spec.rb +1 -1
  101. data/spec/watirspec/wait_spec.rb +257 -305
  102. data/spec/watirspec/window_switching_spec.rb +347 -211
  103. data/spec/watirspec_helper.rb +17 -20
  104. data/support/doctest_helper.rb +0 -2
  105. data/watir.gemspec +6 -7
  106. metadata +37 -26
  107. data/.travis.yml +0 -84
  108. data/appveyor.yml +0 -12
  109. data/lib/watir/elements/area.rb +0 -10
  110. data/spec/watirspec/relaxed_locate_spec.rb +0 -113
@@ -97,7 +97,7 @@ describe 'Div' do
97
97
  expect(browser.div(index: 0).text.strip).to eq ''
98
98
  end
99
99
 
100
- not_compliant_on :safari do
100
+ bug 'Safari is not filtering out hidden text', :safari do
101
101
  it 'returns an empty string if the div is hidden' do
102
102
  expect(browser.div(id: 'hidden').text).to eq ''
103
103
  end
@@ -137,8 +137,10 @@ describe 'Div' do
137
137
  end
138
138
 
139
139
  not_compliant_on :watigiri do
140
- it 'throws deprecation when no longer matched by text content' do
141
- expect { browser.div(text: /some visible$/).locate }.to have_deprecated_text_regexp
140
+ bug 'Safari is not filtering out hidden text', :safari do
141
+ it 'throws deprecation when no longer matched by text content' do
142
+ expect { browser.div(text: /some visible$/).locate }.to have_deprecated_text_regexp
143
+ end
142
144
  end
143
145
  end
144
146
 
@@ -148,77 +150,83 @@ describe 'Div' do
148
150
  end
149
151
  end
150
152
 
151
- # Note: This will work after:text_regexp deprecation removed
152
153
  not_compliant_on :watigiri do
153
- it 'does not locate entire content with regular expressions' do
154
- expect(browser.div(text: /some visible some hidden/)).to_not exist
154
+ bug 'Safari is not filtering out hidden text', :safari do
155
+ it 'does not locate entire content with regular expressions' do
156
+ expect(browser.div(text: /some visible some hidden/)).to_not exist
157
+ end
155
158
  end
156
159
  end
157
160
  end
158
161
  end
159
162
 
160
163
  # Manipulation methods
161
- not_compliant_on :headless do
162
- describe '#click' do
163
- it 'fires events when clicked' do
164
- expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
165
- browser.div(id: 'best_language').click
166
- expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
167
- end
164
+ describe '#click' do
165
+ it 'fires events when clicked' do
166
+ expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
168
167
 
169
- it 'raises UnknownObjectException if the element does not exist' do
170
- expect { browser.div(id: 'no_such_id').click }.to raise_unknown_object_exception
171
- expect { browser.div(title: 'no_such_title').click }.to raise_unknown_object_exception
172
- expect { browser.div(index: 1337).click }.to raise_unknown_object_exception
173
- expect { browser.div(xpath: "//div[@id='no_such_id']").click }.to raise_unknown_object_exception
174
- end
168
+ div = browser.div(id: 'best_language')
169
+ div.scroll.to
170
+ div.click
171
+ expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
172
+ end
175
173
 
176
- it 'includes custom message if element with a custom attribute does not exist' do
177
- message = /Watir treated \[\"custom_attribute\"\] as a non-HTML compliant attribute, ensure that was intended/
178
- expect { browser.div(custom_attribute: 'not_there').click }.to raise_unknown_object_exception(message)
179
- end
174
+ it 'raises UnknownObjectException if the element does not exist' do
175
+ expect { browser.div(id: 'no_such_id').click }.to raise_unknown_object_exception
176
+ expect { browser.div(title: 'no_such_title').click }.to raise_unknown_object_exception
177
+ expect { browser.div(index: 1337).click }.to raise_unknown_object_exception
178
+ expect { browser.div(xpath: "//div[@id='no_such_id']").click }.to raise_unknown_object_exception
180
179
  end
181
180
 
182
- describe '#click!' do
183
- it 'fires events when clicked' do
184
- expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
185
- browser.div(id: 'best_language').click!
186
- expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
187
- end
181
+ it 'includes custom message if element with a custom attribute does not exist' do
182
+ message = /Watir treated \["custom_attribute"\] as a non-HTML compliant attribute, ensure that was intended/
183
+ expect { browser.div(custom_attribute: 'not_there').click }.to raise_unknown_object_exception(message)
184
+ end
185
+ end
188
186
 
189
- it 'raises UnknownObjectException if the element does not exist' do
190
- expect { browser.div(id: 'no_such_id').click! }.to raise_unknown_object_exception
191
- expect { browser.div(title: 'no_such_title').click! }.to raise_unknown_object_exception
192
- expect { browser.div(index: 1337).click! }.to raise_unknown_object_exception
193
- expect { browser.div(xpath: "//div[@id='no_such_id']").click! }.to raise_unknown_object_exception
194
- end
187
+ describe '#click!' do
188
+ it 'fires events when clicked' do
189
+ expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
190
+ browser.div(id: 'best_language').click!
191
+ expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
192
+ end
193
+
194
+ it 'raises UnknownObjectException if the element does not exist' do
195
+ expect { browser.div(id: 'no_such_id').click! }.to raise_unknown_object_exception
196
+ expect { browser.div(title: 'no_such_title').click! }.to raise_unknown_object_exception
197
+ expect { browser.div(index: 1337).click! }.to raise_unknown_object_exception
198
+ expect { browser.div(xpath: "//div[@id='no_such_id']").click! }.to raise_unknown_object_exception
195
199
  end
196
200
  end
197
201
 
198
- not_compliant_on :safari do
199
- bug 'MoveTargetOutOfBoundsError', :firefox do
200
- describe '#double_click' do
201
- it 'fires the ondblclick event' do
202
- browser.div(id: 'html_test').double_click
203
- expect(messages).to include('double clicked')
204
- end
202
+ bug 'command correctly received, but action not taken', :safari, :w3c do
203
+ describe '#double_click' do
204
+ it 'fires the ondblclick event' do
205
+ div = browser.div(id: 'html_test')
206
+ div.scroll.to
207
+ div.double_click
208
+ expect(messages).to include('double clicked')
205
209
  end
210
+ end
206
211
 
207
- describe '#double_click!' do
208
- it 'fires the ondblclick event' do
209
- browser.div(id: 'html_test').double_click!
210
- expect(messages).to include('double clicked')
211
- end
212
+ describe '#double_click!' do
213
+ it 'fires the ondblclick event' do
214
+ browser.div(id: 'html_test').double_click!
215
+ expect(messages).to include('double clicked')
212
216
  end
213
217
  end
214
218
 
215
- not_compliant_on :firefox do
216
- describe '#right_click' do
217
- it 'fires the oncontextmenu event' do
218
- browser.goto(WatirSpec.url_for('right_click.html'))
219
- browser.div(id: 'click').right_click
220
- expect(messages.first).to eq 'right-clicked'
221
- end
219
+ describe '#right_click' do
220
+ it 'fires the oncontextmenu event' do
221
+ browser.goto(WatirSpec.url_for('right_click.html'))
222
+ browser.div(id: 'click').right_click
223
+ expect(messages.first).to eq 'right-clicked'
224
+ end
225
+
226
+ it 'accepts modifiers' do
227
+ browser.goto(WatirSpec.url_for('right_click.html'))
228
+ browser.div(id: 'click-logger').right_click(:control, :alt)
229
+ expect(event_log.first).to eq('control=true alt=true')
222
230
  end
223
231
  end
224
232
  end
@@ -104,24 +104,30 @@ describe 'Element' do
104
104
 
105
105
  expect(browser.element(visible_text: 'all visible')).to exist
106
106
  expect(browser.element(visible_text: /all visible/)).to exist
107
- expect(browser.element(visible_text: 'some visible')).to exist
108
107
  expect(browser.element(visible_text: /some visible/)).to exist
109
- expect(browser.element(visible_text: 'none visible')).not_to exist
110
- expect(browser.element(visible_text: /none visible/)).not_to exist
111
-
112
108
  expect(browser.element(visible_text: 'Link 2', class: 'external')).to exist
113
109
  expect(browser.element(visible_text: /Link 2/, class: 'external')).to exist
114
110
  end
115
111
 
112
+ bug 'Safari is not filtering out hidden text', :safari do
113
+ it 'finds elements by visible text in spite of hidden text' do
114
+ browser.goto WatirSpec.url_for('non_control_elements.html')
115
+
116
+ expect(browser.element(visible_text: 'some visible')).to exist
117
+ expect(browser.element(visible_text: 'none visible')).not_to exist
118
+ expect(browser.element(visible_text: /none visible/)).not_to exist
119
+ end
120
+ end
121
+
116
122
  it 'raises exception unless value is a String or a RegExp' do
117
123
  browser.goto WatirSpec.url_for('non_control_elements.html')
118
- msg = /expected one of \[String, Regexp\], got 7\:(Fixnum|Integer)/
124
+ msg = /expected one of \[String, Regexp\], got 7:Integer/
119
125
  expect { browser.element(visible_text: 7).exists? }.to raise_exception(TypeError, msg)
120
126
  end
121
127
 
122
128
  it 'raises exception unless key is valid' do
123
129
  browser.goto WatirSpec.url_for('non_control_elements.html')
124
- msg = /Unable to build XPath using 7:(Fixnum|Integer)/
130
+ msg = /Unable to build XPath using 7:Integer/
125
131
  expect { browser.element(7 => /foo/).exists? }.to raise_exception(Watir::Exception::Error, msg)
126
132
  end
127
133
  end
@@ -225,32 +231,29 @@ describe 'Element' do
225
231
 
226
232
  describe '#visible?' do
227
233
  it 'returns true if the element is visible' do
228
- msg = /WARN Watir \[\"visible_element\"\]/
234
+ msg = /WARN Watir \["visible_element"\]/
229
235
  expect {
230
236
  expect(browser.text_field(id: 'new_user_email')).to be_visible
231
237
  }.to output(msg).to_stdout_from_any_process
232
238
  end
233
239
 
234
240
  it 'raises UnknownObjectException exception if the element does not exist' do
235
- msg = /WARN Watir \[\"visible_element\"\]/
241
+ msg = /WARN Watir \["visible_element"\]/
236
242
  expect {
237
243
  expect { browser.text_field(id: 'no_such_id').visible? }.to raise_unknown_object_exception
238
244
  }.to output(msg).to_stdout_from_any_process
239
245
  end
240
246
 
241
- it 'raises UnknownObjectException exception if the element is stale' do
247
+ it 'handles staleness' do
242
248
  element = browser.text_field(id: 'new_user_email').locate
243
249
 
244
- browser.refresh
250
+ allow(element).to receive(:stale?).and_return(true)
245
251
 
246
- expect(element).to be_stale
247
- expect {
248
- expect { element.visible? }.to raise_unknown_object_exception
249
- }.to have_deprecated_stale_visible
252
+ expect(element).to be_visible
250
253
  end
251
254
 
252
255
  it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do
253
- msg = /WARN Watir \[\"visible_element\"\]/
256
+ msg = /WARN Watir \["visible_element"\]/
254
257
  expect {
255
258
  expect(browser.div(id: 'visible_child')).to be_visible
256
259
  }.to output(msg).to_stdout_from_any_process
@@ -261,7 +264,7 @@ describe 'Element' do
261
264
  end
262
265
 
263
266
  it "returns false if the element has style='display: none;'" do
264
- msg = /WARN Watir \[\"visible_element\"\]/
267
+ msg = /WARN Watir \["visible_element"\]/
265
268
  expect {
266
269
  expect(browser.div(id: 'changed_language')).to_not be_visible
267
270
  }.to output(msg).to_stdout_from_any_process
@@ -295,9 +298,7 @@ describe 'Element' do
295
298
  element.cache = wd
296
299
 
297
300
  browser.refresh
298
- expect {
299
- expect(element).to_not exist
300
- }.to have_deprecated_stale_exists
301
+ expect(element).to_not exist
301
302
  end
302
303
  end
303
304
 
@@ -306,15 +307,12 @@ describe 'Element' do
306
307
  browser.goto WatirSpec.url_for('removed_element.html')
307
308
  end
308
309
 
309
- it 'element from a collection returns false when it becomes stale' do
310
+ it 'handles staleness in a collection' do
310
311
  element = browser.divs(id: 'text').first.locate
311
312
 
312
- browser.refresh
313
+ allow(element).to receive(:stale?).and_return(true)
313
314
 
314
- expect(element).to be_stale
315
- expect {
316
- expect(element).to_not exist
317
- }.to have_deprecated_stale_exists
315
+ expect(element).to exist
318
316
  end
319
317
 
320
318
  it 'returns false when tag name does not match id' do
@@ -340,36 +338,11 @@ describe 'Element' do
340
338
  expect(browser.div(id: 'should-not-exist')).to_not be_present
341
339
  end
342
340
 
343
- it 'returns false if the element is stale' do
344
- element = browser.div(id: 'foo').locate
345
-
346
- browser.refresh
347
-
348
- expect(element).to be_stale
349
-
350
- expect {
351
- expect(element).to_not be_present
352
- }.to have_deprecated_stale_present
353
- end
354
-
355
- it 'does not raise staleness deprecation if element no longer exists in DOM' do
341
+ it 'handles staleness' do
356
342
  element = browser.div(id: 'foo').locate
357
- browser.goto(WatirSpec.url_for('iframes.html'))
358
343
 
359
- expect { element.present? }.to_not have_deprecated_stale_present
360
- end
361
-
362
- # TODO: Documents Current Behavior, but needs to be refactored/removed
363
- it 'returns true the second time if the element is stale' do
364
- element = browser.div(id: 'foo').locate
344
+ allow(element).to receive(:stale?).and_return(true)
365
345
 
366
- browser.refresh
367
-
368
- expect(element).to be_stale
369
-
370
- expect {
371
- expect(element).to_not be_present
372
- }.to have_deprecated_stale_present
373
346
  expect(element).to be_present
374
347
  end
375
348
  end
@@ -535,8 +508,8 @@ describe 'Element' do
535
508
  expect(events).to eq 10
536
509
  end
537
510
 
538
- bug 'http://code.google.com/p/chromium/issues/detail?id=93879', :chrome do
539
- not_compliant_on :safari, :firefox do
511
+ bug 'http://code.google.com/p/chromium/issues/detail?id=93879', %i[chrome macosx] do
512
+ bug 'special keys are not working correctly', :safari, :firefox do
540
513
  it 'performs key combinations' do
541
514
  receiver.send_keys 'foo'
542
515
  receiver.send_keys [@c, 'a']
@@ -562,14 +535,14 @@ describe 'Element' do
562
535
  end
563
536
 
564
537
  describe '#click' do
565
- bug 'https://github.com/mozilla/geckodriver/issues/1375', :firefox do
566
- it 'accepts modifiers' do
567
- begin
538
+ bug 'Element has been located but Safari does not recognize it', :safari do
539
+ bug 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=2732', :w3c do
540
+ it 'accepts modifiers' do
568
541
  browser.a.click(:shift)
542
+ browser.wait_until { |b| b.windows.size > 1 }
569
543
  expect(browser.windows.size).to eq 2
570
544
  ensure
571
545
  browser.windows.reject(&:current?).each(&:close)
572
- expect(browser.windows.size).to eq 1
573
546
  end
574
547
  end
575
548
  end
@@ -597,12 +570,13 @@ describe 'Element' do
597
570
  end
598
571
 
599
572
  describe '#hover' do
600
- not_compliant_on :internet_explorer, :safari do
573
+ not_compliant_on :internet_explorer do
601
574
  it 'should hover over the element' do
602
575
  browser.goto WatirSpec.url_for('hover.html')
603
576
  link = browser.a
604
577
 
605
578
  expect(link.style('font-size')).to eq '10px'
579
+ link.scroll.to
606
580
  link.hover
607
581
  link.wait_until { |l| l.style('font-size') == '20px' }
608
582
  expect(link.style('font-size')).to eq '20px'
@@ -703,19 +677,22 @@ describe 'Element' do
703
677
  end
704
678
  end
705
679
 
706
- not_compliant_on %i[remote firefox] do
707
- describe '#scroll_into_view' do
708
- it 'scrolls element into view' do
709
- el = browser.button(name: 'new_user_image')
710
- element_center = el.center['y']
680
+ describe '#scroll_into_view' do
681
+ it 'scrolls element into view' do
682
+ initial_size = browser.window.size
683
+ browser.window.resize_to(initial_size.width, 800)
684
+
685
+ el = browser.button(name: 'new_user_image')
686
+ element_center = el.center['y']
711
687
 
712
- bottom_viewport_script = 'return window.pageYOffset + window.innerHeight'
713
- expect(browser.execute_script(bottom_viewport_script)).to be < element_center
688
+ bottom_viewport_script = 'return window.pageYOffset + window.innerHeight'
689
+ expect(browser.execute_script(bottom_viewport_script)).to be < element_center
714
690
 
691
+ expect {
715
692
  expect(el.scroll_into_view).to be_a Selenium::WebDriver::Point
693
+ }.to have_deprecated_scroll_into_view
716
694
 
717
- expect(browser.execute_script(bottom_viewport_script)).to be > element_center
718
- end
695
+ expect(browser.execute_script(bottom_viewport_script)).to be > element_center
719
696
  end
720
697
  end
721
698
 
@@ -732,10 +709,13 @@ describe 'Element' do
732
709
  describe '#size' do
733
710
  it 'returns size of element' do
734
711
  size = browser.button(name: 'new_user_image').size
735
-
736
712
  expect(size).to be_a Selenium::WebDriver::Dimension
737
- expect(size['width']).to eq 104.0
738
- expect(size['height']).to eq 70.0
713
+
714
+ expected_width = browser.name == :safari ? 105 : 104
715
+ expected_height = browser.name == :safari ? 71 : 70
716
+
717
+ expect(size['width']).to eq expected_width
718
+ expect(size['height']).to eq expected_height
739
719
  end
740
720
  end
741
721
 
@@ -743,7 +723,8 @@ describe 'Element' do
743
723
  it 'returns height of element' do
744
724
  height = browser.button(name: 'new_user_image').height
745
725
 
746
- expect(height).to eq 70.0
726
+ expected_height = browser.name == :safari ? 71 : 70
727
+ expect(height).to eq expected_height
747
728
  end
748
729
  end
749
730
 
@@ -751,7 +732,8 @@ describe 'Element' do
751
732
  it 'returns width of element' do
752
733
  width = browser.button(name: 'new_user_image').width
753
734
 
754
- expect(width).to eq 104.0
735
+ expected_width = browser.name == :safari ? 105 : 104
736
+ expect(width).to eq expected_width
755
737
  end
756
738
  end
757
739
 
@@ -902,35 +884,36 @@ describe 'Element' do
902
884
  describe '#obscured?' do
903
885
  before { browser.goto WatirSpec.url_for('obscured.html') }
904
886
 
905
- it 'returns false if element\'s center is not covered' do
887
+ it 'returns false if element center is not covered' do
906
888
  btn = browser.button(id: 'not_obscured')
907
889
  expect(btn).not_to be_obscured
908
890
  expect { btn.click }.not_to raise_exception
909
891
  end
910
892
 
911
- it 'returns false if element\'s center is covered by its descendant' do
893
+ it 'returns false if element center is covered by its descendant' do
912
894
  btn = browser.button(id: 'has_descendant')
913
895
  expect(btn).not_to be_obscured
914
896
  expect { btn.click }.not_to raise_exception
915
897
  end
916
898
 
917
- it 'returns true if element\'s center is covered by a non-descendant' do
899
+ it 'returns true if element center is covered by a non-descendant' do
918
900
  btn = browser.button(id: 'obscured')
919
901
  expect(btn).to be_obscured
920
- not_compliant_on :chrome do
902
+ not_compliant_on :chrome, :safari do
921
903
  expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
922
904
  end
923
905
  compliant_on :chrome do
924
- expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::UnknownError)
906
+ expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
907
+ end
908
+ compliant_on :safari do
909
+ expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::WebDriverError)
925
910
  end
926
911
  end
927
912
 
928
- not_compliant_on %i[firefox appveyor] do
929
- it 'returns false if element\'s center is surrounded by non-descendants' do
930
- btn = browser.button(id: 'surrounded')
931
- expect(btn).not_to be_obscured
932
- expect { btn.click }.not_to raise_exception
933
- end
913
+ it 'returns false if element center is surrounded by non-descendants' do
914
+ btn = browser.button(id: 'surrounded')
915
+ expect(btn).not_to be_obscured
916
+ expect { btn.click }.not_to raise_exception
934
917
  end
935
918
 
936
919
  it 'scrolls interactive element into view before checking if obscured' do
@@ -945,10 +928,12 @@ describe 'Element' do
945
928
  expect { div.click }.not_to raise_exception
946
929
  end
947
930
 
948
- it 'returns true if element cannot be scrolled into view' do
949
- btn = browser.button(id: 'off_screen')
950
- expect(btn).to be_obscured
951
- expect { btn.click }.to raise_unknown_object_exception
931
+ bug 'Safari is throwing click intercepted here', :safari do
932
+ it 'returns true if element cannot be scrolled into view' do
933
+ btn = browser.button(id: 'off_screen')
934
+ expect(btn).to be_obscured
935
+ expect { btn.click }.to raise_unknown_object_exception
936
+ end
952
937
  end
953
938
 
954
939
  it 'returns true if element is hidden' do
@@ -37,12 +37,21 @@ describe 'Elements' do
37
37
  it 'finds elements by visible text' do
38
38
  browser.goto WatirSpec.url_for('non_control_elements.html')
39
39
  container = browser.div(id: 'visible_text')
40
+
40
41
  expect(container.elements(visible_text: 'all visible').count).to eq(1)
41
42
  expect(container.elements(visible_text: /all visible/).count).to eq(1)
42
- expect(container.elements(visible_text: 'some visible').count).to eq(1)
43
43
  expect(container.elements(visible_text: /some visible/).count).to eq(1)
44
- expect(container.elements(visible_text: 'none visible').count).to eq(0)
45
- expect(container.elements(visible_text: /none visible/).count).to eq(0)
44
+ end
45
+
46
+ bug 'Safari is not filtering out hidden text', :safari do
47
+ it 'finds elements in spite of hidden text' do
48
+ browser.goto WatirSpec.url_for('non_control_elements.html')
49
+ container = browser.div(id: 'visible_text')
50
+
51
+ expect(container.elements(visible_text: 'some visible').count).to eq(1)
52
+ expect(container.elements(visible_text: 'none visible').count).to eq(0)
53
+ expect(container.elements(visible_text: /none visible/).count).to eq(0)
54
+ end
46
55
  end
47
56
  end
48
57
  end
@@ -92,66 +92,41 @@ describe 'FileField' do
92
92
  # Manipulation methods
93
93
 
94
94
  describe '#set' do
95
- not_compliant_on :safari do
96
- bug 'https://github.com/mozilla/geckodriver/issues/858', :firefox do
97
- it 'is able to set a file path in the field and click the upload button and fire the onchange event' do
98
- browser.goto WatirSpec.url_for('forms_with_input_elements.html')
95
+ it 'is able to set a file path in the field and click the upload button and fire the onchange event' do
96
+ browser.goto WatirSpec.url_for('forms_with_input_elements.html')
99
97
 
100
- path = File.expand_path(__FILE__)
101
- element = browser.file_field(name: 'new_user_portrait')
98
+ element = browser.file_field(name: 'new_user_portrait')
99
+ element.upload __FILE__
102
100
 
103
- element.set path
101
+ expect(element.value).to include(File.basename(__FILE__)) # only some browser will return the full path
102
+ expect(messages.first).to include(File.basename(__FILE__))
104
103
 
105
- expect(element.value).to include(File.basename(path)) # only some browser will return the full path
106
- expect(messages.first).to include(File.basename(path))
107
-
108
- browser.button(name: 'new_user_submit').click
109
- end
110
- end
104
+ browser.button(name: 'new_user_submit').click
105
+ end
111
106
 
112
- it 'raises an error if the file does not exist' do
113
- expect {
114
- browser.file_field.set(File.join(Dir.tmpdir, 'unlikely-to-exist'))
115
- }.to raise_error(Errno::ENOENT)
116
- end
107
+ it 'raises an error if the file does not exist' do
108
+ expect {
109
+ browser.file_field.set(File.join(Dir.tmpdir, 'unlikely-to-exist'))
110
+ }.to raise_error(Errno::ENOENT)
117
111
  end
118
112
  end
119
113
 
120
- not_compliant_on :safari do
121
- describe '#value=' do
122
- bug 'https://github.com/mozilla/geckodriver/issues/858', :firefox do
123
- it 'is able to set a file path in the field and click the upload button and fire the onchange event' do
124
- browser.goto WatirSpec.url_for('forms_with_input_elements.html')
125
-
126
- path = File.expand_path(__FILE__)
127
- element = browser.file_field(name: 'new_user_portrait')
114
+ describe '#value=' do
115
+ it 'is able to set a file path in the field and click the upload button and fire the onchange event' do
116
+ browser.goto WatirSpec.url_for('forms_with_input_elements.html')
128
117
 
129
- element.value = path
130
- expect(element.value).to include(File.basename(path)) # only some browser will return the full path
131
- end
132
- end
133
-
134
- not_compliant_on :internet_explorer, :firefox, :chrome do
135
- it 'does not raise an error if the file does not exist' do
136
- path = File.join(Dir.tmpdir, 'unlikely-to-exist')
137
- browser.file_field.value = path
138
-
139
- expected = path
140
- expected.tr!('/', '\\') if Selenium::WebDriver::Platform.windows?
118
+ path = File.expand_path(__FILE__)
119
+ element = browser.file_field(name: 'new_user_portrait')
141
120
 
142
- # only some browsers will return the full path
143
- expect(browser.file_field.value).to include(File.basename(expected))
144
- end
145
- end
121
+ element.value = path
122
+ expect(element.value).to include(File.basename(path)) # only some browser will return the full path
123
+ end
146
124
 
147
- not_compliant_on :internet_explorer, %i[chrome windows] do
148
- bug 'Raises InvalidArgumentError: File not found', :firefox do
149
- it 'does not alter its argument' do
150
- value = File.expand_path '.travis.yml'
151
- browser.file_field.value = value
152
- expect(value).to match(/\.travis\.yml$/)
153
- end
154
- end
125
+ not_compliant_on :internet_explorer, %i[chrome windows] do
126
+ it 'does not alter its argument' do
127
+ value = File.expand_path '.rubocop.yml'
128
+ browser.file_field.value = value
129
+ expect(value).to match(/\.rubocop\.yml$/)
155
130
  end
156
131
  end
157
132
  end
@@ -51,14 +51,12 @@ describe 'Form' do
51
51
  expect(browser.text).to include('Semantic table')
52
52
  end
53
53
 
54
- not_compliant_on :safari do
55
- it 'triggers onsubmit event and takes its result into account' do
56
- form = browser.form(name: 'user_new')
57
- form.submit
58
- expect(form).to exist
59
- expect(messages.size).to eq 1
60
- expect(messages[0]).to eq 'submit'
61
- end
54
+ it 'triggers onsubmit event and takes its result into account' do
55
+ form = browser.form(name: 'user_new')
56
+ form.submit
57
+ expect(form).to exist
58
+ expect(messages.size).to eq 1
59
+ expect(messages[0]).to eq 'submit'
62
60
  end
63
61
 
64
62
  compliant_on :relaxed_locate do