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,201 +2,203 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Browser::AfterHooks' do
6
- describe '#add' do
7
- it 'raises ArgumentError when not given any arguments' do
8
- expect { browser.after_hooks.add }.to raise_error(ArgumentError)
9
- end
5
+ module Watir
6
+ describe AfterHooks do
7
+ describe '#add' do
8
+ it 'raises ArgumentError when not given any arguments' do
9
+ expect { browser.after_hooks.add }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ it 'runs the given proc on each page load' do
13
+ proc = proc { |browser| @output = browser.text }
10
14
 
11
- it 'runs the given proc on each page load' do
12
- proc = proc { |browser| @output = browser.text }
15
+ begin
16
+ browser.alert.dismiss if browser.alert.exists?
17
+ browser.after_hooks.add(proc)
18
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
13
19
 
14
- begin
15
- browser.alert.dismiss if browser.alert.exists?
16
- browser.after_hooks.add(proc)
20
+ expect(@output).to include('Dubito, ergo cogito, ergo sum')
21
+ ensure
22
+ browser.after_hooks.delete(proc)
23
+ end
24
+ end
25
+
26
+ it 'runs the given block on each page load' do
27
+ browser.after_hooks.add { |browser| @output = browser.text }
17
28
  browser.goto(WatirSpec.url_for('non_control_elements.html'))
18
29
 
19
30
  expect(@output).to include('Dubito, ergo cogito, ergo sum')
20
31
  ensure
21
- browser.after_hooks.delete(proc)
32
+ browser.after_hooks.delete browser.after_hooks[0]
22
33
  end
23
34
  end
24
35
 
25
- it 'runs the given block on each page load' do
26
- browser.after_hooks.add { |browser| @output = browser.text }
27
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
36
+ describe '#delete' do
37
+ it 'removes a previously added after_hook' do
38
+ after_hook = ->(browser) { @output = browser.text }
28
39
 
29
- expect(@output).to include('Dubito, ergo cogito, ergo sum')
30
- ensure
31
- browser.after_hooks.delete browser.after_hooks[0]
32
- end
33
- end
34
-
35
- describe '#delete' do
36
- it 'removes a previously added after_hook' do
37
- after_hook = ->(browser) { @output = browser.text }
38
-
39
- browser.after_hooks.add(after_hook)
40
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
41
- expect(@output).to include('Dubito, ergo cogito, ergo sum')
40
+ browser.after_hooks.add(after_hook)
41
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
42
+ expect(@output).to include('Dubito, ergo cogito, ergo sum')
42
43
 
43
- browser.after_hooks.delete(after_hook)
44
- browser.goto(WatirSpec.url_for('definition_lists.html'))
45
- expect(@output).to_not include('definition_lists')
44
+ browser.after_hooks.delete(after_hook)
45
+ browser.goto(WatirSpec.url_for('definition_lists.html'))
46
+ expect(@output).not_to include('definition_lists')
47
+ end
46
48
  end
47
- end
48
49
 
49
- describe '#run' do
50
- before { @yield = nil }
50
+ describe '#run' do
51
+ before { @yield = nil }
51
52
 
52
- after(:each) do
53
- browser.after_hooks.delete @page_after_hook
54
- end
53
+ after do
54
+ browser.after_hooks.delete @page_after_hook
55
+ end
55
56
 
56
- it 'runs after_hooks after Browser#goto' do
57
- @page_after_hook = proc { @yield = browser.title == 'The font element' }
58
- browser.after_hooks.add @page_after_hook
59
- browser.goto WatirSpec.url_for('font.html')
60
- expect(@yield).to be true
61
- end
57
+ it 'runs after_hooks after Browser#goto' do
58
+ @page_after_hook = proc { @yield = browser.title == 'The font element' }
59
+ browser.after_hooks.add @page_after_hook
60
+ browser.goto WatirSpec.url_for('font.html')
61
+ expect(@yield).to be true
62
+ end
62
63
 
