watir 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,41 +2,43 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Areas' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('images.html'))
8
- end
5
+ module Watir
6
+ describe AreaCollection do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('images.html'))
9
+ end
9
10
 
10
- describe 'with selectors' do
11
- it 'returns the matching elements' do
12
- expect(browser.areas(alt: 'Tables').to_a).to eq [browser.area(alt: 'Tables')]
11
+ describe 'with selectors' do
12
+ it 'returns the matching elements' do
13
+ expect(browser.areas(alt: 'Tables').to_a).to eq [browser.area(alt: 'Tables')]
14
+ end
13
15
  end
14
- end
15
16
 
16
- describe '#length' do
17
- it 'returns the number of areas' do
18
- expect(browser.areas.length).to eq 3
17
+ describe '#length' do
18
+ it 'returns the number of areas' do
19
+ expect(browser.areas.length).to eq 3
20
+ end
19
21
  end
20
- end
21
22
 
22
- describe '#[]' do
23
- it 'returns the area at the given index' do
24
- expect(browser.areas[0].id).to eq('NCE')
23
+ describe '#[]' do
24
+ it 'returns the area at the given index' do
25
+ expect(browser.areas[0].id).to eq('NCE')
26
+ end
25
27
  end
26
- end
27
28
 
28
- describe '#each' do
29
- it 'iterates through areas correctly' do
30
- count = 0
29
+ describe '#each' do
30
+ it 'iterates through areas correctly' do
31
+ count = 0
31
32
 
32
- browser.areas.each_with_index do |a, index|
33
- expect(a.id).to eq browser.area(index: index).id
34
- expect(a.title).to eq browser.area(index: index).title
33
+ browser.areas.each_with_index do |a, index|
34
+ expect(a.id).to eq browser.area(index: index).id
35
+ expect(a.title).to eq browser.area(index: index).title
35
36
 
36
- count += 1
37
- end
37
+ count += 1
38
+ end
38
39
 
39
- expect(count).to be > 0
40
+ expect(count).to be > 0
41
+ end
40
42
  end
41
43
  end
42
44
  end
