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,227 +2,231 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Div' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
8
- end
9
-
10
- describe '#exists?' do
11
- it 'returns true if the element exists' do
12
- expect(browser.div(id: 'header')).to exist
13
- expect(browser.div(id: /header/)).to exist
14
- expect(browser.div(title: 'Header and primary navigation')).to exist
15
- expect(browser.div(title: /Header and primary navigation/)).to exist
16
- expect(browser.div(text: 'Not shownNot hidden')).to exist
17
- expect(browser.div(text: /Not hidden/)).to exist
18
- expect(browser.div(class: 'profile')).to exist
19
- expect(browser.div(class: /profile/)).to exist
20
- expect(browser.div(index: 0)).to exist
21
- expect(browser.div(xpath: "//div[@id='header']")).to exist
22
- expect(browser.div(custom_attribute: 'custom')).to exist
23
- expect(browser.div(custom_attribute: /custom/)).to exist
24
- expect(browser.div(text: /some visible/)).to exist
25
- expect(browser.div(text: /some (visible|Jeff)/)).to exist
26
- expect(browser.div(text: /none visible/)).to exist
27
- end
28
-
29
- it 'returns the first div if given no args' do
30
- expect(browser.div).to exist
31
- end
32
-
33
- it 'returns false if the element does not exist' do
34
- expect(browser.div(id: 'no_such_id')).to_not exist
35
- expect(browser.div(id: /no_such_id/)).to_not exist
36
- expect(browser.div(title: 'no_such_title')).to_not exist
37
- expect(browser.div(title: /no_such_title/)).to_not exist
38
- expect(browser.div(text: 'no_such_text')).to_not exist
39
- expect(browser.div(text: /no_such_text/)).to_not exist
40
- expect(browser.div(class: 'no_such_class')).to_not exist
41
- expect(browser.div(class: /no_such_class/)).to_not exist
42
- expect(browser.div(text: /some visible some hidden/)).to exist
43
- expect(browser.div(index: 1337)).to_not exist
44
- expect(browser.div(xpath: "//div[@id='no_such_id']")).to_not exist
45
- end
46
-
47
- it "raises TypeError when 'what' argument is invalid" do
48
- expect { browser.div(id: 3.14).exists? }.to raise_error(TypeError)
49
- end
50
- end
51
-
52
- # Attribute methods
53
- describe '#id' do
54
- it 'returns the id attribute if the element exists' do
55
- expect(browser.div(index: 1).id).to eq 'outer_container'
56
- end
57
-
58
- it "returns an empty string if the element exists, but the attribute doesn't" do
59
- expect(browser.div(index: 0).id).to eq ''
60
- end
61
-
62
- it 'raises UnknownObjectException if the element does not exist' do
63
- expect { browser.div(id: 'no_such_id').id }.to raise_unknown_object_exception
64
- expect { browser.div(title: 'no_such_id').id }.to raise_unknown_object_exception
65
- expect { browser.div(index: 1337).id }.to raise_unknown_object_exception
66
- end
67
-
68
- it 'should take all conditions into account when locating by id' do
69
- browser.goto WatirSpec.url_for 'multiple_ids.html'
70
- expect(browser.div(id: 'multiple', class: 'bar').class_name).to eq 'bar'
71
- end
72
-
73
- it 'should find the id with the correct tag name' do
74
- browser.goto WatirSpec.url_for 'multiple_ids.html'
75
- expect(browser.span(id: 'multiple').class_name).to eq 'foobar'
76
- end
77
- end
78
-
79
- describe '#style' do
80
- it 'returns the style attribute if the element exists' do
81
- expect(browser.div(id: 'best_language').style).to eq 'color: red; text-decoration: underline; cursor: pointer;'
82
- end
83
-
84
- it "returns an empty string if the element exists but the attribute doesn't" do
85
- expect(browser.div(id: 'promo').style).to eq ''
86
- end
87
-
88
- it 'raises UnknownObjectException if the element does not exist' do
89
- expect { browser.div(id: 'no_such_id').style }.to raise_unknown_object_exception
90
- end
91
- end
92
-
93
- describe '#text' do
94
- it 'returns the text of the div' do
95
- expect(browser.div(id: 'footer').text.strip).to eq 'This is a footer.'
96
- expect(browser.div(title: 'Closing remarks').text.strip).to eq 'This is a footer.'
97
- expect(browser.div(xpath: "//div[@id='footer']").text.strip).to eq 'This is a footer.'
98
- end
99
-
100
- it 'returns an empty string if the element exists but contains no text' do
101
- expect(browser.div(index: 0).text.strip).to eq ''
102
- end
103
-
104
- it 'returns an empty string if the div is hidden',
105
- except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
106
- expect(browser.div(id: 'hidden').text).to eq ''
107
- end
108
-
109
- it 'raises UnknownObjectException if the element does not exist' do
110
- expect { browser.div(id: 'no_such_id').text }.to raise_unknown_object_exception
111
- expect { browser.div(title: 'no_such_title').text }.to raise_unknown_object_exception
112
- expect { browser.div(index: 1337).text }.to raise_unknown_object_exception
113
- expect { browser.div(xpath: "//div[@id='no_such_id']").text }.to raise_unknown_object_exception
114
- end
115
- end
116
-
117
- describe 'custom methods' do
118
- it 'returns the custom attribute if the element exists' do
119
- expect(browser.div(custom_attribute: 'custom').attribute_value('custom-attribute')).to eq 'custom'
120
- end
121
- end
122
-
123
- describe '#respond_to?' do
124
- it 'returns true for all attribute methods' do
125
- expect(browser.div(index: 0)).to respond_to(:class_name)
126
- expect(browser.div(index: 0)).to respond_to(:id)
127
- expect(browser.div(index: 0)).to respond_to(:style)
128
- expect(browser.div(index: 0)).to respond_to(:text)
129
- end
130
- end
131
-
132
- # Manipulation methods
133
- describe '#click' do
134
- it 'fires events when clicked' do
135
- expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
136
-
137
- div = browser.div(id: 'best_language')
138
- div.scroll.to
139
- div.click
140
- expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
141
- end
142
-
143
- it 'raises UnknownObjectException if the element does not exist' do
144
- expect { browser.div(id: 'no_such_id').click }.to raise_unknown_object_exception
145
- expect { browser.div(title: 'no_such_title').click }.to raise_unknown_object_exception
146
- expect { browser.div(index: 1337).click }.to raise_unknown_object_exception
147
- expect { browser.div(xpath: "//div[@id='no_such_id']").click }.to raise_unknown_object_exception
148
- end
149
-
150
- it 'includes custom message if element with a custom attribute does not exist' do
151
- message = /Watir treated \["custom_attribute"\] as a non-HTML compliant attribute, ensure that was intended/
152
- expect { browser.div(custom_attribute: 'not_there').click }.to raise_unknown_object_exception(message)
153
- end
154
- end
155
-
156
- describe '#click!' do
157
- it 'fires events when clicked' do
158
- expect(browser.div(id: 'best_language').text).to_not eq 'Ruby!'
159
- browser.div(id: 'best_language').click!
160
- expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
161
- end
162
-
163
- it 'raises UnknownObjectException if the element does not exist' do
164
- expect { browser.div(id: 'no_such_id').click! }.to raise_unknown_object_exception
165
- expect { browser.div(title: 'no_such_title').click! }.to raise_unknown_object_exception
166
- expect { browser.div(index: 1337).click! }.to raise_unknown_object_exception
167
- expect { browser.div(xpath: "//div[@id='no_such_id']").click! }.to raise_unknown_object_exception
168
- end
169
- end
170
-
171
- describe '#double_click',
172
- except: {browser: :safari, reason: 'command correctly received, but action not taken'} do
173
- it 'fires the ondblclick event' do
174
- div = browser.div(id: 'html_test')
175
- div.double_click
176
- expect(messages).to include('double clicked')
177
- end
178
-
179
- it 'fires the ondblclick event with specified scroll position' do
180
- div = browser.div(id: 'html_test')
181
- div.double_click(scroll_to: :center)
182
- expect(messages).to include('double clicked')
183
- end
184
- end
185
-
186
- describe '#double_click!' do
187
- it 'fires the ondblclick event' do
188
- browser.div(id: 'html_test').double_click!
189
- expect(messages).to include('double clicked')
190
- end
191
- end
192
-
193
- describe '#right_click' do
194
- it 'fires the oncontextmenu event' do
195
- browser.goto(WatirSpec.url_for('right_click.html'))
196
- browser.div(id: 'click').right_click
197
- expect(messages.first).to eq 'right-clicked'
198
- end
199
-
200
- it 'accepts modifiers', except: {browser: :ie} do
201
- browser.goto(WatirSpec.url_for('right_click.html'))
202
- browser.div(id: 'click-logger').right_click(:control, :alt)
203
- expect(event_log.first).to eq('control=true alt=true')
204
- end
205
-
206
- it 'accepts modifiers with scroll position', except: {browser: :ie} do
207
- browser.goto(WatirSpec.url_for('right_click.html'))
208
- browser.div(id: 'click-logger').right_click(:control, :alt, scroll_to: :center)
209
- expect(event_log.first).to eq('control=true alt=true')
210
- end
211
-
212
- it 'scrolls' do
213
- browser.del(class: 'footer').double_click
214
- end
215
- end
216
-
217
- describe '#html' do
218
- it 'returns the HTML of the element' do
219
- html = browser.div(id: 'footer').html.downcase
220
- expect(html).to include('id="footer"')
221
- expect(html).to include('title="closing remarks"')
222
- expect(html).to include('class="profile"')
223
-
224
- expect(html).to_not include('<div id="content">')
225
- expect(html).to_not include('</body>')
5
+ module Watir
6
+ describe Div do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
9
+ end
10
+
11
+ describe '#exists?' do
12
+ it 'returns true if the element exists' do
13
+ expect(browser.div(id: 'header')).to exist
14
+ expect(browser.div(id: /header/)).to exist
15
+ expect(browser.div(title: 'Header and primary navigation')).to exist
16
+ expect(browser.div(title: /Header and primary navigation/)).to exist
17
+ expect(browser.div(text: 'Not shownNot hidden')).to exist
18
+ expect(browser.div(text: /Not hidden/)).to exist
19
+ expect(browser.div(class: 'profile')).to exist
20
+ expect(browser.div(class: /profile/)).to exist
21
+ expect(browser.div(index: 0)).to exist
22
+ expect(browser.div(xpath: "//div[@id='header']")).to exist
23
+ expect(browser.div(custom_attribute: 'custom')).to exist
24
+ expect(browser.div(custom_attribute: /custom/)).to exist
25
+ expect(browser.div(text: /some visible/)).to exist
26
+ expect(browser.div(text: /some (visible|Jeff)/)).to exist
27
+ expect(browser.div(text: /none visible/)).to exist
28
+ end
29
+
30
+ it 'returns the first div if given no args' do
31
+ expect(browser.div).to exist
32
+ end
33
+
34
+ it 'returns false if the element does not exist' do
35
+ expect(browser.div(id: 'no_such_id')).not_to exist
36
+ expect(browser.div(id: /no_such_id/)).not_to exist
37
+ expect(browser.div(title: 'no_such_title')).not_to exist
38
+ expect(browser.div(title: /no_such_title/)).not_to exist
39
+ expect(browser.div(text: 'no_such_text')).not_to exist
40
+ expect(browser.div(text: /no_such_text/)).not_to exist
41
+ expect(browser.div(class: 'no_such_class')).not_to exist
42
+ expect(browser.div(class: /no_such_class/)).not_to exist
43
+ expect(browser.div(text: /some visible some hidden/)).to exist
44
+ expect(browser.div(index: 1337)).not_to exist
45
+ expect(browser.div(xpath: "//div[@id='no_such_id']")).not_to exist
46
+ end
47
+
48
+ it "raises TypeError when 'what' argument is invalid" do
49
+ expect { browser.div(id: 3.14).exists? }.to raise_error(TypeError)
50
+ end
51
+ end
52
+
53
+ # Attribute methods
54
+ describe '#id' do
55
+ it 'returns the id attribute if the element exists' do
56
+ expect(browser.div(index: 1).id).to eq 'outer_container'
57
+ end
58
+
59
+ it "returns an empty string if the element exists, but the attribute doesn't" do
60
+ expect(browser.div(index: 0).id).to eq ''
61
+ end
62
+
63
+ it 'raises UnknownObjectException if the element does not exist' do
64
+ expect { browser.div(id: 'no_such_id').id }.to raise_unknown_object_exception
65
+ expect { browser.div(title: 'no_such_id').id }.to raise_unknown_object_exception
66
+ expect { browser.div(index: 1337).id }.to raise_unknown_object_exception
67
+ end
68
+
69
+ it 'takes all conditions into account when locating by id' do
70
+ browser.goto WatirSpec.url_for 'multiple_ids.html'
71
+ expect(browser.div(id: 'multiple', class: 'bar').class_name).to eq 'bar'
72
+ end
73
+
74
+ it 'finds the id with the correct tag name' do
75
+ browser.goto WatirSpec.url_for 'multiple_ids.html'
76
+ expect(browser.span(id: 'multiple').class_name).to eq 'foobar'
77
+ end
78
+ end
79
+
80
+ describe '#style' do
81
+ it 'returns the style attribute if the element exists' do
82
+ expect(browser.div(id: 'best_language').style).to eq 'color: red; text-decoration: underline; cursor: pointer;'
83
+ end
84
+
85
+ it "returns an empty string if the element exists but the attribute doesn't" do
86
+ expect(browser.div(id: 'promo').style).to eq ''
87
+ end
88
+
89
+ it 'raises UnknownObjectException if the element does not exist' do
90
+ expect { browser.div(id: 'no_such_id').style }.to raise_unknown_object_exception
91
+ end
92
+ end
93
+
94
+ describe '#text' do
95
+ it 'returns the text of the div' do
96
+ expect(browser.div(id: 'footer').text.strip).to eq 'This is a footer.'
97
+ expect(browser.div(title: 'Closing remarks').text.strip).to eq 'This is a footer.'
98
+ expect(browser.div(xpath: "//div[@id='footer']").text.strip).to eq 'This is a footer.'
99
+ end
100
+
101
+ it 'returns an empty string if the element exists but contains no text' do
102
+ expect(browser.div(index: 0).text.strip).to eq ''
103
+ end
104
+
105
+ it 'returns an empty string if the div is hidden',
106
+ except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
107
+ expect(browser.div(id: 'hidden').text).to eq ''
108
+ end
109
+
110
+ it 'raises UnknownObjectException if the element does not exist' do
111
+ expect { browser.div(id: 'no_such_id').text }.to raise_unknown_object_exception
112
+ expect { browser.div(title: 'no_such_title').text }.to raise_unknown_object_exception
113
+ expect { browser.div(index: 1337).text }.to raise_unknown_object_exception
114
+ expect { browser.div(xpath: "//div[@id='no_such_id']").text }.to raise_unknown_object_exception
115
+ end
116
+ end
117
+
118
+ describe 'custom methods' do
119
+ it 'returns the custom attribute if the element exists' do
120
+ expect(browser.div(custom_attribute: 'custom').attribute_value('custom-attribute')).to eq 'custom'
121
+ end
122
+ end
123
+
124
+ describe '#respond_to?' do
125
+ it 'returns true for all attribute methods' do
126
+ expect(browser.div(index: 0)).to respond_to(:class_name)
127
+ expect(browser.div(index: 0)).to respond_to(:id)
128
+ expect(browser.div(index: 0)).to respond_to(:style)
129
+ expect(browser.div(index: 0)).to respond_to(:text)
130
+ end
131
+ end
132
+
133
+ # Manipulation methods
134
+ describe '#click' do
135
+ it 'fires events when clicked' do
136
+ expect(browser.div(id: 'best_language').text).not_to eq 'Ruby!'
137
+
138
+ div = browser.div(id: 'best_language')
139
+ div.scroll.to
140
+ div.click
141
+ expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
142
+ end
143
+
144
+ it 'raises UnknownObjectException if the element does not exist' do
145
+ expect { browser.div(id: 'no_such_id').click }.to raise_unknown_object_exception
146
+ expect { browser.div(title: 'no_such_title').click }.to raise_unknown_object_exception
147
+ expect { browser.div(index: 1337).click }.to raise_unknown_object_exception
148
+ expect { browser.div(xpath: "//div[@id='no_such_id']").click }.to raise_unknown_object_exception
149
+ end
150
+
151
+ it 'includes custom message if element with a custom attribute does not exist' do
152
+ message = /Watir treated \["custom_attribute"\] as a non-HTML compliant attribute, ensure that was intended/
153
+ expect { browser.div(custom_attribute: 'not_there').click }.to raise_unknown_object_exception(message)
154
+ end
155
+ end
156
+
157
+ describe '#click!' do
158
+ it 'fires events when clicked' do
159
+ expect(browser.div(id: 'best_language').text).not_to eq 'Ruby!'
160
+ browser.div(id: 'best_language').click!
161
+ expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
162
+ end
163
+
164
+ it 'raises UnknownObjectException if the element does not exist' do
165
+ expect { browser.div(id: 'no_such_id').click! }.to raise_unknown_object_exception
166
+ expect { browser.div(title: 'no_such_title').click! }.to raise_unknown_object_exception
167
+ expect { browser.div(index: 1337).click! }.to raise_unknown_object_exception
168
+ expect { browser.div(xpath: "//div[@id='no_such_id']").click! }.to raise_unknown_object_exception
169
+ end
170
+ end
171
+
172
+ describe '#double_click',
173
+ except: {browser: :safari, reason: 'command correctly received, but action not taken'} do
174
+ it 'fires the ondblclick event' do
175
+ div = browser.div(id: 'html_test')
176
+ div.double_click
177
+ expect(messages).to include('double clicked')
178
+ end
179
+
180
+ it 'fires the ondblclick event with specified scroll position' do
181
+ div = browser.div(id: 'html_test')
182
+ div.double_click(scroll_to: :center)
183
+ expect(messages).to include('double clicked')
184
+ end
185
+ end
186
+
187
+ describe '#double_click!' do
188
+ it 'fires the ondblclick event' do
189
+ browser.div(id: 'html_test').double_click!
190
+ expect(messages).to include('double clicked')
191
+ end
192
+ end
193
+
194
+ describe '#right_click' do
195
+ it 'fires the oncontextmenu event' do
196
+ browser.goto(WatirSpec.url_for('right_click.html'))
197
+ browser.div(id: 'click').right_click
198
+ expect(messages.first).to eq 'right-clicked'
199
+ end
200
+
201
+ it 'accepts modifiers', except: {browser: :ie} do
202
+ browser.goto(WatirSpec.url_for('right_click.html'))
203
+ browser.div(id: 'click-logger').right_click(:control, :alt)
204
+ expect(event_log.first).to eq('control=true alt=true')
205
+ end
206
+
207
+ it 'accepts modifiers with scroll position', except: {browser: :ie} do
208
+ browser.goto(WatirSpec.url_for('right_click.html'))
209
+ browser.div(id: 'click-logger').right_click(:control, :alt, scroll_to: :center)
210
+ expect(event_log.first).to eq('control=true alt=true')
211
+ end
212
+
213
+ it 'scrolls' do
214
+ expect {
215
+ browser.del(class: 'footer').double_click
216
+ }.not_to raise_exception
217
+ end
218
+ end
219
+
220
+ describe '#html' do
221
+ it 'returns the HTML of the element' do
222
+ html = browser.div(id: 'footer').html.downcase
223
+ expect(html).to include('id="footer"')
224
+ expect(html).to include('title="closing remarks"')
225
+ expect(html).to include('class="profile"')
226
+
227
+ expect(html).not_to include('<div id="content">')
228
+ expect(html).not_to include('</body>')
229
+ end
226
230
  end