63
- it 'runs after_hooks after Browser#refresh' do
64
- browser.goto WatirSpec.url_for('font.html')
65
- @page_after_hook = proc do
66
- @yield = browser.title == 'The font element'
64
+ it 'runs after_hooks after Browser#refresh' do
65
+ browser.goto WatirSpec.url_for('font.html')
66
+ @page_after_hook = proc do
67
+ @yield = browser.title == 'The font element'
68
+ end
69
+ browser.after_hooks.add @page_after_hook
70
+ browser.refresh
71
+ expect(@yield).to be true
67
72
  end
68
- browser.after_hooks.add @page_after_hook
69
- browser.refresh
70
- expect(@yield).to be true
71
- end
72
73
 
73
- it 'runs after_hooks after Element#click' do
74
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
75
- @page_after_hook = proc do
76
- browser.wait_until { |b| b.title == 'Forms with input elements' }
77
- @yield = true
74
+ it 'runs after_hooks after Element#click' do
75
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
76
+ @page_after_hook = proc do
77
+ browser.wait_until { |b| b.title == 'Forms with input elements' }
78
+ @yield = true
79
+ end
80
+ browser.after_hooks.add @page_after_hook
81
+ browser.link(index: 2).click
82
+ expect(@yield).to be true
78
83
  end
79
- browser.after_hooks.add @page_after_hook
80
- browser.link(index: 2).click
81
- expect(@yield).to be true
82
- end
83
84
 
84
- it 'runs after_hooks after Element#submit' do
85
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
86
- @page_after_hook = proc { @yield = browser.div(id: 'messages').text == 'submit' }
87
- browser.after_hooks.add @page_after_hook
88
- browser.form(id: 'new_user').submit
89
- expect(@yield).to be true
90
- end
85
+ it 'runs after_hooks after Element#submit' do
86
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
87
+ @page_after_hook = proc { @yield = browser.div(id: 'messages').text == 'submit' }
88
+ browser.after_hooks.add @page_after_hook
89
+ browser.form(id: 'new_user').submit
90
+ expect(@yield).to be true
91
+ end
91
92
 
92
- it 'runs after_hooks after Element#double_click' do
93
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
94
- @page_after_hook = proc { @yield = browser.title == 'Non-control elements' }
95
- browser.after_hooks.add @page_after_hook
96
- div = browser.div(id: 'html_test')
97
- div.double_click
98
- expect(@yield).to be true
99
- end
93
+ it 'runs after_hooks after Element#double_click' do
94
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
95
+ @page_after_hook = proc { @yield = browser.title == 'Non-control elements' }
96
+ browser.after_hooks.add @page_after_hook
97
+ div = browser.div(id: 'html_test')
98
+ div.double_click
99
+ expect(@yield).to be true
100
+ end
100
101
 
101
- it 'runs after_hooks after Element#right_click' do
102
- browser.goto(WatirSpec.url_for('right_click.html'))
103
- @page_after_hook = proc { @yield = browser.title == 'Right Click Test' }
104
- browser.after_hooks.add @page_after_hook
105
- div = browser.div(id: 'click')
106
- div.right_click
107
- expect(@yield).to be true
108
- end
102
+ it 'runs after_hooks after Element#right_click' do
103
+ browser.goto(WatirSpec.url_for('right_click.html'))
104
+ @page_after_hook = proc { @yield = browser.title == 'Right Click Test' }
105
+ browser.after_hooks.add @page_after_hook
106
+ div = browser.div(id: 'click')
107
+ div.right_click
108
+ expect(@yield).to be true
109
+ end
109
110
 
