watir 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +1 -1
  3. data/.github/workflows/edge.yml +1 -1
  4. data/.github/workflows/firefox.yml +1 -1
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +1 -1
  8. data/.rubocop.yml +25 -12
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +6 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +1 -1
  13. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  14. data/lib/watir/locators/element/matcher.rb +2 -1
  15. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  16. data/lib/watir/locators/text_field/matcher.rb +0 -4
  17. data/lib/watir/version.rb +1 -1
  18. data/spec/locator_spec_helper.rb +0 -8
  19. data/spec/unit/capabilities_spec.rb +553 -561
  20. data/spec/unit/element_locator_spec.rb +89 -78
  21. data/spec/unit/match_elements/button_spec.rb +69 -62
  22. data/spec/unit/match_elements/element_spec.rb +303 -309
  23. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  24. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  25. data/spec/unit/selector_builder/button_spec.rb +209 -202
  26. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  27. data/spec/unit/selector_builder/element_spec.rb +634 -627
  28. data/spec/unit/selector_builder/row_spec.rb +119 -113
  29. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  30. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  31. data/spec/unit/wait_spec.rb +85 -81
  32. data/spec/watirspec/adjacent_spec.rb +249 -247
  33. data/spec/watirspec/after_hooks_spec.rb +161 -159
  34. data/spec/watirspec/alert_spec.rb +61 -58
  35. data/spec/watirspec/browser_spec.rb +409 -409
  36. data/spec/watirspec/capabilities_spec.rb +89 -99
  37. data/spec/watirspec/cookies_spec.rb +120 -118
  38. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  39. data/spec/watirspec/element_hidden_spec.rb +66 -60
  40. data/spec/watirspec/elements/area_spec.rb +49 -47
  41. data/spec/watirspec/elements/areas_spec.rb +27 -25
  42. data/spec/watirspec/elements/button_spec.rb +253 -251
  43. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  44. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  45. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  46. data/spec/watirspec/elements/collections_spec.rb +126 -119
  47. data/spec/watirspec/elements/date_field_spec.rb +185 -183
  48. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  49. data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
  50. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  51. data/spec/watirspec/elements/dd_spec.rb +87 -85
  52. data/spec/watirspec/elements/dds_spec.rb +27 -25
  53. data/spec/watirspec/elements/del_spec.rb +106 -104
  54. data/spec/watirspec/elements/dels_spec.rb +26 -24
  55. data/spec/watirspec/elements/div_spec.rb +225 -221
  56. data/spec/watirspec/elements/divs_spec.rb +37 -35
  57. data/spec/watirspec/elements/dl_spec.rb +110 -108
  58. data/spec/watirspec/elements/dls_spec.rb +28 -26
  59. data/spec/watirspec/elements/dt_spec.rb +86 -84
  60. data/spec/watirspec/elements/dts_spec.rb +27 -25
  61. data/spec/watirspec/elements/element_spec.rb +794 -775
  62. data/spec/watirspec/elements/elements_spec.rb +40 -38
  63. data/spec/watirspec/elements/em_spec.rb +62 -60
  64. data/spec/watirspec/elements/ems_spec.rb +28 -26
  65. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  66. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  67. data/spec/watirspec/elements/font_spec.rb +20 -18
  68. data/spec/watirspec/elements/form_spec.rb +51 -49
  69. data/spec/watirspec/elements/forms_spec.rb +29 -27
  70. data/spec/watirspec/elements/frame_spec.rb +89 -87
  71. data/spec/watirspec/elements/frames_spec.rb +27 -25
  72. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  73. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  74. data/spec/watirspec/elements/hn_spec.rb +59 -57
  75. data/spec/watirspec/elements/hns_spec.rb +26 -24
  76. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  77. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  78. data/spec/watirspec/elements/image_spec.rb +148 -146
  79. data/spec/watirspec/elements/images_spec.rb +26 -24
  80. data/spec/watirspec/elements/input_spec.rb +9 -7
  81. data/spec/watirspec/elements/ins_spec.rb +106 -104
  82. data/spec/watirspec/elements/inses_spec.rb +26 -24
  83. data/spec/watirspec/elements/label_spec.rb +56 -54
  84. data/spec/watirspec/elements/labels_spec.rb +26 -24
  85. data/spec/watirspec/elements/li_spec.rb +76 -74
  86. data/spec/watirspec/elements/link_spec.rb +173 -177
  87. data/spec/watirspec/elements/links_spec.rb +45 -43
  88. data/spec/watirspec/elements/lis_spec.rb +27 -25
  89. data/spec/watirspec/elements/list_spec.rb +44 -42
  90. data/spec/watirspec/elements/map_spec.rb +57 -55
  91. data/spec/watirspec/elements/maps_spec.rb +27 -25
  92. data/spec/watirspec/elements/meta_spec.rb +16 -14
  93. data/spec/watirspec/elements/metas_spec.rb +26 -24
  94. data/spec/watirspec/elements/ol_spec.rb +56 -65
  95. data/spec/watirspec/elements/ols_spec.rb +26 -24
  96. data/spec/watirspec/elements/option_spec.rb +91 -89
  97. data/spec/watirspec/elements/p_spec.rb +81 -79
  98. data/spec/watirspec/elements/pre_spec.rb +77 -75
  99. data/spec/watirspec/elements/pres_spec.rb +26 -24
  100. data/spec/watirspec/elements/ps_spec.rb +26 -24
  101. data/spec/watirspec/elements/radio_spec.rb +251 -249
  102. data/spec/watirspec/elements/radios_spec.rb +28 -26
  103. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  104. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  105. data/spec/watirspec/elements/span_spec.rb +112 -110
  106. data/spec/watirspec/elements/spans_spec.rb +26 -24
  107. data/spec/watirspec/elements/strong_spec.rb +58 -58
  108. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  109. data/spec/watirspec/elements/table_spec.rb +192 -139
  110. data/spec/watirspec/elements/tables_spec.rb +28 -26
  111. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  112. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  113. data/spec/watirspec/elements/td_spec.rb +66 -64
  114. data/spec/watirspec/elements/tds_spec.rb +41 -39
  115. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  116. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  117. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  118. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  119. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  120. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  121. data/spec/watirspec/elements/thead_spec.rb +65 -63
  122. data/spec/watirspec/elements/theads_spec.rb +42 -40
  123. data/spec/watirspec/elements/tr_spec.rb +48 -46
  124. data/spec/watirspec/elements/trs_spec.rb +42 -40
  125. data/spec/watirspec/elements/ul_spec.rb +56 -54
  126. data/spec/watirspec/elements/uls_spec.rb +26 -24
  127. data/spec/watirspec/radio_set_spec.rb +269 -267
  128. data/spec/watirspec/screenshot_spec.rb +20 -18
  129. data/spec/watirspec/scroll_spec.rb +152 -148
  130. data/spec/watirspec/shadow_root_spec.rb +86 -83
  131. data/spec/watirspec/user_editable_spec.rb +200 -198
  132. data/spec/watirspec/wait_spec.rb +289 -295
  133. data/spec/watirspec/window_switching_spec.rb +422 -434
  134. data/spec/watirspec_helper.rb +1 -23
  135. data/watir.gemspec +5 -4
  136. metadata +44 -33
  137. data/spec/watirspec/attributes_spec.rb +0 -18
  138. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  139. data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,350 +2,344 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe Watir do
