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
@@ -113,16 +113,18 @@ describe "Span" do
113
113
  end
114
114
 
115
115
  # Other
116
- describe "#click" do
117
- it "fires events" do
118
- expect(browser.span(class: 'footer').text).to_not include('Javascript')
119
- browser.span(class: 'footer').click
120
- expect(browser.span(class: 'footer').text).to include('Javascript')
121
- end
122
-
123
- it "raises UnknownObjectException if the span doesn't exist" do
124
- expect { browser.span(id: "no_such_id").click }.to raise_unknown_object_exception
125
- expect { browser.span(title: "no_such_title").click }.to raise_unknown_object_exception
116
+ not_compliant_on :headless do
117
+ describe "#click" do
118
+ it "fires events" do
119
+ expect(browser.span(class: 'footer').text).to_not include('Javascript')
120
+ browser.span(class: 'footer').click
121
+ expect(browser.span(class: 'footer').text).to include('Javascript')
122
+ end
123
+
124
+ it "raises UnknownObjectException if the span doesn't exist" do
125
+ expect { browser.span(id: "no_such_id").click }.to raise_unknown_object_exception
126
+ expect { browser.span(title: "no_such_title").click }.to raise_unknown_object_exception
127
+ end
126
128
  end
127
129
  end
128
130
 
@@ -41,17 +41,19 @@ describe "Table" do
41
41
  end
42
42
 
43
43
  # Other
44
- describe "#strings" do
45
- it "returns a two-dimensional array representation of the table" do
46
- expect(browser.table(id: 'inner').strings).to eq [
47
- ["Table 2, Row 1, Cell 1",
48
- "Table 2, Row 1, Cell 2"]
49
- ]
50
- expect(browser.table(id: 'outer').strings).to eq [
51
- ["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"],
52
- ["Table 1, Row 2, Cell 1", "Table 1, Row 2, Cell 2\nTable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"],
53
- ["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"]
54
- ]
44
+ bug "Safari does not strip text", :safari do
45
+ describe "#strings" do
46
+ it "returns a two-dimensional array representation of the table" do
47
+ expect(browser.table(id: 'inner').strings).to eq [
48
+ ["Table 2, Row 1, Cell 1",
49
+ "Table 2, Row 1, Cell 2"]
50
+ ]
51
+ expect(browser.table(id: 'outer').strings).to eq [
52
+ ["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"],
53
+ ["Table 1, Row 2, Cell 1", "Table 1, Row 2, Cell 2\nTable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"],
54
+ ["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"]
55
+ ]
56
+ end
55
57
  end
56
58
  end
57
59
 
@@ -50,17 +50,19 @@ describe "TableBody" do
50
50
  end
51
51
  end
52
52
 
53
- describe "#[]" do
54
- it "returns the row at the given index (page context)" do
55
- expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
56
- expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
57
- expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
58
- end
59
-
60
- it "returns the row at the given index (table context)" do
61
- expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
62
- expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
63
- expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
53
+ bug "Safari does not strip text", :safari do
54
+ describe "#[]" do
55
+ it "returns the row at the given index (page context)" do
56
+ expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
57
+ expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
58
+ expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
59
+ end
60
+
61
+ it "returns the row at the given index (table context)" do
62
+ expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
63
+ expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
64
+ expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
65
+ end
64
66
  end
65
67
  end
66
68
 
@@ -47,10 +47,12 @@ describe "TableCell" do
47
47
  end
48
48
 
49
49
  # Attribute methods
50
- describe "#text" do
51
- it "returns the text inside the table cell" do
52
- expect(browser.td(id: 't1_r2_c1').text).to eq 'Table 1, Row 2, Cell 1'
53
- expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1'
50
+ bug "Safari does not strip text", :safari do
51
+ describe "#text" do
52
+ it "returns the text inside the table cell" do
53
+ expect(browser.td(id: 't1_r2_c1').text).to eq 'Table 1, Row 2, Cell 1'
54
+ expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1'
55
+ end
54
56
  end
55
57
  end
56
58
 
@@ -204,27 +204,29 @@ describe "TextField" do
204
204
  end
205
205
 
206
206
  # Manipulation methods
207
- describe "#append" do
208
- it "appends the text to the text field" do
209
- browser.text_field(name: "new_user_occupation").append(" Append This")
210
- expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer Append This"
211
- end
207
+ not_compliant_on :safari do
208
+ describe "#append" do
209
+ it "appends the text to the text field" do
210
+ browser.text_field(name: "new_user_occupation").append(" Append This")
211
+ expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer Append This"
212
+ end
212
213
 