227
231
  end
228
232
  end
@@ -2,53 +2,55 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Divs' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
8
- end
9
-
10
- describe 'with selectors' do
11
- it 'returns the matching elements' do
12
- expect(browser.divs(id: 'header').to_a).to eq [browser.div(id: 'header')]
5
+ module Watir
6
+ describe DivCollection do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
13
9
  end
14
- end
15
10
 
16
- describe '#length' do
17
- it 'returns the number of divs' do
18
- expect(browser.divs.length).to eq 20
11
+ describe 'with selectors' do
12
+ it 'returns the matching elements' do
13
+ expect(browser.divs(id: 'header').to_a).to eq [browser.div(id: 'header')]
14
+ end
19
15
  end
20
- end
21
16
 
22
- describe '#[]' do
23
- it 'returns the div at the given index' do
24
- expect(browser.divs[1].id).to eq 'outer_container'
17
+ describe '#length' do
18
+ it 'returns the number of divs' do
19
+ expect(browser.divs.length).to eq 20
20
+ end
25
21
  end
26
22
 
27
- it 'returns an array of divs with a given range of positive values' do
28
- divs = browser.divs[2..4]
29
- ids = divs.map(&:id)
30
- expect(ids).to eq %w[header promo content]
31
- end
23
+ describe '#[]' do
24
+ it 'returns the div at the given index' do
25
+ expect(browser.divs[1].id).to eq 'outer_container'
26
+ end
27
+
28
+ it 'returns an array of divs with a given range of positive values' do
29
+ divs = browser.divs[2..4]
30
+ ids = divs.map(&:id)
31
+ expect(ids).to eq %w[header promo content]
32
+ end
32
33
 