6
- before do
7
- browser.goto WatirSpec.url_for('wait.html')
8
- end
5
+ module Watir
6
+ describe Wait do
7
+ before do
8
+ browser.goto WatirSpec.url_for('wait.html')
9
+ end
9
10
 
10
- describe '#default_timeout' do
11
- context 'when no timeout is specified' do
12
- it 'is used by Wait#until' do
13
- expect { Watir::Wait.until { false } }.to wait_and_raise_timeout_exception(timeout: 1)
14
- end
11
+ describe '#default_timeout' do
12
+ context 'when no timeout is specified' do
13
+ it 'is used by Wait#until' do
14
+ expect { described_class.until { false } }.to wait_and_raise_timeout_exception(timeout: 1)
15
+ end
15
16
 
16
- it 'is used by Wait#while' do
17
- expect { Watir::Wait.while { true } }.to wait_and_raise_timeout_exception(timeout: 1)
18
- end
17
+ it 'is used by Wait#while' do
18
+ expect { described_class.while { true } }.to wait_and_raise_timeout_exception(timeout: 1)
19
+ end
19
20
 
20
- it 'ensures all checks happen once even if time has expired' do
21
- Watir.default_timeout = -1
22
- expect { browser.link.click }.to_not raise_exception
23
- ensure
24
- Watir.default_timeout = 5
21
+ it 'ensures all checks happen once even if time has expired' do
22
+ Watir.default_timeout = -1
23
+ expect { browser.link.click }.not_to raise_exception
24
+ ensure
25
+ Watir.default_timeout = 5
26
+ end
25
27
  end