110
- it 'runs after_hooks after Alert#ok' do
111
- browser.goto(WatirSpec.url_for('alerts.html'))
112
- @page_after_hook = proc { @yield = browser.title == 'Alerts' }
113
- browser.after_hooks.add @page_after_hook
114
- browser.after_hooks.without { browser.button(id: 'alert').click }
115
- browser.alert.ok
116
- expect(@yield).to be true
117
- end
111
+ it 'runs after_hooks after Alert#ok' do
112
+ browser.goto(WatirSpec.url_for('alerts.html'))
113
+ @page_after_hook = proc { @yield = browser.title == 'Alerts' }
114
+ browser.after_hooks.add @page_after_hook
115
+ browser.after_hooks.without { browser.button(id: 'alert').click }
116
+ browser.alert.ok
117
+ expect(@yield).to be true
118
+ end
118
119
 
119
- it 'runs after_hooks after Alert#close' do
120
- browser.goto(WatirSpec.url_for('alerts.html'))
121
- @page_after_hook = proc { @yield = browser.title == 'Alerts' }
122
- browser.after_hooks.add @page_after_hook
123
- browser.after_hooks.without { browser.button(id: 'alert').click }
124
- browser.alert.close
125
- expect(@yield).to be true
126
- end
120
+ it 'runs after_hooks after Alert#close' do
121
+ browser.goto(WatirSpec.url_for('alerts.html'))
122
+ @page_after_hook = proc { @yield = browser.title == 'Alerts' }
123
+ browser.after_hooks.add @page_after_hook
124
+ browser.after_hooks.without { browser.button(id: 'alert').click }
125
+ browser.alert.close
126
+ expect(@yield).to be true
127
+ end
127
128
 
128
- it 'does not run error checks with alert present' do
129
- browser.goto WatirSpec.url_for('alerts.html')
129
+ it 'does not run error checks with alert present' do
130
+ browser.goto WatirSpec.url_for('alerts.html')
130
131
 
131
- @page_after_hook = proc { @yield = browser.title == 'Alerts' }
132
- browser.after_hooks.add @page_after_hook
132
+ @page_after_hook = proc { @yield = browser.title == 'Alerts' }
133
+ browser.after_hooks.add @page_after_hook
133
134
 
134
- browser.button(id: 'alert').click
135
- expect(@yield).to be_nil
135
+ browser.button(id: 'alert').click
136
+ expect(@yield).to be_nil
136
137
 
137
- browser.alert.ok
138
- expect(@yield).to eq true
139
- end
138
+ browser.alert.ok
139
+ expect(@yield).to be true
140
+ end
140
141
 
141
- it 'does not raise error when running error checks using #after_hooks#without with alert present' do
142
- url = WatirSpec.url_for('alerts.html')
143
- @page_after_hook = proc { browser.url }
144
- browser.after_hooks.add @page_after_hook
145
- browser.goto url
146
- expect { browser.after_hooks.without { browser.button(id: 'alert').click } }.to_not raise_error
147
- browser.alert.ok
148
- end
142
+ it 'does not raise error when running error checks using #after_hooks#without with alert present' do
143
+ url = WatirSpec.url_for('alerts.html')
144
+ @page_after_hook = proc { browser.url }
145
+ browser.after_hooks.add @page_after_hook
146
+ browser.goto url
147
+ expect { browser.after_hooks.without { browser.button(id: 'alert').click } }.not_to raise_error
148
+ browser.alert.ok
149
+ end
149
150
 
150
- it 'does not raise error if no error checks are defined with alert present' do
151
- url = WatirSpec.url_for('alerts.html')
152
- @page_after_hook = proc { browser.url }
153
- browser.after_hooks.add @page_after_hook
154
- browser.goto url
155
- browser.after_hooks.delete @page_after_hook
156
- expect { browser.button(id: 'alert').click }.to_not raise_error
157
- browser.alert.ok
158
- end
151
+ it 'does not raise error if no error checks are defined with alert present' do
152
+ url = WatirSpec.url_for('alerts.html')
153
+ @page_after_hook = proc { browser.url }
154
+ browser.after_hooks.add @page_after_hook
155
+ browser.goto url
156
+ browser.after_hooks.delete @page_after_hook
157
+ expect { browser.button(id: 'alert').click }.not_to raise_error
158
+ browser.alert.ok
159
+ end
159
160
 