213
- it "appends multi-byte characters" do
214
- browser.text_field(name: "new_user_occupation").append(" ijij")
215
- expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer ijij"
216
- end
214
+ it "appends multi-byte characters" do
215
+ browser.text_field(name: "new_user_occupation").append(" ijij")
216
+ expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer ijij"
217
+ end
217
218
 
218
- it "raises ObjectReadOnlyException if the object is read only" do
219
- expect { browser.text_field(id: "new_user_code").append("Append This") }.to raise_object_read_only_exception
220
- end
219
+ it "raises ObjectReadOnlyException if the object is read only" do
220
+ expect { browser.text_field(id: "new_user_code").append("Append This") }.to raise_object_read_only_exception
221
+ end
221
222
 
222
- it "raises ObjectDisabledException if the object is disabled" do
223
- expect { browser.text_field(name: "new_user_species").append("Append This") }.to raise_object_disabled_exception
224
- end
223
+ it "raises ObjectDisabledException if the object is disabled" do
224
+ expect { browser.text_field(name: "new_user_species").append("Append This") }.to raise_object_disabled_exception
225
+ end
225
226
 
226
- it "raises UnknownObjectException if the object doesn't exist" do
227
- expect { browser.text_field(name: "no_such_name").append("Append This") }.to raise_unknown_object_exception
227
+ it "raises UnknownObjectException if the object doesn't exist" do
228
+ expect { browser.text_field(name: "no_such_name").append("Append This") }.to raise_unknown_object_exception
229
+ end
228
230
  end
229
231
  end
230
232
 
@@ -36,19 +36,23 @@ describe "TableRow" do
36
36
 
37
37
  describe "#click" do
38
38
  bug "http://github.com/watir/watir/issues/issue/32", :internet_explorer, :chrome do
39
- it "fires the row's onclick event" do
40
- browser.tr(id: 'inner_first').click
41
- expect(messages).to include('tr')
39
+ not_compliant_on :firefox do
40
+ it "fires the row's onclick event" do
41
+ browser.tr(id: 'inner_first').click
42
+ expect(messages).to include('tr')
43
+ end
42
44
  end
43
45
  end
44
46
  end
45
47
 
46
- describe "#[]" do
47
- let(:table) { browser.table(id: 'outer') }
48
+ bug "Safari does not strip text", :safari do
49
+ describe "#[]" do
50
+ let(:table) { browser.table(id: 'outer') }
48
51
 
49
- it "returns the nth cell of the row" do
50
- expect(table[0][0].text).to eq "Table 1, Row 1, Cell 1"
51
- expect(table[2][0].text).to eq "Table 1, Row 3, Cell 1"
52
+ it "returns the nth cell of the row" do
53
+ expect(table[0][0].text).to eq "Table 1, Row 1, Cell 1"
54
+ expect(table[2][0].text).to eq "Table 1, Row 3, Cell 1"
55
+ end
52
56
  end
53
57
  end
54
58
 