26
28
  end
27
- end
28
- end
29
-
30
- describe Watir::Element do
31
- before do
32
- browser.goto WatirSpec.url_for('wait.html')
33
- end
34
29
 
35
- describe '#wait_until' do
36
- it 'returns element for additional actions' do
37
- element = browser.div(id: 'foo')
38
- expect(element.wait_until(&:exist?)).to eq element
39
- end
40
-
41
- it 'accepts self in block' do
42
- element = browser.div(id: 'bar')
43
- browser.a(id: 'show_bar').click
44
- expect { element.wait_until { |el| el.text == 'bar' } }.to_not raise_exception
45
- end
30
+ context 'when acting on Element' do
31
+ describe '#wait_until' do
32
+ it 'returns element for additional actions' do
33
+ element = browser.div(id: 'foo')
34
+ expect(element.wait_until(&:exist?)).to eq element
35
+ end
46
36
 
47
- it 'accepts any values in block' do
48
- element = browser.div(id: 'bar')
49
- expect { element.wait_until { true } }.to_not raise_exception
50
- end
37
+ it 'accepts self in block' do
38
+ element = browser.div(id: 'bar')
39
+ browser.a(id: 'show_bar').click
40
+ expect { element.wait_until { |el| el.text == 'bar' } }.not_to raise_exception
41
+ end
51
42
 
52
- it 'accepts just a timeout parameter' do
53
- element = browser.div(id: 'bar')
54
- expect { element.wait_until(timeout: 0) { true } }.to_not raise_exception
55
- end
43
+ it 'accepts any values in block' do
44
+ element = browser.div(id: 'bar')
45
+ expect { element.wait_until { true } }.not_to raise_exception
46
+ end
56
47
 
57
- it 'accepts just a message parameter' do
58
- element = browser.div(id: 'bar')
59
- expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
60
- end
48
+ it 'accepts just a timeout parameter' do
49
+ element = browser.div(id: 'bar')
50
+ expect { element.wait_until(timeout: 0) { true } }.not_to raise_exception
51
+ end
61
52
 
62
- it 'accepts just an interval parameter' do
63
- element = browser.div(id: 'bar')
64
- expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
65
- end
53
+ it 'accepts just a message parameter' do
54
+ element = browser.div(id: 'bar')
55
+ expect { element.wait_until(message: 'no') { true } }.not_to raise_exception
56
+ end
66
57
 
67
- context 'accepts keywords instead of block' do
68
- before { browser.refresh }
58
+ it 'accepts just an interval parameter' do
59
+ element = browser.div(id: 'bar')
60
+ expect { element.wait_until(interval: 0.1) { true } }.not_to raise_exception
61
+ end
69
62
 