160
- it 'does not raise error when running error checks on closed window',
161
- exclude: [{browser: :safari,
162
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
163
- {browser: :firefox,
164
- platform: :windows,
165
- reason: 'https://github.com/mozilla/geckodriver/issues/1847'},
166
- {browser: :ie,
167
- reason: 'IE and windows do not play well together'}] do
168
- url = WatirSpec.url_for('window_switching.html')
169
- @page_after_hook = proc { browser.url }
170
- browser.after_hooks.add @page_after_hook
171
- browser.goto url
172
- browser.a(id: 'open').click
173
-
174
- window = browser.window(title: 'closeable window')
175
- window.use
176
- expect { browser.a(id: 'close').click }.to_not raise_error
177
- browser.original_window.use
161
+ it 'does not raise error when running error checks on closed window',
162
+ exclude: [{browser: :safari,
163
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
164
+ {browser: :firefox,
165
+ platform: :windows,
166
+ reason: 'https://github.com/mozilla/geckodriver/issues/1847'},
167
+ {browser: :ie,
168
+ reason: 'IE and windows do not play well together'}] do
169
+ url = WatirSpec.url_for('window_switching.html')
170
+ @page_after_hook = proc { browser.url }
171
+ browser.after_hooks.add @page_after_hook
172
+ browser.goto url
173
+ browser.a(id: 'open').click
174
+
175
+ window = browser.window(title: 'closeable window')
176
+ window.use
177
+ expect { browser.a(id: 'close').click }.not_to raise_error
178
+ browser.original_window.use
179
+ end
178
180
  end
179
- end
180
181
 
181
- describe '#length' do
182
- it 'provides the number of after hooks' do
183
- hook = proc { true }
184
- begin
185
- 4.times { browser.after_hooks.add(hook) }
186
- expect(browser.after_hooks.length).to eq 4
187
- ensure
188
- 4.times { browser.after_hooks.delete(hook) }
182
+ describe '#length' do
183
+ it 'provides the number of after hooks' do
184
+ hook = proc { true }
185
+ begin
186
+ 4.times { browser.after_hooks.add(hook) }
187
+ expect(browser.after_hooks.length).to eq 4
188
+ ensure
189
+ 4.times { browser.after_hooks.delete(hook) }
190
+ end
189
191
  end
190
192
  end
191
- end
192
193
 
193
- describe '#[]' do
194
- it 'returns the after hook at the provided index' do
195
- hook1 = proc { true }
196
- hook2 = proc { false }
197
- browser.after_hooks.add(hook1)
198
- browser.after_hooks.add(hook2)
199
- expect(browser.after_hooks[1]).to eq hook2
194
+ describe '#[]' do
195
+ it 'returns the after hook at the provided index' do
196
+ hook1 = proc { true }
197
+ hook2 = proc { false }
198
+ browser.after_hooks.add(hook1)
199
+ browser.after_hooks.add(hook2)
200
+ expect(browser.after_hooks[1]).to eq hook2
201
+ end
200
202
  end
201
203
  end
202
204
  end
@@ -2,84 +2,87 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Alert API' do
6
- before do
7
- browser.goto WatirSpec.url_for('alerts.html')
8
- end
9
-
10
- after do
11
- browser.alert.ok if browser.alert.exists?
12
- end
5
+ module Watir
6
+ describe Alert do
7
+ before do
8
+ browser.goto WatirSpec.url_for('alerts.html')
9
+ end
13
10
 
14
- context 'Waits' do
15
- context 'when acting on an alert' do
16
- it 'raises exception after timing out' do
17
- expect { browser.alert.text }.to wait_and_raise_unknown_object_exception
18
- end
11
+ after do
12
+ browser.alert.ok if browser.alert.exists?
19
13
  end
20
- end
21
14
 
22
- context 'alert' do
23
- describe '#text' do
24
- it 'returns text of alert' do
25
- browser.button(id: 'alert').click
26
- expect(browser.alert.text).to include('ok')
15
+ describe 'Waits' do
16
+ context 'when acting on an alert' do
17
+ it 'raises exception after timing out' do
18
+ expect { browser.alert.text }.to wait_and_raise_unknown_object_exception
19
+ end
27
20
  end
28
21
  end
29
22
 
30
- describe '#exists?' do
31
- it 'returns false if alert is not present' do
32
- expect(browser.alert).to_not exist
23
+ describe 'alert' do
24
+ describe '#text' do
25
+ it 'returns text of alert' do
26
+ browser.button(id: 'alert').click
27
+ expect(browser.alert.text).to include('ok')
28
+ end
33
29
  end
34
30
 
35
- it 'returns true if alert is present' do
36
- browser.button(id: 'alert').click
37
- browser.wait_until(timeout: 10) { browser.alert.exists? }
31
+ describe '#exists?' do
32
+ it 'returns false if alert is not present' do
33
+ expect(browser.alert).not_to exist
34
+ end
35
+
36
+ it 'returns true if alert is present' do
37
+ browser.button(id: 'alert').click
38
+ browser.wait_until(timeout: 10) { browser.alert.exists? }
39
+ expect(browser.alert.exist?).to be true
40
+ end
38
41
  end
39
- end
40
42
 
41
- describe '#ok' do
42
- it 'closes alert' do
43
- browser.button(id: 'alert').click
44
- browser.alert.ok
45
- expect(browser.alert).to_not exist
43
+ describe '#ok' do
44
+ it 'closes alert' do
45
+ browser.button(id: 'alert').click
46
+ browser.alert.ok
47
+ expect(browser.alert).not_to exist
48
+ end
46
49
  end
47
- end
48
50
 
49
- describe '#close' do
50
- it 'closes alert' do
51
- browser.button(id: 'alert').click
52
- browser.alert.close
53
- expect(browser.alert).to_not exist
51
+ describe '#close' do
52
+ it 'closes alert' do
53
+ browser.button(id: 'alert').click
54
+ browser.alert.close
55
+ expect(browser.alert).not_to exist
56
+ end
54
57
  end
55
58
  end
56
- end
57
59
 
58
- context 'confirm' do
59
- describe '#ok' do
60
- it 'accepts confirm' do
61
- browser.button(id: 'confirm').click
62
- browser.alert.ok
63
- expect(browser.button(id: 'confirm').value).to eq 'true'
60
+ describe 'confirm' do
61
+ describe '#ok' do
62
+ it 'accepts confirm' do
63
+ browser.button(id: 'confirm').click
64
+ browser.alert.ok
65
+ expect(browser.button(id: 'confirm').value).to eq 'true'
66
+ end
64
67
  end
65
- end
66
68
 
67
- describe '#close' do
68
- it 'cancels confirm' do
69
- browser.button(id: 'confirm').click
70
- browser.alert.close
71
- expect(browser.button(id: 'confirm').value).to eq 'false'
69
+ describe '#close' do
70
+ it 'cancels confirm' do
71
+ browser.button(id: 'confirm').click
72
+ browser.alert.close
73
+ expect(browser.button(id: 'confirm').value).to eq 'false'
74
+ end
72
75
  end
73
76
  end
74
- end
75
77
 
76
- context 'prompt' do
77
- describe '#set' do
78
- it 'enters text to prompt' do
79
- browser.button(id: 'prompt').click
80
- browser.alert.set 'My Name'
81
- browser.alert.ok
82
- expect(browser.button(id: 'prompt').value).to eq 'My Name'
78
+ describe 'prompt' do
79
+ describe '#set' do
80
+ it 'enters text to prompt' do
81
+ browser.button(id: 'prompt').click
82
+ browser.alert.set 'My Name'
83
+ browser.alert.ok
84
+ expect(browser.button(id: 'prompt').value).to eq 'My Name'
85
+ end
83
86
  end
84
87
  end
85
88
  end