@@ -2,11 +2,11 @@ var WatirSpec = function() {
2
2
 
3
3
  return {
4
4
  addMessage: function(string) {
5
- var text = document.createTextNode(string)
5
+ var text = document.createTextNode(string);
6
6
  var message = document.createElement('div');
7
7
  var messages = document.getElementById('messages');
8
8
 
9
- message.appendChild(text)
9
+ message.appendChild(text);
10
10
  messages.appendChild(message);
11
11
  }
12
12
  };
@@ -8,7 +8,7 @@
8
8
  <body>
9
9
  <span id="grandparent_span">
10
10
  <div id="grandparent">
11
- <span id="parent_span">
11
+ <span class="parent" id="parent_span">
12
12
  <div id="parent">
13
13
  <div id="first_sibling">
14
14
  <span id="child_span">
@@ -22,10 +22,10 @@
22
22
  <div id="youngest_child"></div>
23
23
  </span>
24
24
  </div>
25
- <span id="between_siblings1"></span>
26
- <div id="second_sibling"></div>
27
- <span id="between_siblings2"></span>
28
- <div id="third_sibling"></div>
25
+ <span class="a" id="between_siblings1"></span>
26
+ <div class="b" id="second_sibling"></div>
27
+ <span class="a" id="between_siblings2"></span>
28
+ <div class="a b" id="third_sibling">text</div>
29
29
  </div>
30
30
  </span>
31
31
  </div>
@@ -26,10 +26,10 @@ describe 'Watir#relaxed_locate?' do
26
26
  context 'when acting on an element that is already present' do
27
27
  it 'does not wait' do
28
28
  begin
29
- Watir.default_timeout = 2
29
+ Watir.default_timeout = 5
30
30
  start_time = ::Time.now
31
31
  expect { browser.link.click }.to_not raise_exception
32
- expect(::Time.now - start_time).to be < 2
32
+ expect(::Time.now - start_time).to be < 5
33
33
  ensure
34
34
  Watir.default_timeout = 30
35
35
  end
@@ -37,15 +37,17 @@ describe 'Watir#relaxed_locate?' do
37
37
  end
38
38
 
39
39
  context 'when acting on an element that eventually becomes present' do
40
- it 'waits until present and then takes action' do
41
- begin
42
- Watir.default_timeout = 3
43
- start_time = ::Time.now
44
- browser.a(id: 'show_bar').click
45
- expect { browser.div(id: 'bar').click }.to_not raise_exception
46
- expect(::Time.now - start_time).to be < 3
47
- ensure
48
- Watir.default_timeout = 30
40
+ bug "https://github.com/SeleniumHQ/selenium/issues/4380", %i{remote firefox} do
41
+ it 'waits until present and then takes action' do
42
+ begin
43
+ Watir.default_timeout = 3
44
+ start_time = ::Time.now
45
+ browser.a(id: 'show_bar').click
46
+ expect { browser.div(id: 'bar').click }.to_not raise_exception
47
+ expect(::Time.now - start_time).to be < 3
48
+ ensure
49
+ Watir.default_timeout = 30
50
+ end
49
51
  end
50
52
  end
51
53
  end
@@ -92,14 +94,6 @@ describe 'Watir#relaxed_locate?' do
92
94
  expect(::Time.now - start_time).to be < 1
93
95
  end
94
96
  end
95
-
96
- it 'receives a warning for using #when_present' do
97
- message = /#when_present has been deprecated and is unlikely to be needed; replace this with #wait_until_present if a wait is still needed/
98
- browser.a(id: 'show_bar').click
99
- expect do
100
- browser.div(id: 'bar').when_present.click
101
- end.to output(message).to_stderr
102
- end
103
97
  end
104
98
  end
105
99
  end
@@ -1,398 +1,376 @@
1
1
  require "watirspec_helper"
2
2
 
3
- not_compliant_on :safari do
4
- describe Watir::Wait do
5
- describe "#until" do
6
- it "waits until the block returns true" do
7
- Watir::Wait.until(timeout: 0.5) { @result = true }
8
- expect(@result).to be true
9
- end
3
+ describe Watir::Wait do
4
+ describe "#until" do
5
+ it "waits until the block returns true" do
6
+ Watir::Wait.until(timeout: 0.5) { @result = true }
7
+ expect(@result).to be true
8
+ end
10
9
 
11
- it "executes block if timeout is zero" do
12
- Watir::Wait.until(timeout: 0) { @result = true }
13
- expect(@result).to be true
14
- end
10
+ it "executes block if timeout is zero" do
11
+ Watir::Wait.until(timeout: 0) { @result = true }
12
+ expect(@result).to be true
13
+ end
15
14
 
16
- it "times out" do
17
- expect { Watir::Wait.until(timeout: 0.5) { false } }.to raise_error(Watir::Wait::TimeoutError)
18
- end
15
+ it "times out" do
16
+ expect { Watir::Wait.until(timeout: 0.5) { false } }.to raise_error(Watir::Wait::TimeoutError)
17
+ end
19
18
 
20
- it "times out with a custom message" do
21
- expect {
22
- Watir::Wait.until(timeout: 0.5, message: "oops") { false }
23
- }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
24
- end
19
+ it "times out with a custom message" do
20
+ expect {
21
+ Watir::Wait.until(timeout: 0.5, message: "oops") { false }
22
+ }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
23
+ end
25
24
 
26
- it "uses provided interval" do
27
- begin
28
- Watir::Wait.until(timeout: 0.4, interval: 0.2) do
29
- @result = @result.nil? ? 1 : @result + 1
30
- false
31
- end
32
- rescue Watir::Wait::TimeoutError
25
+ it "uses provided interval" do
26
+ begin
27
+ Watir::Wait.until(timeout: 0.4, interval: 0.2) do
28
+ @result = @result.nil? ? 1 : @result + 1
29
+ false
33
30
  end
34
- expect(@result).to eq 2
35
- end
36
-
37
- it "uses timer for waiting" do
38
- timer = Watir::Wait.timer
39
- expect(timer).to receive(:wait).with(0.5).and_call_original
40
- Watir::Wait.until(timeout: 0.5) { true }
31
+ rescue Watir::Wait::TimeoutError
41
32
  end
33
+ expect(@result).to eq 2
34
+ end
42
35
 
43
- it "ordered pairs are deprecated" do
44
- message = /Instead of passing arguments into Wait#until method, use keywords/
45
- expect { Watir::Wait.until(0) { true } }.to output(message).to_stderr
46
- end
36
+ it "uses timer for waiting" do
37
+ timer = Watir::Wait.timer
38
+ expect(timer).to receive(:wait).with(0.5).and_call_original
39
+ Watir::Wait.until(timeout: 0.5) { true }
47
40
  end
41
+ end
48
42
 
49
- describe "#while" do
50
- it "waits while the block returns true" do
51
- expect(Watir::Wait.while(timeout: 0.5) { false }).to be_nil
52
- end
43
+ describe "#while" do
44
+ it "waits while the block returns true" do
45
+ expect(Watir::Wait.while(timeout: 0.5) { false }).to be_nil
46
+ end
53
47
 
54
- it "executes block if timeout is zero" do
55
- expect(Watir::Wait.while(timeout: 0) { false }).to be_nil
56
- end
48
+ it "executes block if timeout is zero" do
49
+ expect(Watir::Wait.while(timeout: 0) { false }).to be_nil
50
+ end
57
51
 
58
- it "times out" do
59
- expect { Watir::Wait.while(timeout: 0.5) { true } }.to raise_error(Watir::Wait::TimeoutError)
60
- end
52
+ it "times out" do
53
+ expect { Watir::Wait.while(timeout: 0.5) { true } }.to raise_error(Watir::Wait::TimeoutError)
54
+ end
61
55
 
62
- it "times out with a custom message" do
63
- expect {
64
- Watir::Wait.while(timeout: 0.5, message: "oops") { true }
65
- }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
66
- end
56
+ it "times out with a custom message" do
57
+ expect {
58
+ Watir::Wait.while(timeout: 0.5, message: "oops") { true }
59
+ }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
60
+ end
67
61
 
68
- it "uses provided interval" do
69
- begin
70
- Watir::Wait.while(timeout: 0.4, interval: 0.2) do
71
- @result = @result.nil? ? 1 : @result + 1
72
- true
73
- end
74
- rescue Watir::Wait::TimeoutError
62
+ it "uses provided interval" do
63
+ begin
64
+ Watir::Wait.while(timeout: 0.4, interval: 0.2) do
65
+ @result = @result.nil? ? 1 : @result + 1
66
+ true
75
67
  end
76
- expect(@result).to eq 2
77
- end
78
-
79
- it "uses timer for waiting" do
80
- timer = Watir::Wait.timer
81
- expect(timer).to receive(:wait).with(0.5).and_call_original
82
- Watir::Wait.while(timeout: 0.5) { false }
68
+ rescue Watir::Wait::TimeoutError
83
69
  end
70
+ expect(@result).to eq 2
71
+ end
84
72
 
85
- it "ordered pairs are deprecated" do
86
- message = /Instead of passing arguments into Wait#while method, use keywords/
87
- expect { Watir::Wait.while(0) { false } }.to output(message).to_stderr
88
- end
73
+ it "uses timer for waiting" do
74
+ timer = Watir::Wait.timer
75
+ expect(timer).to receive(:wait).with(0.5).and_call_original
76
+ Watir::Wait.while(timeout: 0.5) { false }
89
77
  end
78
+ end
90
79
 
91
- describe "#timer" do
92
- it "returns default timer" do
93
- expect(Watir::Wait.timer).to be_a(Watir::Wait::Timer)
94
- end
80
+ describe "#timer" do
81
+ it "returns default timer" do
82
+ expect(Watir::Wait.timer).to be_a(Watir::Wait::Timer)
95
83
  end
84
+ end
96
85
 
97
- describe "#timer=" do
98
- after { Watir::Wait.timer = nil }
86
+ describe "#timer=" do
87
+ after { Watir::Wait.timer = nil }
99
88
 
100
- it "changes default timer" do
101
- timer = Class.new
102
- Watir::Wait.timer = timer
103
- expect(Watir::Wait.timer).to eq(timer)
104
- end
89
+ it "changes default timer" do
90
+ timer = Class.new
91
+ Watir::Wait.timer = timer
92
+ expect(Watir::Wait.timer).to eq(timer)
105
93
  end
106
94
  end
95
+ end
107
96
 
108
- describe Watir::Element do
109
- before do
110
- browser.goto WatirSpec.url_for("wait.html")
111
- end
97
+ describe Watir::Element do
98
+ before do
99
+ browser.goto WatirSpec.url_for("wait.html")
100
+ end
112
101
 
113
- # TODO: This is deprecated; remove in future version
114
- not_compliant_on :relaxed_locate do
115
- describe "#when_present" do
116
- it "invokes subsequent method calls when the element becomes present" do
117
- browser.a(id: 'show_bar').click
102
+ # TODO: This is deprecated; remove in future version
103
+ not_compliant_on :relaxed_locate do
104
+ describe "#when_present" do
105
+ it "invokes subsequent method calls when the element becomes present" do
106
+ browser.a(id: 'show_bar').click
118
107
 
119
- bar = browser.div(id: 'bar')
120
- bar.when_present(2).click
121
- expect(bar.text).to eq "changed"
122
- end
108
+ bar = browser.div(id: 'bar')
109
+ bar.when_present(2).click
110
+ expect(bar.text).to eq "changed"
111
+ end
123
112
 
124
- it "times out when given a block" do
125
- expect { browser.div(id: 'bar').when_present(1) {} }.to raise_error(Watir::Wait::TimeoutError)
126
- end
113
+ it "times out when given a block" do
114
+ expect { browser.div(id: 'bar').when_present(1) {} }.to raise_error(Watir::Wait::TimeoutError)
115
+ end
127
116
 
128
- it "times out when not given a block" do
129
- message = /^timed out after 1 seconds, waiting for (\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\}) to become present$/
130
- expect { browser.div(id: 'bar').when_present(1).click }.to raise_error(Watir::Wait::TimeoutError, message)
131
- end
117
+ it "times out when not given a block" do
118
+ message = /^timed out after 1 seconds, waiting for (\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\}) to become present$/
119
+ expect { browser.div(id: 'bar').when_present(1).click }.to raise_error(Watir::Wait::TimeoutError, message)
120
+ end
132
121
 