70
- it 'accepts text keyword' do
71
- element = browser.div(id: 'bar')
72
- browser.a(id: 'show_bar').click
73
- expect { element.wait_until(text: 'bar') }.to_not raise_exception
63
+ context 'when accepting keywords instead of block' do
64
+ before { browser.refresh }
65
+
66
+ it 'accepts text keyword' do
67
+ element = browser.div(id: 'bar')
68
+ browser.a(id: 'show_bar').click
69
+ expect { element.wait_until(text: 'bar') }.not_to raise_exception
70
+ end
71
+
72
+ it 'accepts regular expression value' do
73
+ element = browser.div(id: 'bar')
74
+ browser.a(id: 'show_bar').click
75
+ expect { element.wait_until(style: /block/) }.not_to raise_exception
76
+ end
77
+
78
+ it 'accepts multiple keywords' do
79
+ element = browser.div(id: 'bar')
80
+ browser.a(id: 'show_bar').click
81
+ expect { element.wait_until(text: 'bar', style: /block/) }.not_to raise_exception
82
+ end
83
+
84
+ it 'accepts custom keyword' do
85
+ element = browser.div(id: 'bar')
86
+ browser.a(id: 'show_bar').click
87
+ expect { element.wait_until(custom: 'bar') }.not_to raise_exception
88
+ end
89
+
90
+ it 'times out when single keyword not met' do
91
+ element = browser.div(id: 'bar')
92
+ expect { element.wait_until(id: 'foo') }.to raise_timeout_exception
93
+ end
94
+
95
+ it 'times out when one of multiple keywords not met' do
96
+ element = browser.div(id: 'bar')
97
+ expect { element.wait_until(id: 'bar', text: 'foo') }.to raise_timeout_exception
98
+ end
99
+
100
+ it 'times out when a custom keywords not met' do
101
+ element = browser.div(id: 'bar')
102
+ expect { element.wait_until(custom: 'foo') }.to raise_timeout_exception
103
+ end
104
+ end
74
105
  end
75
106
 
76
- it 'accepts regular expression value' do
77
- element = browser.div(id: 'bar')
78
- browser.a(id: 'show_bar').click
79
- expect { element.wait_until(style: /block/) }.to_not raise_exception
80
- end
107
+ describe '#wait_while' do
108
+ it 'returns element for additional actions' do
109
+ element = browser.div(id: 'foo')
110
+ browser.a(id: 'hide_foo').click
111
+ expect(element.wait_while(&:present?)).to eq element
112
+ end
81
113
 
82
- it 'accepts multiple keywords' do
83
- element = browser.div(id: 'bar')
84
- browser.a(id: 'show_bar').click
85
- expect { element.wait_until(text: 'bar', style: /block/) }.to_not raise_exception
86
- end
114
+ it 'accepts any values in block' do
115
+ element = browser.div(id: 'foo')
116
+ expect { element.wait_while { false } }.not_to raise_exception
117
+ end
87
118
 
88
- it 'accepts custom keyword' do
89
- element = browser.div(id: 'bar')
90
- browser.a(id: 'show_bar').click
91
- expect { element.wait_until(custom: 'bar') }.to_not raise_exception
92
- end
119
+ it 'accepts just a timeout parameter' do
120
+ element = browser.div(id: 'foo')
121
+ expect { element.wait_while(timeout: 0) { false } }.not_to raise_exception
122
+ end
93
123
 
94
- it 'times out when single keyword not met' do
95
- element = browser.div(id: 'bar')
96
- expect { element.wait_until(id: 'foo') }.to raise_timeout_exception
97
- end
124
+ it 'accepts just a message parameter' do
125
+ element = browser.div(id: 'foo')
126
+ expect { element.wait_while(message: 'no') { false } }.not_to raise_exception
127
+ end
98
128
 
99
- it 'times out when one of multiple keywords not met' do
100
- element = browser.div(id: 'bar')
101
- expect { element.wait_until(id: 'bar', text: 'foo') }.to raise_timeout_exception
102
- end
129
+ it 'accepts just an interval parameter' do
130
+ element = browser.div(id: 'foo')
131
+ expect { element.wait_while(interval: 0.1) { false } }.not_to raise_exception
132
+ end
103
133
 
