watir 6.11.0 → 6.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +17 -0
  3. data/lib/watir.rb +5 -14
  4. data/lib/watir/adjacent.rb +2 -2
  5. data/lib/watir/alert.rb +1 -1
  6. data/lib/watir/browser.rb +11 -2
  7. data/lib/watir/capabilities.rb +8 -3
  8. data/lib/watir/container.rb +4 -1
  9. data/lib/watir/element_collection.rb +24 -10
  10. data/lib/watir/elements/element.rb +19 -9
  11. data/lib/watir/elements/select.rb +3 -2
  12. data/lib/watir/js_execution.rb +20 -9
  13. data/lib/watir/legacy_wait.rb +3 -2
  14. data/lib/watir/locators.rb +6 -6
  15. data/lib/watir/locators/element/locator.rb +42 -18
  16. data/lib/watir/locators/element/selector_builder/xpath.rb +5 -1
  17. data/lib/watir/logger.rb +24 -11
  18. data/lib/watir/screenshot.rb +9 -2
  19. data/lib/watir/wait.rb +36 -16
  20. data/lib/watirspec.rb +2 -1
  21. data/lib/watirspec/guards.rb +1 -1
  22. data/lib/watirspec/runner.rb +8 -2
  23. data/lib/watirspec/server.rb +1 -1
  24. data/spec/{container_spec.rb → unit/container_spec.rb} +4 -2
  25. data/spec/{element_locator_spec.rb → unit/element_locator_spec.rb} +30 -5
  26. data/spec/unit/logger_spec.rb +78 -0
  27. data/spec/unit/unit_helper.rb +6 -0
  28. data/spec/unit/wait_spec.rb +95 -0
  29. data/spec/watirspec/alert_spec.rb +1 -8
  30. data/spec/watirspec/browser_spec.rb +241 -0
  31. data/spec/{click_spec.rb → watirspec/click_spec.rb} +0 -0
  32. data/spec/watirspec/elements/checkbox_spec.rb +1 -1
  33. data/spec/watirspec/elements/del_spec.rb +1 -1
  34. data/spec/watirspec/elements/div_spec.rb +19 -8
  35. data/spec/watirspec/elements/divs_spec.rb +12 -0
  36. data/spec/watirspec/elements/dt_spec.rb +2 -2
  37. data/spec/watirspec/elements/element_spec.rb +220 -9
  38. data/spec/watirspec/elements/hn_spec.rb +1 -1
  39. data/spec/watirspec/elements/hns_spec.rb +1 -1
  40. data/spec/{input_spec.rb → watirspec/elements/input_spec.rb} +0 -0
  41. data/spec/watirspec/elements/ins_spec.rb +1 -1
  42. data/spec/watirspec/elements/labels_spec.rb +1 -1
  43. data/spec/watirspec/elements/li_spec.rb +1 -1
  44. data/spec/watirspec/elements/link_spec.rb +1 -2
  45. data/spec/watirspec/elements/ol_spec.rb +2 -4
  46. data/spec/watirspec/elements/p_spec.rb +1 -1
  47. data/spec/watirspec/elements/pre_spec.rb +1 -1
  48. data/spec/watirspec/elements/select_list_spec.rb +2 -4
  49. data/spec/watirspec/elements/span_spec.rb +2 -3
  50. data/spec/watirspec/elements/strong_spec.rb +1 -1
  51. data/spec/watirspec/elements/table_spec.rb +2 -6
  52. data/spec/watirspec/elements/td_spec.rb +1 -2
  53. data/spec/watirspec/elements/text_field_spec.rb +11 -0
  54. data/spec/watirspec/elements/text_fields_spec.rb +1 -1
  55. data/spec/watirspec/elements/ul_spec.rb +1 -2
  56. data/spec/watirspec/html/forms_with_input_elements.html +2 -1
  57. data/spec/watirspec/html/wait.html +12 -0
  58. data/spec/watirspec/relaxed_locate_spec.rb +28 -27
  59. data/spec/{special_chars_spec.rb → watirspec/special_chars_spec.rb} +0 -0
  60. data/spec/watirspec/support/rspec_matchers.rb +88 -0
  61. data/spec/watirspec/wait_spec.rb +5 -104
  62. data/spec/watirspec/window_switching_spec.rb +1 -1
  63. data/watir.gemspec +1 -1
  64. metadata +21 -21
  65. data/spec/browser_spec.rb +0 -280
  66. data/spec/element_spec.rb +0 -150
  67. data/spec/logger_spec.rb +0 -46
  68. data/spec/watirspec/support/raise_exception_matchers.rb +0 -36
