watir 6.17.0 → 7.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/actions/enable-safari/action.yml +11 -0
  3. data/.github/actions/install-chrome/action.yml +12 -0
  4. data/.github/actions/setup-linux/action.yml +8 -0
  5. data/.github/workflows/tests.yml +104 -0
  6. data/.rubocop.yml +2 -7
  7. data/.rubocop_todo.yml +36 -0
  8. data/CHANGES.md +59 -0
  9. data/LICENSE +2 -2
  10. data/README.md +6 -10
  11. data/Rakefile +2 -2
  12. data/lib/watir.rb +4 -45
  13. data/lib/watir/adjacent.rb +1 -1
  14. data/lib/watir/alert.rb +4 -8
  15. data/lib/watir/attribute_helper.rb +2 -0
  16. data/lib/watir/browser.rb +20 -6
  17. data/lib/watir/capabilities.rb +79 -110
  18. data/lib/watir/cell_container.rb +4 -4
  19. data/lib/watir/container.rb +4 -26
  20. data/lib/watir/cookies.rb +2 -0
  21. data/lib/watir/element_collection.rb +21 -6
  22. data/lib/watir/elements/checkbox.rb +4 -4
  23. data/lib/watir/elements/date_field.rb +4 -4
  24. data/lib/watir/elements/date_time_field.rb +4 -4
  25. data/lib/watir/elements/element.rb +51 -59
  26. data/lib/watir/elements/file_field.rb +4 -4
  27. data/lib/watir/elements/font.rb +5 -4
  28. data/lib/watir/elements/hidden.rb +4 -4
  29. data/lib/watir/elements/html_elements.rb +444 -446
  30. data/lib/watir/elements/iframe.rb +6 -6
  31. data/lib/watir/elements/radio.rb +6 -6
  32. data/lib/watir/elements/select.rb +62 -90
  33. data/lib/watir/elements/svg_elements.rb +96 -96
  34. data/lib/watir/elements/text_field.rb +4 -4
  35. data/lib/watir/generator/base/generator.rb +4 -4
  36. data/lib/watir/generator/base/visitor.rb +0 -29
  37. data/lib/watir/generator/html/generator.rb +2 -1
  38. data/lib/watir/has_window.rb +22 -18
  39. data/lib/watir/http_client.rb +9 -0
  40. data/lib/watir/js_execution.rb +2 -2
  41. data/lib/watir/js_snippets.rb +2 -2
  42. data/lib/watir/locators.rb +6 -8
  43. data/lib/watir/locators/button/matcher.rb +0 -23
  44. data/lib/watir/locators/button/selector_builder/xpath.rb +4 -15
  45. data/lib/watir/locators/element/matcher.rb +4 -19
  46. data/lib/watir/locators/element/selector_builder.rb +3 -41
  47. data/lib/watir/locators/element/selector_builder/xpath.rb +34 -41
  48. data/lib/watir/locators/option/matcher.rb +24 -0
  49. data/lib/watir/locators/option/selector_builder.rb +8 -0
  50. data/lib/watir/locators/option/selector_builder/xpath.rb +37 -0
  51. data/lib/watir/logger.rb +4 -91
  52. data/lib/watir/radio_set.rb +5 -4
  53. data/lib/watir/row_container.rb +4 -4
  54. data/lib/watir/screenshot.rb +2 -8
  55. data/lib/watir/user_editable.rb +13 -2
  56. data/lib/watir/version.rb +1 -1
  57. data/lib/watir/wait.rb +6 -74
  58. data/lib/watir/wait/timer.rb +1 -1
  59. data/lib/watir/window.rb +24 -25
  60. data/lib/watir/window_collection.rb +79 -0
  61. data/lib/watirspec.rb +5 -2
  62. data/lib/watirspec/guards.rb +1 -1
  63. data/lib/watirspec/implementation.rb +7 -5
  64. data/lib/watirspec/runner.rb +2 -2
  65. data/lib/watirspec/server.rb +2 -2
  66. data/spec/spec_helper.rb +1 -21
  67. data/spec/unit/capabilities_spec.rb +504 -21
  68. data/spec/unit/match_elements/button_spec.rb +0 -13
  69. data/spec/unit/match_elements/element_spec.rb +55 -51
  70. data/spec/unit/match_elements/text_field_spec.rb +6 -6
  71. data/spec/unit/selector_builder/element_spec.rb +6 -23
  72. data/spec/unit/selector_builder/text_field_spec.rb +6 -7
  73. data/spec/unit/unit_helper.rb +2 -4
  74. data/spec/watirspec/after_hooks_spec.rb +23 -42
  75. data/spec/watirspec/alert_spec.rb +4 -21
  76. data/spec/watirspec/browser_spec.rb +186 -206
  77. data/spec/watirspec/cookies_spec.rb +47 -52
  78. data/spec/watirspec/drag_and_drop_spec.rb +5 -7
  79. data/spec/watirspec/elements/area_spec.rb +1 -5
  80. data/spec/watirspec/elements/button_spec.rb +4 -18
  81. data/spec/watirspec/elements/checkbox_spec.rb +10 -24
  82. data/spec/watirspec/elements/date_field_spec.rb +13 -16
  83. data/spec/watirspec/elements/date_time_field_spec.rb +14 -13
  84. data/spec/watirspec/elements/dd_spec.rb +3 -4
  85. data/spec/watirspec/elements/del_spec.rb +10 -12
  86. data/spec/watirspec/elements/div_spec.rb +45 -84
  87. data/spec/watirspec/elements/divs_spec.rb +2 -2
  88. data/spec/watirspec/elements/dl_spec.rb +4 -12
  89. data/spec/watirspec/elements/element_spec.rb +204 -181
  90. data/spec/watirspec/elements/elements_spec.rb +8 -9
  91. data/spec/watirspec/elements/filefield_spec.rb +5 -7
  92. data/spec/watirspec/elements/form_spec.rb +3 -5
  93. data/spec/watirspec/elements/forms_spec.rb +3 -5
  94. data/spec/watirspec/elements/frame_spec.rb +17 -22
  95. data/spec/watirspec/elements/iframe_spec.rb +25 -33
  96. data/spec/watirspec/elements/ins_spec.rb +10 -12
  97. data/spec/watirspec/elements/link_spec.rb +23 -23
  98. data/spec/watirspec/elements/links_spec.rb +8 -9
  99. data/spec/watirspec/elements/radio_spec.rb +11 -14
  100. data/spec/watirspec/elements/select_list_spec.rb +358 -209
  101. data/spec/watirspec/elements/span_spec.rb +12 -14
  102. data/spec/watirspec/elements/spans_spec.rb +1 -1
  103. data/spec/watirspec/elements/strong_spec.rb +1 -1
  104. data/spec/watirspec/elements/table_nesting_spec.rb +31 -34
  105. data/spec/watirspec/elements/table_spec.rb +11 -13
  106. data/spec/watirspec/elements/tbody_spec.rb +10 -12
  107. data/spec/watirspec/elements/td_spec.rb +4 -6
  108. data/spec/watirspec/elements/text_field_spec.rb +10 -12
  109. data/spec/watirspec/elements/tr_spec.rb +5 -7
  110. data/spec/watirspec/html/non_control_elements.html +8 -3
  111. data/spec/watirspec/html/special_chars.html +3 -0
  112. data/spec/watirspec/html/wait.html +5 -5
  113. data/spec/watirspec/html/window_switching.html +10 -0
  114. data/spec/watirspec/special_chars_spec.rb +10 -0
  115. data/spec/watirspec/support/rspec_matchers.rb +11 -24
  116. data/spec/watirspec/user_editable_spec.rb +26 -28
  117. data/spec/watirspec/wait_spec.rb +154 -201
  118. data/spec/watirspec/window_switching_spec.rb +359 -270
  119. data/spec/watirspec_helper.rb +52 -49
  120. data/support/doctest_helper.rb +0 -2
  121. data/watir.gemspec +4 -5
  122. metadata +30 -39
  123. data/.travis.yml +0 -87
  124. data/appveyor.yml +0 -13
  125. data/lib/watir/legacy_wait.rb +0 -123
  126. data/spec/implementation_spec.rb +0 -24
  127. data/spec/unit/container_spec.rb +0 -35
  128. data/spec/unit/logger_spec.rb +0 -81
  129. data/spec/watirspec/relaxed_locate_spec.rb +0 -109