104
- it 'times out when a custom keywords not met' do
105
- element = browser.div(id: 'bar')
106
- expect { element.wait_until(custom: 'foo') }.to raise_timeout_exception
134
+ context 'when accepting keywords instead of block' do
135
+ it 'accepts text keyword', except: {browser: :safari,
136
+ reason: 'Safari does not recognize date type'} do
137
+ element = browser.div(id: 'foo')
138
+ browser.a(id: 'hide_foo').click
139
+ expect { element.wait_while(text: 'foo') }.not_to raise_exception
140
+ end
141
+
142
+ it 'accepts regular expression value' do
143
+ element = browser.div(id: 'foo')
144
+ browser.a(id: 'hide_foo').click
145
+ expect { element.wait_while(style: /block/) }.not_to raise_exception
146
+ end
147
+
148
+ it 'accepts multiple keywords' do
149
+ element = browser.div(id: 'foo')
150
+ browser.a(id: 'hide_foo').click
151
+ expect { element.wait_while(text: 'foo', style: /block/) }.not_to raise_exception
152
+ end
153
+
154
+ it 'accepts custom attributes' do
155
+ element = browser.div(id: 'foo')
156
+ browser.a(id: 'hide_foo').click
157
+ expect { element.wait_while(custom: '') }.not_to raise_exception
158
+ end
159
+
160
+ it 'accepts keywords and block' do
161
+ element = browser.div(id: 'foo')
162
+ browser.a(id: 'hide_foo').click
163
+ expect { element.wait_while(custom: '', &:present?) }.not_to raise_exception
164
+ end
165
+
166
+ it 'browser accepts keywords' do
167
+ expect { browser.wait_until(title: 'wait test') }.not_to raise_exception
168
+ expect { browser.wait_until(title: 'wrong') }.to raise_timeout_exception
169
+ end
170
+
171
+ it 'alert accepts keywords' do
172
+ browser.goto WatirSpec.url_for('alerts.html')
173
+
174
+ begin
175
+ browser.button(id: 'alert').click
176
+ expect { browser.alert.wait_until(text: 'ok') }.not_to raise_exception
177
+ expect { browser.alert.wait_until(text: 'not ok') }.to raise_timeout_exception
178
+ ensure
179
+ browser.alert.ok
180
+ end
181
+ end
182
+
183
+ it 'window accepts keywords' do
184
+ expect { browser.window.wait_until(title: 'wait test') }.not_to raise_exception
185
+ expect { browser.window.wait_until(title: 'wrong') }.to raise_timeout_exception
186
+ end
187
+
188
+ it 'times out when single keyword not met' do
189
+ element = browser.div(id: 'foo')
190
+ expect { element.wait_while(id: 'foo') }.to raise_timeout_exception
191
+ end
192
+
193
+ it 'times out when one of multiple keywords not met' do
194
+ element = browser.div(id: 'foo')
195
+ browser.a(id: 'hide_foo').click
196
+ expect { element.wait_while(id: 'foo', style: /block/) }.to raise_timeout_exception
197
+ end
198
+
199
+ it 'times out when one of custom keywords not met' do
200
+ element = browser.div(id: 'foo')
201
+ expect { element.wait_while(custom: '') }.to raise_timeout_exception
202
+ end
203
+ end
107
204
  end
108
- end
109
- end
110
-
111
- describe '#wait_while' do
112
- it 'returns element for additional actions' do
113
- element = browser.div(id: 'foo')
114
- browser.a(id: 'hide_foo').click
115
- expect(element.wait_while(&:present?)).to eq element
116
- end
117
-
118
- it 'accepts any values in block' do
119
- element = browser.div(id: 'foo')
120
- expect { element.wait_while { false } }.to_not raise_exception
121
- end
122
-
123
- it 'accepts just a timeout parameter' do
124
- element = browser.div(id: 'foo')
125
- expect { element.wait_while(timeout: 0) { false } }.to_not raise_exception
126
- end
127
205
 
128
- it 'accepts just a message parameter' do
129
- element = browser.div(id: 'foo')
130
- expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
131
- end
132
-
133
- it 'accepts just an interval parameter' do
134
- element = browser.div(id: 'foo')
135
- expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
136
- end
137
-
138
- context 'accepts keywords instead of block' do
139
- it 'accepts text keyword', except: {browser: :safari,
140
- reason: 'Safari does not recognize date type'} do
141
- element = browser.div(id: 'foo')
142
- browser.a(id: 'hide_foo').click
143
- expect { element.wait_while(text: 'foo') }.to_not raise_exception
206
+ context 'when acting on an element that is never present' do
207
+ it 'raises exception after timing out' do
208
+ element = browser.link(id: 'not_there')
209
+ expect { element.click }.to wait_and_raise_unknown_object_exception
210
+ end
144
211
  end
145
212
 
146
- it 'accepts regular expression value' do
147
- element = browser.div(id: 'foo')
148
- browser.a(id: 'hide_foo').click
149
- expect { element.wait_while(style: /block/) }.to_not raise_exception
213
+ context 'when acting on an element that is already present' do
214
+ it 'does not wait' do
215
+ expect { browser.link.click }.to execute_when_satisfied(max: 1)
216
+ end
150
217
  end