133
- it "responds to Element methods" do
134
- decorator = browser.div.when_present
122
+ it "responds to Element methods" do
123
+ decorator = browser.div.when_present
135
124
 
136
- expect(decorator).to respond_to(:exist?)
137
- expect(decorator).to respond_to(:present?)
138
- expect(decorator).to respond_to(:click)
139
- end
125
+ expect(decorator).to respond_to(:exist?)
126
+ expect(decorator).to respond_to(:present?)
127
+ expect(decorator).to respond_to(:click)
128
+ end
140
129
 
141
- it "delegates present? to element" do
142
- Object.class_eval do
143
- def present?
144
- false
145
- end
130
+ it "delegates present? to element" do
131
+ Object.class_eval do
132
+ def present?
133
+ false
146
134
  end
147
- element = browser.a(id: "show_bar").when_present(1)
148
- expect(element).to be_present
149
135
  end
136
+ element = browser.a(id: "show_bar").when_present(1)
137
+ expect(element).to be_present
138
+ end
150
139
 
151
- it "processes before calling present?" do
152
- browser.a(id: 'show_bar').click
153
- expect(browser.div(id: 'bar').when_present.present?).to be true
154
- end
140
+ it "processes before calling present?" do
141
+ browser.a(id: 'show_bar').click
142
+ expect(browser.div(id: 'bar').when_present.present?).to be true
155
143
  end