@@ -5,34 +5,32 @@ describe Watir::UserEditable do
5
5
  browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
6
6
  end
7
7
 
8
- bug 'incorrectly clears first', :safari do
9
- describe '#append' do
10
- it 'appends the text to the text field' do
11
- browser.text_field(name: 'new_user_occupation').append(' Append This')
12
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer Append This'
13
- end
14
-
15
- it 'appends multi-byte characters' do
16
- browser.text_field(name: 'new_user_occupation').append(' ijij')
17
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer ijij'
18
- end
19
-
20
- it 'raises NotImplementedError if the object is content editable element' do
21
- msg = '#append method is not supported with contenteditable element'
22
- expect { browser.div(id: 'contenteditable').append('bar') }.to raise_exception(NotImplementedError, msg)
23
- end
24
-
25
- it 'raises ObjectReadOnlyException if the object is read only' do
26
- expect { browser.text_field(id: 'new_user_code').append('Append This') }.to raise_object_read_only_exception
27
- end
28
-
29
- it 'raises ObjectDisabledException if the object is disabled' do
30
- expect { browser.text_field(name: 'new_user_species').append('Append This') }.to raise_object_disabled_exception
31
- end
32
-
33
- it "raises UnknownObjectException if the object doesn't exist" do
34
- expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
35
- end
8
+ describe '#append' do
9
+ it 'appends the text to the text field', except: {browser: :safari, reason: 'incorrectly clears first'} do
10
+ browser.text_field(name: 'new_user_occupation').append(' Append This')
11
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer Append This'
12
+ end
13
+
14
+ it 'appends multi-byte characters', except: {browser: :safari, reason: 'incorrectly clears first'} do
15
+ browser.text_field(name: 'new_user_occupation').append(' ijij')
16
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer ijij'
17
+ end
18
+
19
+ it 'raises NotImplementedError if the object is content editable element' do
20
+ msg = '#append method is not supported with contenteditable element'
21
+ expect { browser.div(id: 'contenteditable').append('bar') }.to raise_exception(NotImplementedError, msg)
22
+ end
23
+
24
+ it 'raises ObjectReadOnlyException if the object is read only' do
25
+ expect { browser.text_field(id: 'new_user_code').append('Append This') }.to raise_object_read_only_exception
26
+ end
27
+
28
+ it 'raises ObjectDisabledException if the object is disabled' do
29
+ expect { browser.text_field(name: 'new_user_species').append('Append This') }.to raise_object_disabled_exception
30
+ end
31
+
32
+ it "raises UnknownObjectException if the object doesn't exist" do
33
+ expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
36
34
  end