151
218
 
152
- it 'accepts multiple keywords' do
153
- element = browser.div(id: 'foo')
154
- browser.a(id: 'hide_foo').click
155
- expect { element.wait_while(text: 'foo', style: /block/) }.to_not raise_exception
156
- end
219
+ context 'when acting on an element that eventually becomes present' do
220
+ it 'waits until element is present and then takes action' do
221
+ expect {
222
+ browser.a(id: 'show_bar').click
223
+ browser.div(id: 'bar').click
224
+ }.to execute_when_satisfied(min: 1, max: 4)
225
+ expect(browser.div(id: 'bar').text).to eq 'changed'
226
+ end
157
227
 
158
- it 'accepts custom attributes' do
159
- element = browser.div(id: 'foo')
160
- browser.a(id: 'hide_foo').click
161
- expect { element.wait_while(custom: '') }.to_not raise_exception
228
+ it 'waits until text field present and then takes action' do
229
+ expect {
230
+ browser.a(id: 'show_textfield').click
231
+ browser.text_field(id: 'textfield').set 'Foo'
232
+ }.to execute_when_satisfied(min: 1, max: 4)
233
+ end
162
234
  end
163
235
 
164
- it 'accepts keywords and block' do
165
- element = browser.div(id: 'foo')
166
- browser.a(id: 'hide_foo').click
167
- expect { element.wait_while(custom: '', &:present?) }.to_not raise_exception
168
- end
236
+ context 'when acting on a read only text field' do
237
+ it 'waits and raises read only exception if never becomes writable' do
238
+ expect { browser.text_field(id: 'writable').set 'foo' }.to wait_and_raise_object_read_only_exception
239
+ end
169
240
 
170
- it 'browser accepts keywords' do
171
- expect { browser.wait_until(title: 'wait test') }.to_not raise_exception
172
- expect { browser.wait_until(title: 'wrong') }.to raise_timeout_exception
241
+ it 'waits until writable' do
242
+ expect {
243
+ browser.a(id: 'make-writable').click
244
+ browser.text_field(id: 'writable').set 'foo'
245
+ }.to execute_when_satisfied(min: 1, max: 4)
246
+ end
173
247
  end
174
248
 
175
- it 'alert accepts keywords' do
176
- browser.goto WatirSpec.url_for('alerts.html')
177
-
178
- begin
179
- browser.button(id: 'alert').click
180
- expect { browser.alert.wait_until(text: 'ok') }.to_not raise_exception
181
- expect { browser.alert.wait_until(text: 'not ok') }.to raise_timeout_exception
182
- ensure
183
- browser.alert.ok
249
+ context 'when acting on a disabled button' do
250
+ it 'waits and raises exception if it never becomes enabled' do
251
+ expect { browser.button(id: 'btn').click }.to wait_and_raise_object_disabled_exception
184
252
  end
185
- end
186
253
 
187
- it 'window accepts keywords' do
188
- expect { browser.window.wait_until(title: 'wait test') }.to_not raise_exception
189
- expect { browser.window.wait_until(title: 'wrong') }.to raise_timeout_exception
254
+ it 'waits until enabled' do
255
+ expect {
256
+ browser.a(id: 'enable_btn').click
257
+ browser.button(id: 'btn').click
258
+ }.to execute_when_satisfied(min: 1, max: 4)
259
+ end
190
260
  end
191
261
 
192
- it 'times out when single keyword not met' do
193
- element = browser.div(id: 'foo')
194
- expect { element.wait_while(id: 'foo') }.to raise_timeout_exception
195
- end
262
+ context 'when acting on an element with a parent' do
263
+ it 'raises exception after timing out if parent never present' do
264
+ element = browser.link(id: 'not_there')
265
+ expect { element.element.click }.to wait_and_raise_unknown_object_exception
266
+ end
196
267
 