156
144
  end
145
+ end
157
146
 
158
- not_compliant_on :relaxed_locate do
159
- describe "#wait_until &:enabled?" do
160
- it "invokes subsequent method calls when the element becomes enabled" do
161
- browser.a(id: 'enable_btn').click
147
+ not_compliant_on :relaxed_locate do
148
+ describe "#wait_until &:enabled?" do
149
+ it "invokes subsequent method calls when the element becomes enabled" do
150
+ browser.a(id: 'enable_btn').click
162
151
 
163
- btn = browser.button(id: 'btn')
164
- btn.wait_until(timeout: 2, &:enabled?).click
165
- Watir::Wait.while { btn.enabled? }
166
- expect(btn.disabled?).to be true
167
- end
152
+ btn = browser.button(id: 'btn')
153
+ btn.wait_until(timeout: 2, &:enabled?).click
154
+ Watir::Wait.while { btn.enabled? }
155
+ expect(btn.disabled?).to be true
156
+ end
168
157
 
169
- it "times out" do
170
- error = Watir::Wait::TimeoutError
171
- inspected = '#<Watir::Button: located: false; {:id=>"btn", :tag_name=>"button"}>'
172
- message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
173
- element = browser.button(id: 'btn')
174
- expect { element.wait_until(timeout: 1, &:enabled?).click }.to raise_error(error, message)
175
- end
158
+ it "times out" do
159
+ error = Watir::Wait::TimeoutError
160
+ inspected = '#<Watir::Button: located: false; {:id=>"btn", :tag_name=>"button"}>'
161
+ message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
162
+ element = browser.button(id: 'btn')
163
+ expect { element.wait_until(timeout: 1, &:enabled?).click }.to raise_error(error, message)
164
+ end
176
165
 
177
- it "responds to Element methods" do
178
- element = browser.button.wait_until { true }
166
+ it "responds to Element methods" do
167
+ element = browser.button.wait_until { true }
179
168
 
180
- expect(element).to respond_to(:exist?)
181
- expect(element).to respond_to(:present?)
182
- expect(element).to respond_to(:click)
183
- end
169
+ expect(element).to respond_to(:exist?)
170
+ expect(element).to respond_to(:present?)
171
+ expect(element).to respond_to(:click)
172
+ end
184
173
 