37
35
  end
38
36
 
@@ -1,191 +1,33 @@
1
1
  require 'watirspec_helper'
2
2
 
3
- describe Watir::Element do
3
+ describe Watir do
4
4
  before do
5
5
  browser.goto WatirSpec.url_for('wait.html')
6
6
  end
7
7
 
8
- # TODO: This is deprecated; remove in future version
9
- not_compliant_on :relaxed_locate do
10
- describe '#when_present' do
11
- it 'invokes subsequent method calls when the element becomes present' do
12
- browser.a(id: 'show_bar').click
13
-
14
- bar = browser.div(id: 'bar')
15
- bar.when_present(2).click
16
- expect(bar.text).to eq 'changed'
17
- end
18
-
19
- it 'times out when given a block' do
20
- expect { browser.div(id: 'bar').when_present(1) {} }.to raise_error(Watir::Wait::TimeoutError)
21
- end
22
-
23
- it 'times out when not given a block' do
24
- locator = '(\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\})'
25
- msg = /^timed out after 1 seconds, waiting for #{locator} to become present$/
26
- expect { browser.div(id: 'bar').when_present(1).click }.to raise_error(Watir::Wait::TimeoutError, msg)
27
- end
28
-
29
- it 'responds to Element methods' do
30
- decorator = browser.div.when_present
31
-
32
- expect(decorator).to respond_to(:exist?)
33
- expect(decorator).to respond_to(:present?)
34
- expect(decorator).to respond_to(:click)
35
- end
36
-
37
- it 'delegates present? to element' do
38
- Object.class_eval do
39
- def present?
40
- false
41
- end
42
- end
43
- element = browser.a(id: 'show_bar').when_present(1)
44
- expect(element).to be_present
45
- end
46
-
47
- it 'processes before calling present?' do
48
- browser.a(id: 'show_bar').click
49
- expect(browser.div(id: 'bar').when_present.present?).to be true
50
- end
51
- end
52
- end
53
-
54
- compliant_on :relaxed_locate do
55
- it 'clicking automatically waits until the element appears' do
56
- browser.a(id: 'show_bar').click
57
- expect { browser.div(id: 'bar').click }.to_not raise_exception
58
- expect(browser.div(id: 'bar').text).to eq 'changed'
59
- end
60
-
61
- it "raises exception if the element doesn't appear" do
62
- expect { browser.div(id: 'bar').click }.to raise_unknown_object_exception
63
- end
64
-
65
- it "raises exception if the element doesn't become enabled" do
66
- expect { browser.button(id: 'btn').click }.to raise_object_disabled_exception
67
- end
68
- end
69
-
70
- not_compliant_on :relaxed_locate do
71
- describe '#wait_until &:enabled?' do
72
- it 'invokes subsequent method calls when the element becomes enabled' do
73
- browser.a(id: 'enable_btn').click
74
-
75
- btn = browser.button(id: 'btn')
76
- btn.wait_until(timeout: 2, &:enabled?).click
77
- Watir::Wait.while { btn.enabled? }
78
- expect(btn.disabled?).to be true
79
- end
80
-
81
- it 'times out' do
82
- error = Watir::Wait::TimeoutError
83
- inspected = '#<Watir::Button: located: true; {:id=>"btn", :tag_name=>"button"}>'
84
- message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
85
- element = browser.button(id: 'btn')
86
- expect { element.wait_until(timeout: 1, &:enabled?).click }.to raise_error(error, message)
87
- end
88
-
89
- it 'responds to Element methods' do
90
- element = browser.button.wait_until { true }
91
-
92
- expect(element).to respond_to(:exist?)
93
- expect(element).to respond_to(:present?)
94
- expect(element).to respond_to(:click)
8
+ describe '#default_timeout' do
9
+ context 'when no timeout is specified' do
10
+ it 'is used by Wait#until' do
11
+ expect { Watir::Wait.until { false } }.to wait_and_raise_timeout_exception(timeout: 1)
95
12
  end