197
- it 'times out when one of multiple keywords not met' do
198
- element = browser.div(id: 'foo')
199
- browser.a(id: 'hide_foo').click
200
- expect { element.wait_while(id: 'foo', style: /block/) }.to raise_timeout_exception
201
- end
268
+ it 'raises exception after timing out when element from a collection whose parent is never present' do
269
+ element = browser.link(id: 'not_there')
270
+ expect { element.elements[2].click }.to wait_and_raise_unknown_object_exception
271
+ end
202
272
 
203
- it 'times out when one of custom keywords not met' do
204
- element = browser.div(id: 'foo')
205
- expect { element.wait_while(custom: '') }.to raise_timeout_exception
273
+ it 'does not wait for parent element to be present when querying child element' do
274
+ el = browser.element(id: 'not_there').element(id: 'doesnt_matter')
275
+ expect { el.present? }.to execute_when_satisfied(max: 1)
276
+ end
206
277
  end
207
278
  end
208
- end
209
-
210
- context 'when acting on an element that is never present' do
211
- it 'raises exception after timing out' do
212
- element = browser.link(id: 'not_there')
213
- expect { element.click }.to wait_and_raise_unknown_object_exception
214
- end
215
- end
216
-
217
- context 'when acting on an element that is already present' do
218
- it 'does not wait' do
219
- expect { browser.link.click }.to execute_when_satisfied(max: 1)
220
- end
221
- end
222
-
223
- context 'when acting on an element that eventually becomes present' do
224
- it 'waits until element is present and then takes action' do
225
- expect {
226
- browser.a(id: 'show_bar').click
227
- browser.div(id: 'bar').click
228
- }.to execute_when_satisfied(min: 1)
229
- expect(browser.div(id: 'bar').text).to eq 'changed'
230
- end
231
-
232
- it 'waits until text field present and then takes action' do
233
- expect {
234
- browser.a(id: 'show_textfield').click
235
- browser.text_field(id: 'textfield').set 'Foo'
236
- }.to execute_when_satisfied(min: 1)
237
- end
238
- end
239
-
240
- context 'when acting on a read only text field' do
241
- it 'waits and raises read only exception if never becomes writable' do
242
- expect { browser.text_field(id: 'writable').set 'foo' }.to wait_and_raise_object_read_only_exception
243
- end
244
-
245
- it 'waits until writable' do
246
- expect {
247
- browser.a(id: 'make-writable').click
248
- browser.text_field(id: 'writable').set 'foo'
249
- }.to execute_when_satisfied(min: 1)
250
- end
251
- end
252
-
253
- context 'when acting on a disabled button' do
254
- it 'waits and raises exception if it never becomes enabled' do
255
- expect { browser.button(id: 'btn').click }.to wait_and_raise_object_disabled_exception
256
- end
257
-
258
- it 'waits until enabled' do
259
- expect {
260
- browser.a(id: 'enable_btn').click
261
- browser.button(id: 'btn').click
262
- }.to execute_when_satisfied(min: 1)
263
- end
264
- end
265
-
266
- context 'when acting on an element with a parent' do
267
- it 'raises exception after timing out if parent never present' do
268
- element = browser.link(id: 'not_there')
269
- expect { element.element.click }.to wait_and_raise_unknown_object_exception
270
- end
271
279
 
272
- it 'raises exception after timing out when element from a collection whose parent is never present' do
273
- element = browser.link(id: 'not_there')
274
- expect { element.elements[2].click }.to wait_and_raise_unknown_object_exception
275
- end
276
-
277
- it 'does not wait for parent element to be present when querying child element' do
278
- el = browser.element(id: 'not_there').element(id: 'doesnt_matter')
279
- expect { el.present? }.to execute_when_satisfied(max: 1)
280
- end
281
- end
282
- end
283
-
284
- describe Watir::ElementCollection do
285
- before do
286
- browser.goto WatirSpec.url_for('wait.html')
287
- end
280
+ context 'when acting on Element Collection' do
281
+ describe '#wait_until' do
282
+ it 'returns collection' do
283
+ elements = browser.divs
284
+ expect(elements.wait_until(&:exist?)).to eq elements
285
+ end
288
286
 
289
- describe '#wait_until' do
290
- it 'returns collection' do
291
- elements = browser.divs
292
- expect(elements.wait_until(&:exist?)).to eq elements
293
- end
287
+ it 'times out when waiting for non-empty collection' do
288
+ expect { browser.divs.wait_until(&:empty?) }.to raise_timeout_exception
289
+ end
294
290
 