185
- it "can be chained with #wait_until &:present?" do
186
- browser.a(id: 'show_and_enable_btn').click
187
- browser.button(id: 'btn2').wait_until(&:present?).wait_until(&:enabled?).click
174
+ it "can be chained with #wait_until &:present?" do
175
+ browser.a(id: 'show_and_enable_btn').click
176
+ browser.button(id: 'btn2').wait_until(&:present?).wait_until(&:enabled?).click
188
177
 
189
- expect(browser.button(id: 'btn2')).to exist
190
- expect(browser.button(id: 'btn2')).to be_enabled
191
- end
178
+ expect(browser.button(id: 'btn2')).to exist
179
+ expect(browser.button(id: 'btn2')).to be_enabled
192
180
  end
193
181
  end
182
+ end
194
183
 
195
- describe "#wait_until_present" do
196
- it "waits until the element appears" do
197
- browser.a(id: 'show_bar').click
198
- expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
199
- end
200
-
201
- it "times out if the element doesn't appear" do
202
- inspected = '#<Watir::Div: located: false; {:id=>"bar", :tag_name=>"div"}>'
203
- error = Watir::Wait::TimeoutError
204
- message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
205
-
206
- expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
207
- end
184
+ describe "#wait_until_present" do
185
+ it "waits until the element appears" do
186
+ browser.a(id: 'show_bar').click
187
+ expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
188
+ end
208
189
 
209
- it "uses provided interval" do
210
- element = browser.div(id: 'bar')
211
- expect(element).to receive(:present?).twice
190
+ it "times out if the element doesn't appear" do
191
+ inspected = '#<Watir::Div: located: false; {:id=>"bar", :tag_name=>"div"}>'
192
+ error = Watir::Wait::TimeoutError
193
+ message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
212
194
 
213
- begin
214
- element.wait_until_present(timeout: 0.4, interval: 0.2)
215
- rescue Watir::Wait::TimeoutError
216
- end
217
- end
195
+ expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
196
+ end
218
197
 
219
- it "ordered pairs are deprecated" do
220
- browser.a(id: 'show_bar').click
221
- message = /Instead of passing arguments into #wait_until_present method, use keywords/
222
- expect { browser.div(id: 'bar').wait_until_present(5) }.to output(message).to_stderr
223
- end
198
+ it "uses provided interval" do
199
+ element = browser.div(id: 'bar')
200
+ expect(element).to receive(:present?).twice
224
201
 
225
- it 'waits to select an option' do
226
- browser.a(id: 'add_select').click
227
- select_list = browser.select_list(id: 'languages')
228
- Watir.default_timeout = 1
229
- begin
230
- start_time = ::Time.now
231
- expect { select_list.select('No') }.to raise_error Watir::Exception::NoValueFoundException
232
- expect(::Time.now - start_time).to be > 1
233
- ensure
234
- Watir.default_timeout = 30
235
- end
202
+ begin
203
+ element.wait_until_present(timeout: 0.4, interval: 0.2)
204
+ rescue Watir::Wait::TimeoutError
236
205
  end
237
206
  end
238
207
 
239
- describe "#wait_while_present" do
240
- it "waits until the element disappears" do
241
- browser.a(id: 'hide_foo').click
242
- expect { browser.div(id: 'foo').wait_while_present(timeout: 2) }.to_not raise_exception
208
+ it 'waits to select an option' do
209
+ browser.a(id: 'add_select').click
210
+ select_list = browser.select_list(id: 'languages')
211
+ Watir.default_timeout = 1
212
+ begin
213
+ start_time = ::Time.now
214
+ expect { select_list.select('No') }.to raise_error Watir::Exception::NoValueFoundException
215
+ expect(::Time.now - start_time).to be > 1
216
+ ensure
217
+ Watir.default_timeout = 30
243
218
  end
219
+ end
220
+ end
244
221
 
245
- it "times out if the element doesn't disappear" do
246
- error = Watir::Wait::TimeoutError
247
- inspected = '#<Watir::Div: located: false; {:id=>"foo", :tag_name=>"div"}>'
248
- message = "timed out after 1 seconds, waiting for false condition on #{inspected}"
249
- expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(error, message)
250
- end
222
+ describe "#wait_while_present" do
223
+ it "waits until the element disappears" do
224
+ browser.a(id: 'hide_foo').click
225
+ expect { browser.div(id: 'foo').wait_while_present(timeout: 2) }.to_not raise_exception
226
+ end
251
227
 
252
- it "uses provided interval" do
253
- element = browser.div(id: 'foo')
254
- expect(element).to receive(:present?).twice
228
+ it "times out if the element doesn't disappear" do
229
+ error = Watir::Wait::TimeoutError
230
+ inspected = '#<Watir::Div: located: false; {:id=>"foo", :tag_name=>"div"}>'
231
+ message = "timed out after 1 seconds, waiting for false condition on #{inspected}"
232
+ expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(error, message)
233
+ end
255
234
 