@@ -169,7 +169,7 @@ describe "CheckBox" do
169
169
 
170
170
  it "returns false if the checkbox button is disabled" do
171
171
  expect(browser.checkbox(id: "new_user_interests_dentistry")).to_not be_enabled
172
- expect(browser.checkbox(:xpath,"//input[@id='new_user_interests_dentistry']")).to_not be_enabled
172
+ expect(browser.checkbox(xpath: "//input[@id='new_user_interests_dentistry']")).to_not be_enabled
173
173
  end
174
174
 
175
175
  it "raises UnknownObjectException if the checkbox button doesn't exist" do
@@ -95,7 +95,7 @@ describe "Del" do
95
95
 
96
96
  it "raises UnknownObjectException if the del doesn't exist" do
97
97
  expect { browser.del(id: 'no_such_id').text }.to raise_unknown_object_exception
98
- expect { browser.del(:xpath , "//del[@id='no_such_id']").text }.to raise_unknown_object_exception
98
+ expect { browser.del(xpath: "//del[@id='no_such_id']").text }.to raise_unknown_object_exception
99
99
  end
100
100
  end
101
101
 
@@ -14,8 +14,7 @@ describe "Div" do
14
14
  expect(browser.div(title: "Header and primary navigation")).to exist
15
15
  expect(browser.div(title: /Header and primary navigation/)).to exist
16
16
  expect(browser.div(text: "Not shownNot hidden")).to exist
17
- msg = /text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
18
- expect { expect(browser.div(text: /Not hidden/)).to exist }.to output(msg).to_stdout_from_any_process
17
+ expect(browser.div(text: /Not hidden/)).to exist
19
18
  expect(browser.div(class: "profile")).to exist
20
19
  expect(browser.div(class: /profile/)).to exist
21
20
  expect(browser.div(index: 0)).to exist
@@ -34,8 +33,7 @@ describe "Div" do
34
33
  expect(browser.div(title: "no_such_title")).to_not exist
35
34
  expect(browser.div(title: /no_such_title/)).to_not exist
36
35
  expect(browser.div(text: "no_such_text")).to_not exist
37
- msg = /:text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
38
- expect { expect(browser.div(text: /no_such_text/)).to_not exist }.to output(msg).to_stdout_from_any_process
36
+ expect(browser.div(text: /no_such_text/)).to_not exist
39
37
  expect(browser.div(class: "no_such_class")).to_not exist
40
38
  expect(browser.div(class: /no_such_class/)).to_not exist
41
39
  expect(browser.div(index: 1337)).to_not exist
@@ -148,9 +146,22 @@ describe "Div" do
148
146
  end
149
147
 
150
148
  describe "Deprecation Warnings" do
151
- it "throws deprecation when for text and RegExp" do
152
- msg = /text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
153
- expect { browser.div(text: /Not hidden/).exists? }.to output(msg).to_stdout_from_any_process
149
+ describe "text locator with RegExp values" do
150
+ it "does not throw deprecation when still matched by text content" do
151
+ expect { browser.div(text: /some visible/).exists? }.not_to have_deprecated_text_regexp
152
+ end
153
+
154
+ it "throws deprecation when no longer matched by text content" do
155
+ expect { browser.div(text: /some visible$/).exists? }.to have_deprecated_text_regexp
156
+ end
157
+
158
+ it "throws deprecation when begins to be matched by text content" do
159
+ expect { browser.div(text: /some hidden/).exists? }.to have_deprecated_text_regexp
160
+ end
161
+
162
+ it "does not throw deprecation when still not matched by text content" do
163
+ expect { browser.div(text: /does not exist/).exists? }.not_to have_deprecated_text_regexp
164
+ end
154
165
  end