33
- it 'returns an array of divs with a given range including negative values' do
34
- divs = browser.divs[11..-7]
35
- ids = divs.map(&:id)
36
- expect(ids).to eq %w[messages ins_tag_test del_tag_test]
34
+ it 'returns an array of divs with a given range including negative values' do
35
+ divs = browser.divs[11..-7]
36
+ ids = divs.map(&:id)
37
+ expect(ids).to eq %w[messages ins_tag_test del_tag_test]
38
+ end
37
39
  end
38
- end
39
40
 
40
- describe '#each' do
41
- it 'iterates through divs correctly' do
42
- count = 0
41
+ describe '#each' do
42
+ it 'iterates through divs correctly' do
43
+ count = 0
43
44
 
44
- browser.divs.each_with_index do |d, index|
45
- expect(d.id).to eq browser.div(index: index).id
46
- expect(d.class_name).to eq browser.div(index: index).class_name
45
+ browser.divs.each_with_index do |d, index|
46
+ expect(d.id).to eq browser.div(index: index).id
47
+ expect(d.class_name).to eq browser.div(index: index).class_name
47
48
 
48
- count += 1
49
- end
49
+ count += 1
50
+ end
50
51
 
51
- expect(count).to be > 0
52
+ expect(count).to be > 0
53
+ end
52
54
  end
53
55
  end
54
56
  end