256
- begin
257
- element.wait_until_present(timeout: 0.4, interval: 0.2)
258
- rescue Watir::Wait::TimeoutError
259
- end
260
- end
235
+ it "uses provided interval" do
236
+ element = browser.div(id: 'foo')
237
+ expect(element).to receive(:present?).twice
261
238
 
262
- it "ordered pairs are deprecated" do
263
- browser.a(id: 'hide_foo').click
264
- message = /Instead of passing arguments into #wait_while_present method, use keywords/
265
- expect { browser.div(id: 'foo').wait_while_present(5) }.to output(message).to_stderr
239
+ begin
240
+ element.wait_until_present(timeout: 0.4, interval: 0.2)
241
+ rescue Watir::Wait::TimeoutError
266
242
  end
243
+ end
267
244
 
268
- it "does not error when element goes stale" do
269
- element = browser.div(id: 'foo')
245
+ it "does not error when element goes stale" do
246
+ element = browser.div(id: 'foo')
270
247
 
271
- allow(element).to receive(:stale?).and_return(false, true)
272
- allow(element.wd).to receive(:displayed?).and_raise(Selenium::WebDriver::Error::StaleElementReferenceError)
248
+ allow(element).to receive(:stale?).and_return(false, true)
249
+ allow(element.wd).to receive(:displayed?).and_raise(Selenium::WebDriver::Error::StaleElementReferenceError)
273
250
 
274
- browser.a(id: 'hide_foo').click
275
- expect { element.wait_while_present(timeout: 1) }.to_not raise_exception
276
- end
251
+ browser.a(id: 'hide_foo').click
252
+ expect { element.wait_while_present(timeout: 1) }.to_not raise_exception
253
+ end
277
254
 
278
- it "waits until the selector no longer matches" do
279
- Watir.default_timeout = 1
280
- element = browser.link(name: 'add_select').wait_until(&:exists?)
281
- begin
282
- start_time = ::Time.now
283
- browser.link(id: 'change_select').click
284
- expect { element.wait_while_present }.not_to raise_error
285
- ensure
286
- Watir.default_timeout = 30
287
- end
255
+ it "waits until the selector no longer matches" do
256
+ Watir.default_timeout = 1
257
+ element = browser.link(name: 'add_select').wait_until(&:exists?)
258
+ begin
259
+ start_time = ::Time.now
260
+ browser.link(id: 'change_select').click
261
+ expect { element.wait_while_present }.not_to raise_error
262
+ ensure
263
+ Watir.default_timeout = 30
288
264
  end
289
265
  end
266
+ end
290
267
 
291
- describe "#wait_until" do
292
- it "returns element for additional actions" do
293
- element = browser.div(id: 'foo')
294
- expect(element.wait_until(&:exist?)).to eq element
295
- end
268
+ describe "#wait_until" do
269
+ it "returns element for additional actions" do
270
+ element = browser.div(id: 'foo')
271
+ expect(element.wait_until(&:exist?)).to eq element
272
+ end
296
273
 
297
- it "accepts self in block" do
298
- element = browser.div(id: 'bar')
299
- browser.a(id: 'show_bar').click
300
- expect { element.wait_until { |el| el.text == 'bar' } }.to_not raise_exception
301
- end
274
+ it "accepts self in block" do
275
+ element = browser.div(id: 'bar')
276
+ browser.a(id: 'show_bar').click
277
+ expect { element.wait_until { |el| el.text == 'bar' } }.to_not raise_exception
278
+ end
302
279
 
303
- it "accepts any values in block" do
304
- element = browser.div(id: 'bar')
305
- expect { element.wait_until { true } }.to_not raise_exception
306
- end
280
+ it "accepts any values in block" do
281
+ element = browser.div(id: 'bar')
282
+ expect { element.wait_until { true } }.to_not raise_exception
283
+ end
307
284
 
308
- it "accepts just a timeout parameter" do
309
- element = browser.div(id: 'bar')
310
- expect { element.wait_until(timeout: 0) { true } }.to_not raise_exception
311
- end
285
+ it "accepts just a timeout parameter" do
286
+ element = browser.div(id: 'bar')
287
+ expect { element.wait_until(timeout: 0) { true } }.to_not raise_exception
288
+ end
312
289
 
313
- it "accepts just a message parameter" do
314
- element = browser.div(id: 'bar')
315
- expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
316
- end
290
+ it "accepts just a message parameter" do
291
+ element = browser.div(id: 'bar')
292
+ expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
293
+ end
317
294
 