96
13
 
97
- it 'can be chained with #wait_until &:present?' do
98
- browser.a(id: 'show_and_enable_btn').click
99
- browser.button(id: 'btn2').wait_until(&:present?).wait_until(&:enabled?).click
100
-
101
- expect(browser.button(id: 'btn2')).to exist
102
- expect(browser.button(id: 'btn2')).to be_enabled
14
+ it 'is used by Wait#while' do
15
+ expect { Watir::Wait.while { true } }.to wait_and_raise_timeout_exception(timeout: 1)
103
16
  end
104
- end
105
- end
106
-
107
- describe '#wait_until_present' do
108
- it 'waits until the element appears' do
109
- browser.a(id: 'show_bar').click
110
- expect {
111
- expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
112
- }.to have_deprecated_wait_until_present
113
- end
114
17
 
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
18
+ it 'ensures all checks happen once even if time has expired' do
19
+ Watir.default_timeout = -1
20
+ expect { browser.link.click }.to_not raise_exception
21
+ ensure
22
+ Watir.default_timeout = 5
121
23
  end
122
24
  end
123
-
124
- it "times out if the element doesn't appear" do
125
- inspected = '#<Watir::Div: located: true; {:id=>"bar", :tag_name=>"div"}>'
126
- error = Watir::Wait::TimeoutError
127
- message = "timed out after 1 seconds, waiting for #{inspected} to become present"
128
-
129
- expect {
130
- expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
131
- }.to have_deprecated_wait_until_present
132
- end
133
-
134
- it 'uses provided interval' do
135
- element = browser.div(id: 'bar')
136
- expect(element).to receive(:present?).twice
137
-
138
- expect {
139
- expect { element.wait_until_present(timeout: 0.4, interval: 0.2) }.to raise_timeout_exception
140
- }.to have_deprecated_wait_until_present
141
- end
142
25
  end
26
+ end
143
27
 