295
- it 'times out when waiting for non-empty collection' do
296
- expect { browser.divs.wait_until(&:empty?) }.to raise_timeout_exception
297
- end
291
+ it 'provides matching collection when exists' do
292
+ expect {
293
+ browser.a(id: 'add_foobar').click
294
+ browser.divs(id: 'foobar').wait_until(&:exists?)
295
+ }.to execute_when_satisfied(min: 1)
296
+ end
298
297
 
299
- it 'provides matching collection when exists' do
300
- expect {
301
- browser.a(id: 'add_foobar').click
302
- browser.divs(id: 'foobar').wait_until(&:exists?)
303
- }.to execute_when_satisfied(min: 1)
304
- end
298
+ it 'accepts self in block' do
299
+ expect {
300
+ browser.a(id: 'add_foobar').click
301
+ browser.divs.wait_until { |els| els.size == 7 }
302
+ }.to execute_when_satisfied(min: 1)
303
+ end
305
304
 
306
- it 'accepts self in block' do
307
- expect {
308
- browser.a(id: 'add_foobar').click
309
- browser.divs.wait_until { |els| els.size == 7 }
310
- }.to execute_when_satisfied(min: 1)
311
- end
305
+ it 'accepts attributes to evaluate' do
306
+ expect {
307
+ browser.a(id: 'add_foobar').click
308
+ browser.divs.wait_until(size: 7)
309
+ }.to execute_when_satisfied(min: 1)
310
+ end
311
+ end
312
312
 
313
- it 'accepts attributes to evaluate' do
314
- expect {
315
- browser.a(id: 'add_foobar').click
316
- browser.divs.wait_until(size: 7)
317
- }.to execute_when_satisfied(min: 1)
318
- end
319
- end
313
+ describe '#wait_while' do
314
+ it 'returns collection' do
315
+ elements = browser.divs
316
+ expect(elements.wait_while(&:empty?)).to eq elements
317
+ end
320
318
 
321
- describe '#wait_while' do
322
- it 'returns collection' do
323
- elements = browser.divs
324
- expect(elements.wait_while(&:empty?)).to eq elements
325
- end
319
+ it 'times out when waiting for non-empty collection' do
320
+ elements = browser.divs
321
+ expect { elements.wait_while(&:exists?) }.to raise_timeout_exception
322
+ end
326
323
 
327
- it 'times out when waiting for non-empty collection' do
328
- elements = browser.divs
329
- expect { elements.wait_while(&:exists?) }.to raise_timeout_exception
330
- end
324
+ it 'provides matching collection when exists' do
325
+ expect {
326
+ browser.a(id: 'remove_foo').click
327
+ browser.divs(id: 'foo').wait_while(&:exists?)
328
+ }.to execute_when_satisfied(min: 1)
329
+ end
331
330
 
332
- it 'provides matching collection when exists' do
333
- expect {
334
- browser.a(id: 'remove_foo').click
335
- browser.divs(id: 'foo').wait_while(&:exists?)
336
- }.to execute_when_satisfied(min: 1)
337
- end
331
+ it 'accepts self in block' do
332
+ expect {
333
+ browser.a(id: 'add_foobar').click
334
+ browser.divs.wait_while { |els| els.size == 6 }
335
+ }.to execute_when_satisfied(min: 1)
336
+ end
337
+ end
338
338
 
339
- it 'accepts self in block' do
340
- expect {
341
- browser.a(id: 'add_foobar').click
342
- browser.divs.wait_while { |els| els.size == 6 }
343
- }.to execute_when_satisfied(min: 1)
339
+ it 'waits for parent element to be present before locating' do
340
+ els = browser.element(id: /not|there/).elements(id: 'doesnt_matter')
341
+ expect { els.to_a }.to wait_and_raise_unknown_object_exception
342
+ end
344
343
  end
345
344
  end
346
-
347
- it 'waits for parent element to be present before locating' do
348
- els = browser.element(id: /not|there/).elements(id: 'doesnt_matter')
349
- expect { els.to_a }.to wait_and_raise_unknown_object_exception
350
- end
351
345
  end