318
- it "accepts just an interval parameter" do
319
- element = browser.div(id: 'bar')
320
- expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
321
- end
295
+ it "accepts just an interval parameter" do
296
+ element = browser.div(id: 'bar')
297
+ expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
322
298
  end
299
+ end
323
300
 
324
- describe "#wait_while" do
325
- it "returns element for additional actions" do
326
- element = browser.div(id: 'foo')
327
- browser.a(id: 'hide_foo').click
328
- expect(element.wait_while(&:present?)).to eq element
329
- end
301
+ describe "#wait_while" do
302
+ it "returns element for additional actions" do
303
+ element = browser.div(id: 'foo')
304
+ browser.a(id: 'hide_foo').click
305
+ expect(element.wait_while(&:present?)).to eq element
306
+ end
330
307
 
308
+ not_compliant_on :safari do
331
309
  it "accepts self in block" do
332
310
  element = browser.div(id: 'foo')
333
311
  browser.a(id: 'hide_foo').click
334
312
  expect { element.wait_while { |el| el.text == 'foo' } }.to_not raise_exception
335
313
  end
314
+ end
336
315
 
337
- it "accepts any values in block" do
338
- element = browser.div(id: 'foo')
339
- expect { element.wait_while { false } }.to_not raise_exception
340
- end
316
+ it "accepts any values in block" do
317
+ element = browser.div(id: 'foo')
318
+ expect { element.wait_while { false } }.to_not raise_exception
319
+ end
341
320
 
342
- it "accepts just a timeout parameter" do
343
- element = browser.div(id: 'foo')
344
- expect { element.wait_while(timeout: 0) { false } }.to_not raise_exception
345
- end
321
+ it "accepts just a timeout parameter" do
322
+ element = browser.div(id: 'foo')
323
+ expect { element.wait_while(timeout: 0) { false } }.to_not raise_exception
324
+ end
346
325
 
347
- it "accepts just a message parameter" do
348
- element = browser.div(id: 'foo')
349
- expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
350
- end
326
+ it "accepts just a message parameter" do
327
+ element = browser.div(id: 'foo')
328
+ expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
329
+ end
351
330
 
352
- it "accepts just an interval parameter" do
353
- element = browser.div(id: 'foo')
354
- expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
355
- end
331
+ it "accepts just an interval parameter" do
332
+ element = browser.div(id: 'foo')
333
+ expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
356
334
  end
357
335
  end
336
+ end
358
337
 
359
- describe Watir do
360
- describe "#default_timeout" do
361
- before do
362
- Watir.default_timeout = 1
338
+ describe Watir do
339
+ describe "#default_timeout" do
340
+ before do
341
+ Watir.default_timeout = 1
363
342
 
364
- browser.goto WatirSpec.url_for("wait.html")
365
- end
343
+ browser.goto WatirSpec.url_for("wait.html")
344
+ end
366
345
 
367
- after do
368
- # Reset the default timeout
369
- Watir.default_timeout = 30
370
- end
346
+ after do
347
+ # Reset the default timeout
348
+ Watir.default_timeout = 30
349
+ end
371
350
 
372
- context "when no timeout is specified" do
373
- it "is used by Wait#until" do
374
- expect {
375
- Watir::Wait.until { false }
376
- }.to raise_error(Watir::Wait::TimeoutError)
377
- end
351
+ context "when no timeout is specified" do
352
+ it "is used by Wait#until" do
353
+ expect {
354
+ Watir::Wait.until { false }
355
+ }.to raise_error(Watir::Wait::TimeoutError)
356
+ end
378
357
 
379
- it "is used by Wait#while" do
380
- expect {
381
- Watir::Wait.while { true }
382
- }.to raise_error(Watir::Wait::TimeoutError)
383
- end
358
+ it "is used by Wait#while" do
359
+ expect {
360
+ Watir::Wait.while { true }
361
+ }.to raise_error(Watir::Wait::TimeoutError)
362
+ end
384
363
 
385
- it "is used by Element#wait_until_present" do
386
- expect {
387
- browser.div(id: 'bar').wait_until_present
388
- }.to raise_error(Watir::Wait::TimeoutError)
389
- end
364
+ it "is used by Element#wait_until_present" do
365
+ expect {
366
+ browser.div(id: 'bar').wait_until_present
367
+ }.to raise_error(Watir::Wait::TimeoutError)
368
+ end
390
369
 
391
- it "is used by Element#wait_while_present" do
392
- expect {
393
- browser.div(id: 'foo').wait_while_present
394
- }.to raise_error(Watir::Wait::TimeoutError)
395
- end
370
+ it "is used by Element#wait_while_present" do
371
+ expect {
372
+ browser.div(id: 'foo').wait_while_present
373
+ }.to raise_error(Watir::Wait::TimeoutError)
396
374
  end
397
375
  end
398
376
  end