144
- describe '#wait_while_present' do
145
- it 'waits until the element disappears' do
146
- browser.a(id: 'hide_foo').click
147
- expect {
148
- expect { browser.div(id: 'foo').wait_while_present(timeout: 2) }.to_not raise_exception
149
- }.to have_deprecated_wait_while_present
150
- end
151
-
152
- it "times out if the element doesn't disappear" do
153
- error = Watir::Wait::TimeoutError
154
- inspected = '#<Watir::Div: located: true; {:id=>"foo", :tag_name=>"div"}>'
155
- message = "timed out after 1 seconds, waiting for #{inspected} not to be present"
156
- expect {
157
- expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(error, message)
158
- }.to have_deprecated_wait_while_present
159
- end
160
-
161
- it 'uses provided interval' do
162
- error = Watir::Wait::TimeoutError
163
- element = browser.div(id: 'foo')
164
- expect(element).to receive(:present?).and_return(true).twice
165
-
166
- expect {
167
- expect { element.wait_while_present(timeout: 0.4, interval: 0.2) }.to raise_error(error)
168
- }.to have_deprecated_wait_while_present
169
- end
170
-
171
- it 'does not error when element goes stale' do
172
- element = browser.div(id: 'foo').locate
173
-
174
- allow(element).to receive(:stale?).and_return(false, true)
175
-
176
- browser.a(id: 'hide_foo').click
177
- expect {
178
- expect { element.wait_while_present(timeout: 1) }.to_not raise_exception
179
- }.to have_deprecated_wait_while_present
180
- end
181
-
182
- it 'waits until the selector no longer matches' do
183
- element = browser.link(name: 'add_select').wait_until(&:exists?)
184
- browser.link(id: 'change_select').click
185
- expect {
186
- expect { element.wait_while_present }.not_to raise_error
187
- }.to have_deprecated_wait_while_present
188
- end
28
+ describe Watir::Element do
29
+ before do
30
+ browser.goto WatirSpec.url_for('wait.html')
189
31
  end
190
32
 
191
33
  describe '#wait_until' do
@@ -292,12 +134,11 @@ describe Watir::Element do
292
134
  end
293
135
 
294
136
  context 'accepts keywords instead of block' do
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
137
+ it 'accepts text keyword', except: {browser: :safari,
138
+ reason: 'Safari does not recognize date type'} do
139
+ element = browser.div(id: 'foo')
140
+ browser.a(id: 'hide_foo').click
141
+ expect { element.wait_while(text: 'foo') }.to_not raise_exception
301
142
  end
302
143
 
303
144
  it 'accepts regular expression value' do
@@ -363,34 +204,146 @@ describe Watir::Element do
363
204
  end
364
205
  end
365
206
  end
207
+
208
+ context 'when acting on an element that is never present' do
209
+ it 'raises exception after timing out' do
210
+ element = browser.link(id: 'not_there')
211
+ expect { element.click }.to wait_and_raise_unknown_object_exception
212
+ end
213
+ end
214
+
215
+ context 'when acting on an element that is already present' do
216
+ it 'does not wait' do
217
+ expect { browser.link.click }.to execute_when_satisfied(max: 1)
218
+ end
219
+ end
220
+
221
+ context 'when acting on an element that eventually becomes present' do
222
+ it 'waits until element is present and then takes action' do
223
+ expect {
224
+ browser.a(id: 'show_bar').click
225
+ browser.div(id: 'bar').click
226
+ }.to execute_when_satisfied(min: 1)
227
+ expect(browser.div(id: 'bar').text).to eq 'changed'
228
+ end
229
+
230
+ it 'waits until text field present and then takes action' do
231
+ expect {
232
+ browser.a(id: 'show_textfield').click
233
+ browser.text_field(id: 'textfield').set 'Foo'
234
+ }.to execute_when_satisfied(min: 1)
235
+ end
236
+ end
237
+
238
+ context 'when acting on a read only text field' do
239
+ it 'waits and raises read only exception if never becomes writable' do
240
+ expect { browser.text_field(id: 'writable').set 'foo' }.to wait_and_raise_object_read_only_exception
241
+ end
242
+
243
+ it 'waits until writable' do
244
+ expect {
245
+ browser.a(id: 'make-writable').click
246
+ browser.text_field(id: 'writable').set 'foo'
247
+ }.to execute_when_satisfied(min: 1)
248
+ end
249
+ end
250
+
251
+ context 'when acting on a disabled button' do
252
+ it 'waits and raises exception if it never becomes enabled' do
253
+ expect { browser.button(id: 'btn').click }.to wait_and_raise_object_disabled_exception
254
+ end
255
+
256
+ it 'waits until enabled' do
257
+ expect {
258
+ browser.a(id: 'enable_btn').click
259
+ browser.button(id: 'btn').click
260
+ }.to execute_when_satisfied(min: 1)
261
+ end
262
+ end
263
+
264
+ context 'when acting on an element with a parent' do
265
+ it 'raises exception after timing out if parent never present' do
266
+ element = browser.link(id: 'not_there')
267
+ expect { element.element.click }.to wait_and_raise_unknown_object_exception
268
+ end
269
+
270
+ it 'raises exception after timing out when element from a collection whose parent is never present' do
271
+ element = browser.link(id: 'not_there')
272
+ expect { element.elements[2].click }.to wait_and_raise_unknown_object_exception
273
+ end
274
+
275
+ it 'does not wait for parent element to be present when querying child element' do
276
+ el = browser.element(id: 'not_there').element(id: 'doesnt_matter')
277
+ expect { el.present? }.to execute_when_satisfied(max: 1)
278
+ end
279
+ end
366
280
  end