@@ -2,262 +2,264 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Button' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
8
- end
9
-
10
- # Exists method
11
- describe '#exists?' do
12
- it 'returns true if the button exists (tag = :input)' do
13
- expect(browser.button(id: 'new_user_submit')).to exist
14
- expect(browser.button(id: /new_user_submit/)).to exist
15
- expect(browser.button(name: 'new_user_reset')).to exist
16
- expect(browser.button(name: /new_user_reset/)).to exist
17
- expect(browser.button(value: 'Button')).to exist
18
- expect(browser.button(value: /Button/)).to exist
19
- expect(browser.button(src: 'images/button.png')).to exist
20
- expect(browser.button(src: /button\.png/)).to exist
21
- expect(browser.button(text: 'Button 2')).to exist
22
- expect(browser.button(text: /Button 2/)).to exist
23
- expect(browser.button(class: 'image')).to exist
24
- expect(browser.button(class: /image/)).to exist
25
- expect(browser.button(index: 0)).to exist
26
- expect(browser.button(xpath: "//input[@id='new_user_submit']")).to exist
27
- expect(browser.button(alt: 'Create a new user')).to exist
28
- expect(browser.button(alt: /Create a/)).to exist
29
- end
30
-
31
- it 'returns true if the button exists (tag = :button)' do
32
- expect(browser.button(name: 'new_user_button_2')).to exist
33
- expect(browser.button(name: /new_user_button_2/)).to exist
34
- expect(browser.button(value: 'button_2')).to exist
35
- expect(browser.button(value: /button_2/)).to exist
36
- expect(browser.button(text: 'Button 2')).to exist
37
- expect(browser.button(text: /Button 2/)).to exist
38
- expect(browser.button(value: 'Button 2')).to exist
39
- expect(browser.button(value: /Button 2/)).to exist
40
- expect(browser.button(value: 'Button 4 With Child Text')).to exist
41
- expect(browser.button(value: /Button 4 With Child Text/)).to exist
42
- end
43
-
44
- it 'returns the first button if given no args' do
45
- expect(browser.button).to exist
46
- end
47
-
48
- it 'returns true for element with upper case type' do
49
- expect(browser.button(id: 'new_user_button_preview')).to exist
50
- end
51
-
52
- it "returns false if the button doesn't exist" do
53
- expect(browser.button(id: 'no_such_id')).to_not exist
54
- expect(browser.button(id: /no_such_id/)).to_not exist
55
- expect(browser.button(name: 'no_such_name')).to_not exist
56
- expect(browser.button(name: /no_such_name/)).to_not exist
57
- expect(browser.button(value: 'no_such_value')).to_not exist
58
- expect(browser.button(value: /no_such_value/)).to_not exist
59
- expect(browser.button(src: 'no_such_src')).to_not exist
60
- expect(browser.button(src: /no_such_src/)).to_not exist
61
- expect(browser.button(text: 'no_such_text')).to_not exist
62
- expect(browser.button(text: /no_such_text/)).to_not exist
63
- expect(browser.button(class: 'no_such_class')).to_not exist
64
- expect(browser.button(class: /no_such_class/)).to_not exist
65
- expect(browser.button(index: 1337)).to_not exist
66
- expect(browser.button(xpath: "//input[@id='no_such_id']")).to_not exist
67
- end
68
-
69
- it 'checks the tag name and type attribute when locating by xpath' do
70
- expect(browser.button(xpath: "//input[@type='text']")).to_not exist
71
- expect(browser.button(xpath: "//input[@type='button']")).to exist
72
- end
73
-
74
- it 'matches the specific type when locating by type' do
75
- expect(browser.button(type: 'button').type).to eq 'button'
76
- expect(browser.button(type: 'reset').type).to eq 'reset'
77
- expect(browser.button(type: 'submit').type).to eq 'submit'
78
- expect(browser.button(type: 'image').type).to eq 'image'
79
- end
80
-
81
- it 'matches valid input types when type is boolean' do
82
- expect(browser.buttons(type: false).map(&:tag_name)).to all eq('button')
83
-
84
- input_buttons = browser.buttons(type: true).select { |e| e.tag_name == 'input' }
85
- expect(input_buttons.map(&:type).uniq).to match_array(Watir::Button::VALID_TYPES)
86
- end
87
-
88
- it "raises TypeError when 'what' argument is invalid" do
89
- expect { browser.button(id: 3.14).exists? }.to raise_error(TypeError)
90
- end
91
- end
92
-
93
- # Attribute methods
94
- describe '#id' do
95
- it 'returns the id if the button exists' do
96
- expect(browser.button(index: 0).id).to eq 'new_user_submit'
97
- expect(browser.button(index: 1).id).to eq 'new_user_reset'
98
- expect(browser.button(index: 2).id).to eq 'new_user_button'
99
- end
100
-
101
- it 'raises UnknownObjectException if button does not exist' do
102
- expect { browser.button(index: 1337).id }.to raise_unknown_object_exception
103
- end
104
- end
105
-
106
- describe '#name' do
107
- it 'returns the name if button exists' do
108
- expect(browser.button(index: 0).name).to eq 'new_user_submit'
109
- expect(browser.button(index: 1).name).to eq 'new_user_reset'
110
- expect(browser.button(index: 2).name).to eq 'new_user_button'
111
- end
112
-
113
- it 'raises UnknownObjectException if the button does not exist' do
114
- expect { browser.button(name: 'no_such_name').name }.to raise_unknown_object_exception
115
- end
116
- end
117
-
118
- describe '#src' do
119
- it 'returns the src attribute for the button image' do
120
- # varies between browsers
121
- expect(browser.button(name: 'new_user_image').src).to include('images/button.png')
122
- end
123
-
124
- it 'raises UnknownObjectException if the button does not exist' do
125
- expect { browser.button(name: 'no_such_name').src }.to raise_unknown_object_exception
126
- end
127
- end
128
-
129
- describe '#style' do
130
- it 'returns the style attribute if the button exists' do
131
- expect(browser.button(id: 'delete_user_submit').style).to include 'border: 4px solid red;'
132
- end
133
-
134
- it "returns an empty string if the element exists and the attribute doesn't exist" do
135
- expect(browser.button(id: 'new_user_submit').style).to eq ''
136
- end
137
-
138
- it 'raises UnknownObjectException if the button does not exist' do
139
- expect { browser.button(name: 'no_such_name').style }.to raise_unknown_object_exception
140
- end
141
- end
142
-
143
- describe '#title' do
144
- it 'returns the title of the button' do
145
- expect(browser.button(index: 0).title).to eq 'Submit the form'
146
- end
147
-
148
- it 'returns an empty string for button without title' do
149
- expect(browser.button(index: 1).title).to eq ''
150
- end
151
- end
152
-
153
- describe '#type' do
154
- it 'returns the type if button exists' do
155
- expect(browser.button(index: 0).type).to eq 'submit'
156
- expect(browser.button(index: 1).type).to eq 'reset'
157
- expect(browser.button(index: 2).type).to eq 'button'
158
- end
159
-
160
- it 'raises UnknownObjectException if button does not exist' do
161
- expect { browser.button(name: 'no_such_name').type }.to raise_unknown_object_exception
162
- end
163
- end
164
-
165
- describe '#value' do
166
- it 'returns the value if button exists' do
167
- expect(browser.button(index: 0).value).to eq 'Submit'
168
- expect(browser.button(index: 1).value).to eq 'Reset'
169
- expect(browser.button(index: 2).value).to eq 'Button'
170
- end
171
-
172
- it 'raises UnknownObjectException if button does not exist' do
173
- expect { browser.button(name: 'no_such_name').value }.to raise_unknown_object_exception
174
- end
175
- end
176
-
177
- describe '#text' do
178
- it 'returns the text of an input button' do
179
- expect(browser.button(index: 0).text).to eq 'Submit'
180
- expect(browser.button(index: 1).text).to eq 'Reset'
181
- expect(browser.button(index: 2).text).to eq 'Button'
182
- expect(browser.button(index: 3).text).to eq 'Preview'
183
- end
184
-
185
- it 'returns the text of a button element' do
186
- expect(browser.button(name: 'new_user_button_2').text).to eq 'Button 2'
187
- end
188
-
189
- it 'raises UnknownObjectException if the element does not exist' do
190
- expect { browser.button(id: 'no_such_id').text }.to raise_unknown_object_exception
191
- end
192
- end
193
-
194
- describe '#respond_to?' do
195
- it 'returns true for all attribute methods' do
196
- expect(browser.button(index: 0)).to respond_to(:class_name)
197
- expect(browser.button(index: 0)).to respond_to(:id)
198
- expect(browser.button(index: 0)).to respond_to(:name)
199
- expect(browser.button(index: 0)).to respond_to(:src)
200
- expect(browser.button(index: 0)).to respond_to(:style)
201
- expect(browser.button(index: 0)).to respond_to(:title)
202
- expect(browser.button(index: 0)).to respond_to(:type)
203
- expect(browser.button(index: 0)).to respond_to(:value)
204
- end
205
- end
206
-
207
- # Access methods
208
- describe '#enabled?' do
209
- it 'returns true if the button is enabled' do
210
- expect(browser.button(name: 'new_user_submit')).to be_enabled
211
- end
212
-
213
- it 'returns false if the button is disabled' do
214
- expect(browser.button(name: 'new_user_submit_disabled')).to_not be_enabled
215
- end
216
-
217
- it "raises UnknownObjectException if the button doesn't exist" do
218
- expect { browser.button(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
219
- end
220
-
221
- it 'raises ObjectDisabledException if disabled button is clicked' do
222
- expect { browser.button(name: 'new_user_submit_disabled').click }.to raise_object_disabled_exception
223
- end
224
- end
225
-
226
- describe '#disabled?' do
227
- it 'returns false when button is enabled' do
228
- expect(browser.button(name: 'new_user_submit')).to_not be_disabled
229
- end
230
-
231
- it 'returns true when button is disabled' do
232
- expect(browser.button(name: 'new_user_submit_disabled')).to be_disabled
233
- end
234
-
235
- it 'raises UnknownObjectException if button does not exist' do
236
- expect { browser.button(name: 'no_such_name').disabled? }.to raise_unknown_object_exception
237
- end
238
- end
239
-
240
- # Manipulation methods
241
- describe '#click' do
242
- it 'clicks the button if it exists' do
5
+ module Watir
6
+ describe Button do
7
+ before do
243
8
  browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
244
- browser.button(id: 'delete_user_submit').click
245
- browser.wait_while(url: /forms_with_input_elements\.html$/)
246
- expect(browser.text).to include('Semantic table')
247
9
  end
248
10
 
249
- it 'fires events' do
250
- browser.button(id: 'new_user_button').click
251
- expect(browser.button(id: 'new_user_button').value).to eq 'new_value_set_by_onclick_event'
252
- end
11
+ # Exists method
12
+ describe '#exists?' do
13
+ it 'returns true if the button exists (tag = :input)' do
14
+ expect(browser.button(id: 'new_user_submit')).to exist
15
+ expect(browser.button(id: /new_user_submit/)).to exist
16
+ expect(browser.button(name: 'new_user_reset')).to exist
17
+ expect(browser.button(name: /new_user_reset/)).to exist
18
+ expect(browser.button(value: 'Button')).to exist
19
+ expect(browser.button(value: /Button/)).to exist
20
+ expect(browser.button(src: 'images/button.png')).to exist
21
+ expect(browser.button(src: /button\.png/)).to exist
22
+ expect(browser.button(text: 'Button 2')).to exist
23
+ expect(browser.button(text: /Button 2/)).to exist
24
+ expect(browser.button(class: 'image')).to exist
25
+ expect(browser.button(class: /image/)).to exist
26
+ expect(browser.button(index: 0)).to exist
27
+ expect(browser.button(xpath: "//input[@id='new_user_submit']")).to exist
28
+ expect(browser.button(alt: 'Create a new user')).to exist
29
+ expect(browser.button(alt: /Create a/)).to exist
30
+ end
31
+
32
+ it 'returns true if the button exists (tag = :button)' do
33
+ expect(browser.button(name: 'new_user_button_2')).to exist
34
+ expect(browser.button(name: /new_user_button_2/)).to exist
35
+ expect(browser.button(value: 'button_2')).to exist
36
+ expect(browser.button(value: /button_2/)).to exist
37
+ expect(browser.button(text: 'Button 2')).to exist
38
+ expect(browser.button(text: /Button 2/)).to exist
39
+ expect(browser.button(value: 'Button 2')).to exist
40
+ expect(browser.button(value: /Button 2/)).to exist
41
+ expect(browser.button(value: 'Button 4 With Child Text')).to exist
42
+ expect(browser.button(value: /Button 4 With Child Text/)).to exist
43
+ end
44
+
45
+ it 'returns the first button if given no args' do
46
+ expect(browser.button).to exist
47
+ end
48
+
49
+ it 'returns true for element with upper case type' do
50
+ expect(browser.button(id: 'new_user_button_preview')).to exist
51
+ end
52
+
53
+ it "returns false if the button doesn't exist" do
54
+ expect(browser.button(id: 'no_such_id')).not_to exist
55
+ expect(browser.button(id: /no_such_id/)).not_to exist
56
+ expect(browser.button(name: 'no_such_name')).not_to exist
57
+ expect(browser.button(name: /no_such_name/)).not_to exist
58
+ expect(browser.button(value: 'no_such_value')).not_to exist
59
+ expect(browser.button(value: /no_such_value/)).not_to exist
60
+ expect(browser.button(src: 'no_such_src')).not_to exist
61
+ expect(browser.button(src: /no_such_src/)).not_to exist
62
+ expect(browser.button(text: 'no_such_text')).not_to exist
63
+ expect(browser.button(text: /no_such_text/)).not_to exist
64
+ expect(browser.button(class: 'no_such_class')).not_to exist
65
+ expect(browser.button(class: /no_such_class/)).not_to exist
66
+ expect(browser.button(index: 1337)).not_to exist
67
+ expect(browser.button(xpath: "//input[@id='no_such_id']")).not_to exist
68
+ end
69
+
70
+ it 'checks the tag name and type attribute when locating by xpath' do
71
+ expect(browser.button(xpath: "//input[@type='text']")).not_to exist
72
+ expect(browser.button(xpath: "//input[@type='button']")).to exist
73
+ end
74
+
75
+ it 'matches the specific type when locating by type' do
76
+ expect(browser.button(type: 'button').type).to eq 'button'
77
+ expect(browser.button(type: 'reset').type).to eq 'reset'
78
+ expect(browser.button(type: 'submit').type).to eq 'submit'
79
+ expect(browser.button(type: 'image').type).to eq 'image'
80
+ end
81
+
82
+ it 'matches valid input types when type is boolean' do
83
+ expect(browser.buttons(type: false).map(&:tag_name)).to all eq('button')
84
+
85
+ input_buttons = browser.buttons(type: true).select { |e| e.tag_name == 'input' }
86
+ expect(input_buttons.map(&:type).uniq).to match_array(Button::VALID_TYPES)
87
+ end
88
+
89
+ it "raises TypeError when 'what' argument is invalid" do
90
+ expect { browser.button(id: 3.14).exists? }.to raise_error(TypeError)
91
+ end
92
+ end
93
+
94
+ # Attribute methods
95
+ describe '#id' do
96
+ it 'returns the id if the button exists' do
97
+ expect(browser.button(index: 0).id).to eq 'new_user_submit'
98
+ expect(browser.button(index: 1).id).to eq 'new_user_reset'
99
+ expect(browser.button(index: 2).id).to eq 'new_user_button'
100
+ end
101
+
102
+ it 'raises UnknownObjectException if button does not exist' do
103
+ expect { browser.button(index: 1337).id }.to raise_unknown_object_exception
104
+ end
105
+ end
106
+
107
+ describe '#name' do
108
+ it 'returns the name if button exists' do
109
+ expect(browser.button(index: 0).name).to eq 'new_user_submit'
110
+ expect(browser.button(index: 1).name).to eq 'new_user_reset'
111
+ expect(browser.button(index: 2).name).to eq 'new_user_button'
112
+ end
113
+
114
+ it 'raises UnknownObjectException if the button does not exist' do
115
+ expect { browser.button(name: 'no_such_name').name }.to raise_unknown_object_exception
116
+ end
117
+ end
118
+
119
+ describe '#src' do
120
+ it 'returns the src attribute for the button image' do
121
+ # varies between browsers
122
+ expect(browser.button(name: 'new_user_image').src).to include('images/button.png')
123
+ end
124
+
125
+ it 'raises UnknownObjectException if the button does not exist' do
126
+ expect { browser.button(name: 'no_such_name').src }.to raise_unknown_object_exception
127
+ end
128
+ end
129
+
130
+ describe '#style' do
131
+ it 'returns the style attribute if the button exists' do
132
+ expect(browser.button(id: 'delete_user_submit').style).to include 'border: 4px solid red;'
133
+ end
134
+
135
+ it "returns an empty string if the element exists and the attribute doesn't exist" do
136
+ expect(browser.button(id: 'new_user_submit').style).to eq ''
137
+ end
138
+
139
+ it 'raises UnknownObjectException if the button does not exist' do
140
+ expect { browser.button(name: 'no_such_name').style }.to raise_unknown_object_exception
141
+ end
142
+ end
143
+
144
+ describe '#title' do
145
+ it 'returns the title of the button' do
146
+ expect(browser.button(index: 0).title).to eq 'Submit the form'
147
+ end
148
+
149
+ it 'returns an empty string for button without title' do
150
+ expect(browser.button(index: 1).title).to eq ''
151
+ end
152
+ end
153
+
154
+ describe '#type' do
155
+ it 'returns the type if button exists' do
156
+ expect(browser.button(index: 0).type).to eq 'submit'
157
+ expect(browser.button(index: 1).type).to eq 'reset'
158
+ expect(browser.button(index: 2).type).to eq 'button'
159
+ end
160
+
161
+ it 'raises UnknownObjectException if button does not exist' do
162
+ expect { browser.button(name: 'no_such_name').type }.to raise_unknown_object_exception
163
+ end
164
+ end
165
+
166
+ describe '#value' do
167
+ it 'returns the value if button exists' do
168
+ expect(browser.button(index: 0).value).to eq 'Submit'
169
+ expect(browser.button(index: 1).value).to eq 'Reset'
170
+ expect(browser.button(index: 2).value).to eq 'Button'
171
+ end
172
+
173
+ it 'raises UnknownObjectException if button does not exist' do
174
+ expect { browser.button(name: 'no_such_name').value }.to raise_unknown_object_exception
175
+ end
176
+ end
177
+
178
+ describe '#text' do
179
+ it 'returns the text of an input button' do
180
+ expect(browser.button(index: 0).text).to eq 'Submit'
181
+ expect(browser.button(index: 1).text).to eq 'Reset'
182
+ expect(browser.button(index: 2).text).to eq 'Button'
183
+ expect(browser.button(index: 3).text).to eq 'Preview'
184
+ end
185
+
186
+ it 'returns the text of a button element' do
187
+ expect(browser.button(name: 'new_user_button_2').text).to eq 'Button 2'
188
+ end
189
+
190
+ it 'raises UnknownObjectException if the element does not exist' do
191
+ expect { browser.button(id: 'no_such_id').text }.to raise_unknown_object_exception
192
+ end
193
+ end
194
+
195
+ describe '#respond_to?' do
196
+ it 'returns true for all attribute methods' do
197
+ expect(browser.button(index: 0)).to respond_to(:class_name)
198
+ expect(browser.button(index: 0)).to respond_to(:id)
199
+ expect(browser.button(index: 0)).to respond_to(:name)
200
+ expect(browser.button(index: 0)).to respond_to(:src)
201
+ expect(browser.button(index: 0)).to respond_to(:style)
202
+ expect(browser.button(index: 0)).to respond_to(:title)
203
+ expect(browser.button(index: 0)).to respond_to(:type)
204
+ expect(browser.button(index: 0)).to respond_to(:value)
205
+ end
206
+ end
207
+
208
+ # Access methods
209
+ describe '#enabled?' do
210
+ it 'returns true if the button is enabled' do
211
+ expect(browser.button(name: 'new_user_submit')).to be_enabled
212
+ end
253
213
 
254
- it "raises UnknownObjectException when clicking a button that doesn't exist" do
255
- expect { browser.button(value: 'no_such_value').click }.to raise_unknown_object_exception
256
- expect { browser.button(id: 'no_such_id').click }.to raise_unknown_object_exception
257
- end
214
+ it 'returns false if the button is disabled' do
215
+ expect(browser.button(name: 'new_user_submit_disabled')).not_to be_enabled
216
+ end
258
217
 
259
- it 'raises ObjectDisabledException when clicking a disabled button' do
260
- expect { browser.button(value: 'Disabled').click }.to raise_object_disabled_exception
218
+ it "raises UnknownObjectException if the button doesn't exist" do
219
+ expect { browser.button(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
220
+ end
221
+
222
+ it 'raises ObjectDisabledException if disabled button is clicked' do
223
+ expect { browser.button(name: 'new_user_submit_disabled').click }.to raise_object_disabled_exception
224
+ end
225
+ end
226
+
227
+ describe '#disabled?' do
228
+ it 'returns false when button is enabled' do
229
+ expect(browser.button(name: 'new_user_submit')).not_to be_disabled
230
+ end
231
+
232
+ it 'returns true when button is disabled' do
233
+ expect(browser.button(name: 'new_user_submit_disabled')).to be_disabled
234
+ end
235
+
236
+ it 'raises UnknownObjectException if button does not exist' do
237
+ expect { browser.button(name: 'no_such_name').disabled? }.to raise_unknown_object_exception
238
+ end
239
+ end
240
+
241
+ # Manipulation methods
242
+ describe '#click' do
243
+ it 'clicks the button if it exists' do
244
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
245
+ browser.button(id: 'delete_user_submit').click
246
+ browser.wait_while(url: /forms_with_input_elements\.html$/)
247
+ expect(browser.text).to include('Semantic table')
248
+ end
249
+
250
+ it 'fires events' do
251
+ browser.button(id: 'new_user_button').click
252
+ expect(browser.button(id: 'new_user_button').value).to eq 'new_value_set_by_onclick_event'
253
+ end
254
+
255
+ it "raises UnknownObjectException when clicking a button that doesn't exist" do
256
+ expect { browser.button(value: 'no_such_value').click }.to raise_unknown_object_exception
257
+ expect { browser.button(id: 'no_such_id').click }.to raise_unknown_object_exception
258
+ end
259
+
260
+ it 'raises ObjectDisabledException when clicking a disabled button' do
261
+ expect { browser.button(value: 'Disabled').click }.to raise_object_disabled_exception
262
+ end
261
263
  end
262
264
  end
263
265
  end
@@ -2,54 +2,56 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Buttons' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
8
- end
5
+ module Watir
6
+ describe ButtonCollection do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
9
+ end
9
10
 
10
- describe 'with selectors' do
11
- it 'returns the matching elements' do
12
- expect(browser.buttons(name: 'new_user_button').to_a).to eq [browser.button(name: 'new_user_button')]
11
+ describe 'with selectors' do
12
+ it 'returns the matching elements' do
13
+ expect(browser.buttons(name: 'new_user_button').to_a).to eq [browser.button(name: 'new_user_button')]
14
+ end
13
15
  end
14
- end
15
16
 
16
- describe '#length' do
17
- it 'returns the number of buttons' do
18
- expect(browser.buttons.length).to eq 11
17
+ describe '#length' do
18
+ it 'returns the number of buttons' do
19
+ expect(browser.buttons.length).to eq 11
20
+ end
19
21
  end
20
- end
21
22
 
22
- describe '#[]' do
23
- it 'returns the button at the given index' do
24
- expect(browser.buttons[0].title).to eq 'Submit the form'
23
+ describe '#[]' do
24
+ it 'returns the button at the given index' do
25
+ expect(browser.buttons[0].title).to eq 'Submit the form'
26
+ end
25
27
  end
26
- end
27
28
 
28
- describe '#first' do
29
- it 'returns the first element in the collection' do
30
- expect(browser.buttons.first.value).to eq browser.buttons[0].value
29
+ describe '#first' do
30
+ it 'returns the first element in the collection' do
31
+ expect(browser.buttons.first.value).to eq browser.buttons[0].value
32
+ end
31
33
  end
32
- end
33
34
 
34
- describe '#last' do
35
- it 'returns the last element in the collection' do
36
- expect(browser.buttons.last.value).to eq browser.buttons[-1].value
35
+ describe '#last' do
36
+ it 'returns the last element in the collection' do
37
+ expect(browser.buttons.last.value).to eq browser.buttons[-1].value
38
+ end
37
39
  end
38
- end
39
40
 
40
- describe '#each' do
41
- it 'iterates through buttons correctly' do
42
- count = 0
41
+ describe '#each' do
42
+ it 'iterates through buttons correctly' do
43
+ count = 0
43
44
 
44
- browser.buttons.each_with_index do |b, index|
45
- expect(b.name).to eq browser.button(index: index).name
46
- expect(b.id).to eq browser.button(index: index).id
47
- expect(b.value).to eq browser.button(index: index).value
45
+ browser.buttons.each_with_index do |b, index|
46
+ expect(b.name).to eq browser.button(index: index).name
47
+ expect(b.id).to eq browser.button(index: index).id
48
+ expect(b.value).to eq browser.button(index: index).value
48
49
 
49
- count += 1
50
- end
50
+ count += 1
51
+ end
51
52
 
52
- expect(count).to be > 0
53
+ expect(count).to be > 0
54
+ end
53
55
  end
54
56
  end
55
57
  end