155
166
  end
156
167
 
@@ -171,7 +182,7 @@ describe "Div" do
171
182
  end
172
183
 
173
184
  it "includes custom message if element with a custom attribute does not exist" do
174
- message = "Watir treated [\"custom_attribute\"] as a non-HTML compliant attribute, ensure that was intended"
185
+ message = /Watir treated \[\"custom_attribute\"\] as a non-HTML compliant attribute, ensure that was intended/
175
186
  expect { browser.div(custom_attribute: "not_there").click }.to raise_unknown_object_exception(message)
176
187
  end
177
188
  end
@@ -22,6 +22,18 @@ describe "Divs" do
22
22
  it "returns the div at the given index" do
23
23
  expect(browser.divs[1].id).to eq "outer_container"
24
24
  end
25
+
26
+ it "returns an array of divs with a given range of positive values" do
27
+ divs = browser.divs[2..4]
28
+ ids = divs.map(&:id)
29
+ expect(ids).to eq %w(header promo content)
30
+ end
31
+
32
+ it "returns an array of divs with a given range including negative values" do
33
+ divs = browser.divs[11..-3]
34
+ ids = divs.map(&:id)
35
+ expect(ids).to eq %w(messages ins_tag_test del_tag_test)
36
+ end
25
37
  end
26
38
 
27
39
  describe "#each" do
@@ -31,11 +31,11 @@ describe "Dt" do
31
31
  # Attribute methods
32
32
  describe "#class_name" do
33
33
  it "returns the class attribute if the element exists" do
34
- expect(browser.dt(:id , "experience").class_name).to eq "industry"
34
+ expect(browser.dt(id: "experience").class_name).to eq "industry"
35
35
  end
36
36
 
37
37
  it "returns an empty string if the element exists but the attribute doesn't" do
38
- expect(browser.dt(:id , "education").class_name).to eq ""
38
+ expect(browser.dt(id: "education").class_name).to eq ""
39
39
  end
40
40
 
41
41
  it "raises UnknownObjectException if the element does not exist" do
@@ -23,6 +23,19 @@ describe "Element" do
23
23
  end
24
24
  end
25
25
 
26
+ describe "#element_call" do
27
+ it 'handles exceptions when taking an action on a stale element' do
28
+ browser.goto WatirSpec.url_for('removed_element.html')
29
+
30
+ element = browser.div(id: "text").tap(&:exists?)
31
+
32
+ browser.refresh
33
+
34
+ expect(element).to be_stale
35
+ expect { element.text }.to_not raise_error
36
+ end
37
+ end
38
+
26
39
  describe "#eq and #eql?" do
27
40
  before { browser.goto WatirSpec.url_for("definition_lists.html") }
28
41
 
@@ -119,7 +132,7 @@ describe "Element" do
119
132
  end
120
133
 
121
134
  it "finds several elements from an element's subtree" do
122
- expect(browser.fieldset.elements(xpath: ".//label").length).to eq 21
135
+ expect(browser.fieldset.elements(xpath: ".//label").length).to eq 22
123
136
  end
124
137
  end
125
138
 
@@ -191,11 +204,17 @@ describe "Element" do
191
204
 
192
205
  describe "#visible?" do
193
206
  it "returns true if the element is visible" do
194
- expect(browser.text_field(id: "new_user_email")).to be_visible
207
+ msg = /WARN Watir \[\"visible_element\"\]/
208
+ expect {
209
+ expect(browser.text_field(id: "new_user_email")).to be_visible
210
+ }.to output(msg).to_stdout_from_any_process
195
211
  end
196
212
 
197
213
  it "raises UnknownObjectException exception if the element does not exist" do
198
- expect { browser.text_field(id: "no_such_id").visible? }.to raise_unknown_object_exception
214
+ msg = /WARN Watir \[\"visible_element\"\]/
215
+ expect {
216
+ expect { browser.text_field(id: "no_such_id").visible? }.to raise_unknown_object_exception
217
+ }.to output(msg).to_stdout_from_any_process
199
218
  end
200
219
 
201
220
  it "raises UnknownObjectException exception if the element is stale" do
@@ -204,11 +223,16 @@ describe "Element" do
204
223
  browser.refresh
205
224
 
206
225
  expect(element).to be_stale
207
- expect { element.visible? }.to raise_unknown_object_exception
226
+ expect {
227
+ expect { element.visible? }.to raise_unknown_object_exception
228
+ }.to have_deprecated_stale_visible
208
229
  end
209
230
 
210
231
  it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do
211
- expect(browser.div(id: "visible_child")).to be_visible
232
+ msg = /WARN Watir \[\"visible_element\"\]/
233
+ expect {
234
+ expect(browser.div(id: "visible_child")).to be_visible
235
+ }.to output(msg).to_stdout_from_any_process
212
236
  end
213
237
 
214
238
  it "returns false if the element is input element where type eq 'hidden'" do
@@ -216,15 +240,108 @@ describe "Element" do
216
240
  end
217
241
 
218
242
  it "returns false if the element has style='display: none;'" do
219
- expect(browser.div(id: 'changed_language')).to_not be_visible
243
+ msg = /WARN Watir \[\"visible_element\"\]/
244
+ expect {
245
+ expect(browser.div(id: 'changed_language')).to_not be_visible
246
+ }.to output(msg).to_stdout_from_any_process
220
247
  end
221
248
 
222
249
  it "returns false if the element has style='visibility: hidden;" do
223
- expect(browser.div(id: 'wants_newsletter')).to_not be_visible
250
+ msg = /WARN Watir \[\"visible_element\"\]/
251
+ expect {
252
+ expect(browser.div(id: 'wants_newsletter')).to_not be_visible
253
+ }
224
254
  end
225
255
 
226
256
  it "returns false if one of the parent elements is hidden" do
227
- expect(browser.div(id: 'hidden_parent')).to_not be_visible
257
+ msg = /WARN Watir \[\"visible_element\"\]/
258
+ expect {
259
+ expect(browser.div(id: 'hidden_parent')).to_not be_visible
260
+ }
261
+ end
262
+ end
263
+
264
+ describe "#exists?" do
265
+ before do
266
+ browser.goto WatirSpec.url_for('removed_element.html')
267
+ end
268
+
269
+ it "element from a collection returns false when it becomes stale" do
270
+ element = browser.divs(id: "text").first.tap(&:exists?)
271
+
272
+ browser.refresh
273
+
274
+ expect(element).to be_stale
275
+ expect(element).to_not exist
276
+ end
277
+
278
+ it "returns false when tag name does not match id" do
279
+ watir_element = browser.span(id: "text")
280
+ expect(watir_element).to_not exist
281
+ end
282
+ end
283
+
284
+ describe '#present?' do
285
+ before do
286
+ browser.goto(WatirSpec.url_for("wait.html"))
287
+ end
288
+
289
+ it 'returns true if the element exists and is visible' do
290
+ expect(browser.div(id: 'foo')).to be_present
291
+ end
292
+
293
+ it 'returns false if the element exists but is not visible' do
294
+ expect(browser.div(id: 'bar')).to_not be_present
295
+ end
296
+
297
+ it 'returns false if the element does not exist' do
298
+ expect(browser.div(id: 'should-not-exist')).to_not be_present
299
+ end
300
+
301
+ # TODO Refactor so that this returns true
302
+ it "returns false if the element is stale" do
303
+ element = browser.div(id: "foo").tap(&:exists?)
304
+
305
+ browser.refresh
306
+
307
+ expect(element).to be_stale
308
+
309
+ expect {
310
+ expect(element).to_not be_present
311
+ }.to have_deprecated_stale_present
312
+ end
313
+
314
+ # TODO Documents Current Behavior, but needs to be refactored/removed
315
+ it "returns true the second time if the element is stale" do
316
+ element = browser.div(id: "foo").tap(&:exists?)
317
+
318
+ browser.refresh
319
+
320
+ expect(element).to be_stale
321
+
322
+ expect {
323
+ expect(element).to_not be_present
324
+ }.to have_deprecated_stale_present
325
+ expect(element).to be_present
326
+ end
327
+
328
+ end
329
+
330
+ describe "#enabled?" do
331
+ before do
332
+ browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
333
+ end
334
+
335
+ it "returns true if the element is enabled" do
336
+ expect(browser.element(name: 'new_user_submit')).to be_enabled
337
+ end
338
+
339
+ it "returns false if the element is disabled" do
340
+ expect(browser.element(name: 'new_user_submit_disabled')).to_not be_enabled
341
+ end
342
+
343
+ it "raises UnknownObjectException if the element doesn't exist" do
344
+ expect { browser.element(name: "no_such_name").enabled? }.to raise_unknown_object_exception
228
345
  end
229
346
  end
230
347
 
@@ -339,6 +456,11 @@ describe "Element" do
339
456
  expect(browser.element(name: "new_user_first_name")).to exist
340
457
  expect(browser.element(name: /new_user_first_name/)).to exist
341
458
  end
459
+
460
+ it "returns false when tag name does not match id" do
461
+ watir_element = browser.span(id: "text")
462
+ expect(watir_element).to_not exist
463
+ end
342
464
  end
343
465
 
344
466
  describe '#send_keys' do
@@ -389,12 +511,90 @@ describe "Element" do
389
511
  end
390
512
 
391
513
  describe "#flash" do
392
-
393
514
  let(:h2) { browser.h2(text: 'Add user') }
515
+ let(:h1) { browser.h1(text: 'User administration') }
394
516
 
395
517
  it 'returns the element on which it was called' do
396
518
  expect(h2.flash).to eq h2
397
519
  end
520
+
521
+ it 'should keep the element background color after flashing' do
522
+ expect(h2.style('background-color')).to eq h2.flash(:rainbow).style('background-color')
523
+ expect(h1.style('background-color')).to eq h1.flash.style('background-color')
524
+ end
525
+
526
+ it 'should respond to preset symbols like :fast and :slow' do
527
+ expect(h1.flash(:rainbow)).to eq h1
528
+ expect(h2.flash(:slow)).to eq h2
529
+ expect(h1.flash(:fast)).to eq h1
530
+ expect(h2.flash(:long)).to eq h2
531
+ end
532
+
533
+ end
534
+
535
+ describe "#hover" do
536
+ not_compliant_on :internet_explorer, :safari do
537
+ it "should hover over the element" do
538
+ browser.goto WatirSpec.url_for('hover.html')
539
+ link = browser.a
540
+
541
+ expect(link.style("font-size")).to eq "10px"
542
+ link.hover
543
+ link.wait_until { |l| l.style("font-size") == "20px" }
544
+ expect(link.style("font-size")).to eq "20px"
545
+ end
546
+ end
547
+ end
548
+
549
+ describe "#inspect" do
550
+ before(:each) { browser.goto(WatirSpec.url_for("nested_iframes.html")) }
551
+
552
+ it "does displays specified element type" do
553
+ expect(browser.div.inspect).to include('Watir::Div')
554
+ end
555
+
556
+ it "does not display element type if not specified" do
557
+ element = browser.element(index: 4)
558
+ expect(element.inspect).to include('Watir::HTMLElement')
559
+ end
560
+
561
+ it "displays keyword if specified" do
562
+ element = browser.h3
563
+ element.keyword = 'foo'
564
+ expect(element.inspect).to include('keyword: foo')
565
+ end
566
+
567
+ it "does not display keyword if not specified" do
568
+ element = browser.h3
569
+ expect(element.inspect).to_not include('keyword')
570
+ end
571
+
572
+ it "locate is false when not located" do
573
+ element = browser.div(id: 'not_present')
574
+ expect(element.inspect).to include('located: false')
575
+ end
576
+
577
+ it "locate is true when located" do
578
+ element = browser.h3
579
+ element.exists?
580
+ expect(element.inspect).to include('located: true')
581
+ end
582
+
583
+ it "displays selector string for element from colection" do
584
+ elements = browser.frames
585
+ expect(elements.last.inspect).to include '{:tag_name=>"frame", :index=>-1}'
586
+ end
587
+
588
+ it "displays selector string for nested element" do
589
+ browser.goto(WatirSpec.url_for("wait.html"))
590
+ element = browser.div(index: 1).div(id: 'div2')
591
+ expect(element.inspect).to include '{:index=>1, :tag_name=>"div"} --> {:id=>"div2", :tag_name=>"div"}'
592
+ end
593
+
594
+ it "displays selector string for nested element under frame" do
595
+ element = browser.iframe(id: 'one').iframe(id: 'three')
596
+ expect(element.inspect).to include '{:id=>"one", :tag_name=>"iframe"} --> {:id=>"three", :tag_name=>"iframe"}'
597
+ end
398
598
  end
399
599
 
400
600
  describe '#text_content' do
@@ -493,4 +693,15 @@ describe "Element" do
493
693
  end
494
694
  end
495
695
 
696
+ describe '#attribute_value' do
697
+ before { browser.goto WatirSpec.url_for("data_attributes.html") }
698
+
699
+ it 'returns attribute value by string attribute name' do
700
+ expect(browser.p.attribute_value('data-type')).to eq "ruby-library"
701
+ end
702
+
703
+ it 'returns attribute value by symbol attribute name' do
704
+ expect(browser.p.attribute_value(:data_type)).to eq "ruby-library"
705
+ end
706
+ end
496
707
  end
@@ -77,7 +77,7 @@ describe ["H1", "H2", "H3", "H4", "H5", "H6"] do
77
77
 
78
78
  it "raises UnknownObjectException if the p doesn't exist" do
79
79
  expect { browser.h1(id: 'no_such_id').text }.to raise_unknown_object_exception
80
- expect { browser.h1(:xpath , "//h1[@id='no_such_id']").text }.to raise_unknown_object_exception
80
+ expect { browser.h1(xpath: "//h1[@id='no_such_id']").text }.to raise_unknown_object_exception
81
81
  end
82
82
  end
83
83
 
@@ -28,7 +28,7 @@ describe ["H1s", "H2s", "H3s", "H4s", "H5s", "H6s"] do
28
28
  lengths = (1..6).collect do |i|
29
29
  collection = browser.send(:"h#{i}s")
30
30
  collection.each_with_index do |h, index|
31
- expect(h.id).to eq browser.send(:"h#{i}", :index, index).id
31
+ expect(h.id).to eq browser.send(:"h#{i}", index: index).id
32
32
  end
33
33
  collection.length
34
34
  end
@@ -95,7 +95,7 @@ describe "Ins" do
95
95
 
96
96
  it "raises UnknownObjectException if the ins doesn't exist" do
97
97
  expect { browser.ins(id: 'no_such_id').text }.to raise_unknown_object_exception
98
- expect { browser.ins(:xpath , "//ins[@id='no_such_id']").text }.to raise_unknown_object_exception
98
+ expect { browser.ins(xpath: "//ins[@id='no_such_id']").text }.to raise_unknown_object_exception
99
99
  end
100
100
  end
101
101
 
@@ -14,7 +14,7 @@ describe "Labels" do
14
14
 
15
15
  describe "#length" do
16
16
  it "returns the number of labels" do
17
- expect(browser.labels.length).to eq 40
17
+ expect(browser.labels.length).to eq 41
18
18
  end
19
19
  end
20
20
 
@@ -95,7 +95,7 @@ describe "Li" do
95
95
 
96
96
  it "raises UnknownObjectException if the li doesn't exist" do
97
97
  expect { browser.li(id: 'no_such_id').text }.to raise_unknown_object_exception
98
- expect { browser.li(:xpath , "//li[@id='no_such_id']").text }.to raise_unknown_object_exception
98
+ expect { browser.li(xpath: "//li[@id='no_such_id']").text }.to raise_unknown_object_exception
99
99
  end
100
100
  end
101
101