367
281
 
368
- describe Watir do
369
- describe '#default_timeout' do
370
- before do
371
- browser.goto WatirSpec.url_for('wait.html')
282
+ describe Watir::ElementCollection do
283
+ before do
284
+ browser.goto WatirSpec.url_for('wait.html')
285
+ end
286
+
287
+ describe '#wait_until' do
288
+ it 'returns collection' do
289
+ elements = browser.divs
290
+ expect(elements.wait_until(&:exist?)).to eq elements
372
291
  end
373
292
 
374
- context 'when no timeout is specified' do
375
- it 'is used by Wait#until' do
376
- expect { Watir::Wait.until { false } }.to wait_and_raise_timeout_exception(timeout: 1)
377
- end
293
+ it 'times out when waiting for non-empty collection' do
294
+ expect { browser.divs.wait_until(&:empty?) }.to raise_timeout_exception
295
+ end
378
296
 
379
- it 'is used by Wait#while' do
380
- expect { Watir::Wait.while { true } }.to wait_and_raise_timeout_exception(timeout: 1)
381
- end
297
+ it 'provides matching collection when exists' do
298
+ expect {
299
+ browser.a(id: 'add_foobar').click
300
+ browser.divs(id: 'foobar').wait_until(&:exists?)
301
+ }.to execute_when_satisfied(min: 1)
302
+ end
382
303
 
383
- it 'is used by Element#wait_until_present' do
384
- expect {
385
- expect { browser.div(id: 'bar').wait_until_present }.to wait_and_raise_timeout_exception(timeout: 1)
386
- }.to have_deprecated_wait_until_present
387
- end
304
+ it 'accepts self in block' do
305
+ expect {
306
+ browser.a(id: 'add_foobar').click
307
+ browser.divs.wait_until { |els| els.size == 7 }
308
+ }.to execute_when_satisfied(min: 1)
309
+ end
388
310
 
389
- it 'is used by Element#wait_while_present' do
390
- expect {
391
- expect { browser.div(id: 'foo').wait_while_present }.to wait_and_raise_timeout_exception(timeout: 1)
392
- }.to have_deprecated_wait_while_present
393
- end
311
+ it 'accepts attributes to evaluate' do
312
+ expect {
313
+ browser.a(id: 'add_foobar').click
314
+ browser.divs.wait_until(size: 7)
315
+ }.to execute_when_satisfied(min: 1)
316
+ end
317
+ end
318
+
319
+ describe '#wait_while' do
320
+ it 'returns collection' do
321
+ elements = browser.divs
322
+ expect(elements.wait_while(&:empty?)).to eq elements
323
+ end
324
+
325
+ it 'times out when waiting for non-empty collection' do
326
+ elements = browser.divs
327
+ expect { elements.wait_while(&:exists?) }.to raise_timeout_exception
394
328
  end
329
+
330
+ it 'provides matching collection when exists' do
331
+ expect {
332
+ browser.a(id: 'remove_foo').click
333
+ browser.divs(id: 'foo').wait_while(&:exists?)
334
+ }.to execute_when_satisfied(min: 1)
335
+ end
336
+
337
+ it 'accepts self in block' do
338
+ expect {
339
+ browser.a(id: 'add_foobar').click
340
+ browser.divs.wait_while { |els| els.size == 6 }
341
+ }.to execute_when_satisfied(min: 1)
342
+ end
343
+ end
344
+
345
+ it 'waits for parent element to be present before locating' do
346
+ els = browser.element(id: /not|there/).elements(id: 'doesnt_matter')
347
+ expect { els.to_a }.to wait_and_raise_unknown_object_exception
395
348
  end
396
349
  end