watir 7.0.0 → 7.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +29 -16
  3. data/.github/workflows/edge.yml +19 -11
  4. data/.github/workflows/firefox.yml +28 -16
  5. data/.github/workflows/ie.yml +13 -7
  6. data/.github/workflows/safari.yml +22 -11
  7. data/.github/workflows/unit.yml +31 -23
  8. data/.rubocop.yml +33 -13
  9. data/.rubocop_todo.yml +7 -26
  10. data/CHANGES.md +33 -0
  11. data/Gemfile +6 -1
  12. data/LICENSE +2 -2
  13. data/README.md +15 -11
  14. data/Rakefile +9 -7
  15. data/lib/watir/adjacent.rb +3 -1
  16. data/lib/watir/after_hooks.rb +5 -3
  17. data/lib/watir/alert.rb +2 -0
  18. data/lib/watir/aliases.rb +2 -0
  19. data/lib/watir/attribute_helper.rb +4 -2
  20. data/lib/watir/browser.rb +10 -14
  21. data/lib/watir/capabilities.rb +53 -33
  22. data/lib/watir/cell_container.rb +2 -0
  23. data/lib/watir/container.rb +2 -0
  24. data/lib/watir/cookies.rb +5 -5
  25. data/lib/watir/element_collection.rb +3 -1
  26. data/lib/watir/elements/button.rb +2 -0
  27. data/lib/watir/elements/cell.rb +2 -0
  28. data/lib/watir/elements/checkbox.rb +2 -0
  29. data/lib/watir/elements/date_field.rb +2 -0
  30. data/lib/watir/elements/date_time_field.rb +2 -0
  31. data/lib/watir/elements/dlist.rb +3 -1
  32. data/lib/watir/elements/element.rb +68 -118
  33. data/lib/watir/elements/file_field.rb +2 -0
  34. data/lib/watir/elements/font.rb +2 -0
  35. data/lib/watir/elements/form.rb +2 -0
  36. data/lib/watir/elements/hidden.rb +2 -0
  37. data/lib/watir/elements/iframe.rb +2 -0
  38. data/lib/watir/elements/image.rb +2 -0
  39. data/lib/watir/elements/input.rb +2 -0
  40. data/lib/watir/elements/link.rb +2 -0
  41. data/lib/watir/elements/list.rb +2 -0
  42. data/lib/watir/elements/option.rb +2 -0
  43. data/lib/watir/elements/radio.rb +2 -0
  44. data/lib/watir/elements/row.rb +2 -0
  45. data/lib/watir/elements/select.rb +2 -0
  46. data/lib/watir/elements/table.rb +3 -1
  47. data/lib/watir/elements/table_cell.rb +2 -0
  48. data/lib/watir/elements/table_row.rb +2 -0
  49. data/lib/watir/elements/table_section.rb +2 -0
  50. data/lib/watir/elements/text_area.rb +2 -0
  51. data/lib/watir/elements/text_field.rb +2 -0
  52. data/lib/watir/exception.rb +2 -0
  53. data/lib/watir/extensions/nokogiri.rb +2 -0
  54. data/lib/watir/generator/base/generator.rb +2 -0
  55. data/lib/watir/generator/base/idl_sorter.rb +3 -1
  56. data/lib/watir/generator/base/spec_extractor.rb +6 -4
  57. data/lib/watir/generator/base/util.rb +2 -0
  58. data/lib/watir/generator/base/visitor.rb +5 -5
  59. data/lib/watir/generator/base.rb +2 -1
  60. data/lib/watir/generator/html/generator.rb +2 -0
  61. data/lib/watir/generator/html/spec_extractor.rb +2 -0
  62. data/lib/watir/generator/html/visitor.rb +2 -0
  63. data/lib/watir/generator/html.rb +2 -0
  64. data/lib/watir/generator/svg/generator.rb +2 -0
  65. data/lib/watir/generator/svg/spec_extractor.rb +2 -0
  66. data/lib/watir/generator/svg/visitor.rb +2 -0
  67. data/lib/watir/generator/svg.rb +2 -0
  68. data/lib/watir/generator.rb +2 -0
  69. data/lib/watir/has_window.rb +3 -1
  70. data/lib/watir/http_client.rb +2 -0
  71. data/lib/watir/js_execution.rb +2 -0
  72. data/lib/watir/js_snippets/isElementInViewport.js +20 -0
  73. data/lib/watir/js_snippets.rb +2 -0
  74. data/lib/watir/locators/anchor/selector_builder.rb +5 -0
  75. data/lib/watir/locators/button/matcher.rb +2 -0
  76. data/lib/watir/locators/button/selector_builder/xpath.rb +15 -19
  77. data/lib/watir/locators/button/selector_builder.rb +2 -0
  78. data/lib/watir/locators/cell/selector_builder/xpath.rb +2 -0
  79. data/lib/watir/locators/cell/selector_builder.rb +2 -0
  80. data/lib/watir/locators/element/locator.rb +2 -0
  81. data/lib/watir/locators/element/matcher.rb +4 -1
  82. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +4 -1
  83. data/lib/watir/locators/element/selector_builder/xpath.rb +16 -15
  84. data/lib/watir/locators/element/selector_builder/xpath_support.rb +4 -2
  85. data/lib/watir/locators/element/selector_builder.rb +16 -6
  86. data/lib/watir/locators/option/matcher.rb +2 -0
  87. data/lib/watir/locators/option/selector_builder/xpath.rb +2 -0
  88. data/lib/watir/locators/option/selector_builder.rb +2 -0
  89. data/lib/watir/locators/row/selector_builder/xpath.rb +2 -0
  90. data/lib/watir/locators/row/selector_builder.rb +2 -0
  91. data/lib/watir/locators/text_area/selector_builder/xpath.rb +2 -0
  92. data/lib/watir/locators/text_area/selector_builder.rb +2 -0
  93. data/lib/watir/locators/text_field/matcher.rb +2 -4
  94. data/lib/watir/locators/text_field/selector_builder/xpath.rb +2 -0
  95. data/lib/watir/locators/text_field/selector_builder.rb +2 -0
  96. data/lib/watir/locators.rb +2 -0
  97. data/lib/watir/logger.rb +2 -0
  98. data/lib/watir/navigation.rb +3 -1
  99. data/lib/watir/radio_set.rb +2 -0
  100. data/lib/watir/row_container.rb +2 -0
  101. data/lib/watir/screenshot.rb +2 -0
  102. data/lib/watir/scroll.rb +29 -3
  103. data/lib/watir/search_context.rb +96 -0
  104. data/lib/watir/shadow_root.rb +60 -0
  105. data/lib/watir/user_editable.rb +3 -1
  106. data/lib/watir/version.rb +3 -1
  107. data/lib/watir/wait/timer.rb +3 -1
  108. data/lib/watir/wait.rb +5 -5
  109. data/lib/watir/window.rb +7 -3
  110. data/lib/watir/window_collection.rb +4 -1
  111. data/lib/watir.rb +4 -0
  112. data/lib/watirspec/guards.rb +2 -0
  113. data/lib/watirspec/implementation.rb +14 -10
  114. data/lib/watirspec/rake_tasks.rb +4 -4
  115. data/lib/watirspec/remote_server.rb +5 -3
  116. data/lib/watirspec/runner.rb +3 -1
  117. data/lib/watirspec/server/app.rb +2 -0
  118. data/lib/watirspec/server.rb +2 -0
  119. data/lib/watirspec.rb +7 -4
  120. data/spec/locator_spec_helper.rb +2 -8
  121. data/spec/spec_helper.rb +2 -0
  122. data/spec/unit/capabilities_spec.rb +561 -550
  123. data/spec/unit/element_locator_spec.rb +71 -58
  124. data/spec/unit/match_elements/button_spec.rb +58 -49
  125. data/spec/unit/match_elements/element_spec.rb +305 -309
  126. data/spec/unit/match_elements/text_field_spec.rb +78 -73
  127. data/spec/unit/selector_builder/anchor_spec.rb +41 -33
  128. data/spec/unit/selector_builder/button_spec.rb +211 -201
  129. data/spec/unit/selector_builder/cell_spec.rb +50 -42
  130. data/spec/unit/selector_builder/element_spec.rb +636 -628
  131. data/spec/unit/selector_builder/row_spec.rb +121 -104
  132. data/spec/unit/selector_builder/text_field_spec.rb +197 -182
  133. data/spec/unit/selector_builder/textarea_spec.rb +24 -14
  134. data/spec/unit/unit_helper.rb +2 -0
  135. data/spec/unit/wait_spec.rb +77 -71
  136. data/spec/watirspec/adjacent_spec.rb +251 -247
  137. data/spec/watirspec/after_hooks_spec.rb +160 -162
  138. data/spec/watirspec/alert_spec.rb +63 -58
  139. data/spec/watirspec/browser_spec.rb +411 -407
  140. data/spec/watirspec/capabilities_spec.rb +566 -0
  141. data/spec/watirspec/cookies_spec.rb +122 -118
  142. data/spec/watirspec/drag_and_drop_spec.rb +30 -14
  143. data/spec/watirspec/element_hidden_spec.rb +68 -60
  144. data/spec/watirspec/elements/area_spec.rb +51 -47
  145. data/spec/watirspec/elements/areas_spec.rb +29 -25
  146. data/spec/watirspec/elements/button_spec.rb +255 -251
  147. data/spec/watirspec/elements/buttons_spec.rb +38 -34
  148. data/spec/watirspec/elements/checkbox_spec.rb +50 -36
  149. data/spec/watirspec/elements/checkboxes_spec.rb +31 -27
  150. data/spec/watirspec/elements/collections_spec.rb +128 -119
  151. data/spec/watirspec/elements/date_field_spec.rb +187 -183
  152. data/spec/watirspec/elements/date_fields_spec.rb +31 -27
  153. data/spec/watirspec/elements/date_time_field_spec.rb +199 -195
  154. data/spec/watirspec/elements/date_time_fields_spec.rb +32 -28
  155. data/spec/watirspec/elements/dd_spec.rb +89 -85
  156. data/spec/watirspec/elements/dds_spec.rb +29 -25
  157. data/spec/watirspec/elements/del_spec.rb +108 -104
  158. data/spec/watirspec/elements/dels_spec.rb +28 -24
  159. data/spec/watirspec/elements/div_spec.rb +227 -211
  160. data/spec/watirspec/elements/divs_spec.rb +39 -35
  161. data/spec/watirspec/elements/dl_spec.rb +112 -110
  162. data/spec/watirspec/elements/dls_spec.rb +30 -26
  163. data/spec/watirspec/elements/dt_spec.rb +88 -84
  164. data/spec/watirspec/elements/dts_spec.rb +29 -25
  165. data/spec/watirspec/elements/element_spec.rb +815 -715
  166. data/spec/watirspec/elements/elements_spec.rb +42 -38
  167. data/spec/watirspec/elements/em_spec.rb +64 -60
  168. data/spec/watirspec/elements/ems_spec.rb +30 -26
  169. data/spec/watirspec/elements/filefield_spec.rb +100 -96
  170. data/spec/watirspec/elements/filefields_spec.rb +30 -26
  171. data/spec/watirspec/elements/font_spec.rb +22 -18
  172. data/spec/watirspec/elements/form_spec.rb +53 -49
  173. data/spec/watirspec/elements/forms_spec.rb +31 -27
  174. data/spec/watirspec/elements/frame_spec.rb +91 -87
  175. data/spec/watirspec/elements/frames_spec.rb +29 -25
  176. data/spec/watirspec/elements/hidden_spec.rb +81 -77
  177. data/spec/watirspec/elements/hiddens_spec.rb +30 -26
  178. data/spec/watirspec/elements/hn_spec.rb +61 -57
  179. data/spec/watirspec/elements/hns_spec.rb +28 -24
  180. data/spec/watirspec/elements/iframe_spec.rb +197 -191
  181. data/spec/watirspec/elements/iframes_spec.rb +33 -29
  182. data/spec/watirspec/elements/image_spec.rb +146 -142
  183. data/spec/watirspec/elements/images_spec.rb +28 -24
  184. data/spec/watirspec/elements/input_spec.rb +11 -7
  185. data/spec/watirspec/elements/ins_spec.rb +108 -104
  186. data/spec/watirspec/elements/inses_spec.rb +28 -24
  187. data/spec/watirspec/elements/label_spec.rb +58 -54
  188. data/spec/watirspec/elements/labels_spec.rb +28 -24
  189. data/spec/watirspec/elements/li_spec.rb +76 -72
  190. data/spec/watirspec/elements/link_spec.rb +175 -179
  191. data/spec/watirspec/elements/links_spec.rb +47 -43
  192. data/spec/watirspec/elements/lis_spec.rb +29 -25
  193. data/spec/watirspec/elements/list_spec.rb +46 -42
  194. data/spec/watirspec/elements/map_spec.rb +59 -55
  195. data/spec/watirspec/elements/maps_spec.rb +29 -25
  196. data/spec/watirspec/elements/meta_spec.rb +18 -14
  197. data/spec/watirspec/elements/metas_spec.rb +28 -24
  198. data/spec/watirspec/elements/ol_spec.rb +58 -65
  199. data/spec/watirspec/elements/ols_spec.rb +28 -24
  200. data/spec/watirspec/elements/option_spec.rb +93 -89
  201. data/spec/watirspec/elements/p_spec.rb +79 -75
  202. data/spec/watirspec/elements/pre_spec.rb +77 -73
  203. data/spec/watirspec/elements/pres_spec.rb +28 -24
  204. data/spec/watirspec/elements/ps_spec.rb +28 -24
  205. data/spec/watirspec/elements/radio_spec.rb +253 -249
  206. data/spec/watirspec/elements/radios_spec.rb +30 -26
  207. data/spec/watirspec/elements/select_list_spec.rb +539 -522
  208. data/spec/watirspec/elements/select_lists_spec.rb +34 -30
  209. data/spec/watirspec/elements/span_spec.rb +114 -110
  210. data/spec/watirspec/elements/spans_spec.rb +28 -24
  211. data/spec/watirspec/elements/strong_spec.rb +60 -58
  212. data/spec/watirspec/elements/strongs_spec.rb +30 -26
  213. data/spec/watirspec/elements/table_spec.rb +194 -139
  214. data/spec/watirspec/elements/tables_spec.rb +30 -26
  215. data/spec/watirspec/elements/tbody_spec.rb +71 -67
  216. data/spec/watirspec/elements/tbodys_spec.rb +42 -38
  217. data/spec/watirspec/elements/td_spec.rb +68 -64
  218. data/spec/watirspec/elements/tds_spec.rb +43 -39
  219. data/spec/watirspec/elements/text_field_spec.rb +208 -204
  220. data/spec/watirspec/elements/text_fields_spec.rb +32 -28
  221. data/spec/watirspec/elements/textarea_spec.rb +22 -18
  222. data/spec/watirspec/elements/textareas_spec.rb +20 -16
  223. data/spec/watirspec/elements/tfoot_spec.rb +67 -63
  224. data/spec/watirspec/elements/tfoots_spec.rb +44 -40
  225. data/spec/watirspec/elements/thead_spec.rb +67 -63
  226. data/spec/watirspec/elements/theads_spec.rb +44 -40
  227. data/spec/watirspec/elements/tr_spec.rb +50 -46
  228. data/spec/watirspec/elements/trs_spec.rb +44 -40
  229. data/spec/watirspec/elements/ul_spec.rb +58 -54
  230. data/spec/watirspec/elements/uls_spec.rb +28 -24
  231. data/spec/watirspec/html/child_frame.html +29 -0
  232. data/spec/watirspec/html/class_locator.html +2 -0
  233. data/spec/watirspec/html/scroll.html +8 -25
  234. data/spec/watirspec/html/scroll_nested.html +17 -0
  235. data/spec/watirspec/html/scroll_nested_offscreen.html +18 -0
  236. data/spec/watirspec/html/shadow_dom.html +28 -0
  237. data/spec/watirspec/html/sticky_elements.html +10 -0
  238. data/spec/watirspec/radio_set_spec.rb +271 -267
  239. data/spec/watirspec/screenshot_spec.rb +22 -18
  240. data/spec/watirspec/scroll_spec.rb +179 -77
  241. data/spec/watirspec/shadow_root_spec.rb +106 -0
  242. data/spec/watirspec/support/rspec_matchers.rb +35 -32
  243. data/spec/watirspec/user_editable_spec.rb +202 -198
  244. data/spec/watirspec/wait_spec.rb +291 -295
  245. data/spec/watirspec/window_switching_spec.rb +426 -428
  246. data/spec/watirspec_helper.rb +25 -42
  247. data/support/doctest_helper.rb +2 -0
  248. data/support/version_differ.rb +2 -0
  249. data/watir.gemspec +14 -10
  250. metadata +91 -240
  251. data/.github/actions/enable-safari/action.yml +0 -11
  252. data/.github/actions/install-chrome/action.yml +0 -12
  253. data/.github/actions/setup-linux/action.yml +0 -8
  254. data/lib/watir-webdriver.rb +0 -2
  255. data/spec/watirspec/attributes_spec.rb +0 -16
  256. data/spec/watirspec/elements/table_nesting_spec.rb +0 -49
  257. data/spec/watirspec/html/hover.html +0 -12
  258. data/spec/watirspec/special_chars_spec.rb +0 -21
@@ -1,683 +1,700 @@
1
- require 'watirspec_helper'
2
-
3
- describe 'SelectList' do
4
- before :each do
5
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
- # Exists method
9
- describe '#exists?' do
10
- it 'returns true if the select list exists' do
11
- expect(browser.select_list(id: 'new_user_country')).to exist
12
- expect(browser.select_list(id: /new_user_country/)).to exist
13
- expect(browser.select_list(name: 'new_user_country')).to exist
14
- expect(browser.select_list(name: /new_user_country/)).to exist
15
- expect(browser.select_list(class: 'country')).to exist
16
- expect(browser.select_list(class: /country/)).to exist
17
- expect(browser.select_list(index: 0)).to exist
18
- expect(browser.select_list(xpath: "//select[@id='new_user_country']")).to exist
19
- end
20
-
21
- it 'returns the first select if given no args' do
22
- expect(browser.select_list).to exist
23
- end
3
+ require 'watirspec_helper'
24
4
 
25
- it "returns false if the select list doesn't exist" do
26
- expect(browser.select_list(id: 'no_such_id')).to_not exist
27
- expect(browser.select_list(id: /no_such_id/)).to_not exist
28
- expect(browser.select_list(name: 'no_such_name')).to_not exist
29
- expect(browser.select_list(name: /no_such_name/)).to_not exist
30
- expect(browser.select_list(value: 'no_such_value')).to_not exist
31
- expect(browser.select_list(value: /no_such_value/)).to_not exist
32
- expect(browser.select_list(text: 'no_such_text')).to_not exist
33
- expect(browser.select_list(text: /no_such_text/)).to_not exist
34
- expect(browser.select_list(class: 'no_such_class')).to_not exist
35
- expect(browser.select_list(class: /no_such_class/)).to_not exist
36
- expect(browser.select_list(index: 1337)).to_not exist
37
- expect(browser.select_list(xpath: "//select[@id='no_such_id']")).to_not exist
5
+ module Watir
6
+ describe Select do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
38
9
  end
39
10
 
40
- it "raises TypeError when 'what' argument is invalid" do
41
- expect { browser.select_list(id: 3.14).exists? }.to raise_error(TypeError)
42
- end
43
- end
11
+ # Exists method
12
+ describe '#exists?' do
13
+ it 'returns true if the select list exists' do
14
+ expect(browser.select_list(id: 'new_user_country')).to exist
15
+ expect(browser.select_list(id: /new_user_country/)).to exist
16
+ expect(browser.select_list(name: 'new_user_country')).to exist
17
+ expect(browser.select_list(name: /new_user_country/)).to exist
18
+ expect(browser.select_list(class: 'country')).to exist
19
+ expect(browser.select_list(class: /country/)).to exist
20
+ expect(browser.select_list(index: 0)).to exist
21
+ expect(browser.select_list(xpath: "//select[@id='new_user_country']")).to exist
22
+ end
44
23
 
45
- # Attribute methods
46
- describe '#id' do
47
- it 'returns the id of the element' do
48
- expect(browser.select_list(index: 0).id).to eq 'new_user_country'
49
- end
24
+ it 'returns the first select if given no args' do
25
+ expect(browser.select_list).to exist
26
+ end
50
27
 
51
- it "raises UnknownObjectException if the select list doesn't exist" do
52
- expect { browser.select_list(index: 1337).id }.to raise_unknown_object_exception
53
- end
54
- end
28
+ it "returns false if the select list doesn't exist" do
29
+ expect(browser.select_list(id: 'no_such_id')).not_to exist
30
+ expect(browser.select_list(id: /no_such_id/)).not_to exist
31
+ expect(browser.select_list(name: 'no_such_name')).not_to exist
32
+ expect(browser.select_list(name: /no_such_name/)).not_to exist
33
+ expect(browser.select_list(value: 'no_such_value')).not_to exist
34
+ expect(browser.select_list(value: /no_such_value/)).not_to exist
35
+ expect(browser.select_list(text: 'no_such_text')).not_to exist
36
+ expect(browser.select_list(text: /no_such_text/)).not_to exist
37
+ expect(browser.select_list(class: 'no_such_class')).not_to exist
38
+ expect(browser.select_list(class: /no_such_class/)).not_to exist
39
+ expect(browser.select_list(index: 1337)).not_to exist
40
+ expect(browser.select_list(xpath: "//select[@id='no_such_id']")).not_to exist
41
+ end
55
42
 
56
- describe '#name' do
57
- it 'returns the name of the element' do
58
- expect(browser.select_list(index: 0).name).to eq 'new_user_country'
43
+ it "raises TypeError when 'what' argument is invalid" do
44
+ expect { browser.select_list(id: 3.14).exists? }.to raise_error(TypeError)
45
+ end
59
46
  end
60
47
 
61
- it "raises UnknownObjectException if the select list doesn't exist" do
62
- expect { browser.select_list(index: 1337).name }.to raise_unknown_object_exception
63
- end
64
- end
48
+ # Attribute methods
49
+ describe '#id' do
50
+ it 'returns the id of the element' do
51
+ expect(browser.select_list(index: 0).id).to eq 'new_user_country'
52
+ end
65
53
 
66
- describe '#multiple?' do
67
- it 'knows whether the select list allows multiple selections' do
68
- expect(browser.select_list(index: 0)).to_not be_multiple
69
- expect(browser.select_list(index: 1)).to be_multiple
54
+ it "raises UnknownObjectException if the select list doesn't exist" do
55
+ expect { browser.select_list(index: 1337).id }.to raise_unknown_object_exception
56
+ end
70
57
  end
71
58
 
72
- it "raises UnknownObjectException if the select list doesn't exist" do
73
- expect { browser.select_list(index: 1337).multiple? }.to raise_unknown_object_exception
74
- end
75
- end
59
+ describe '#name' do
60
+ it 'returns the name of the element' do
61
+ expect(browser.select_list(index: 0).name).to eq 'new_user_country'
62
+ end
76
63
 
77
- describe '#value' do
78
- it 'returns the value of the selected option' do
79
- expect(browser.select_list(index: 0).value).to eq '2'
80
- browser.select_list(index: 0).select(/Sweden/)
81
- expect(browser.select_list(index: 0).value).to eq '3'
64
+ it "raises UnknownObjectException if the select list doesn't exist" do
65
+ expect { browser.select_list(index: 1337).name }.to raise_unknown_object_exception
66
+ end
82
67
  end
83
68
 
84
- it 'returns the value of the selected options' do
85
- browser.select_list(name: 'new_user_languages').select('1')
86
- expect(browser.select_list(name: 'new_user_languages').value).to eq '1'
87
- browser.select_list(name: 'new_user_languages').clear
88
- browser.select_list(name: 'new_user_languages').select('NO')
89
- expect(browser.select_list(name: 'new_user_languages').value).to eq '3'
90
- end
69
+ describe '#multiple?' do
70
+ it 'knows whether the select list allows multiple selections' do
71
+ expect(browser.select_list(index: 0)).not_to be_multiple
72
+ expect(browser.select_list(index: 1)).to be_multiple
73
+ end
91
74
 
92
- it 'returns null when no values selected' do
93
- browser.select_list(name: 'new_user_languages').clear
94
- expect(browser.select_list(name: 'new_user_languages').value).to be_nil
75
+ it "raises UnknownObjectException if the select list doesn't exist" do
76
+ expect { browser.select_list(index: 1337).multiple? }.to raise_unknown_object_exception
77
+ end
95
78
  end
96
79
 
97
- it "raises UnknownObjectException if the select list doesn't exist" do
98
- expect { browser.select_list(index: 1337).value }.to raise_unknown_object_exception
99
- end
100
- end
80
+ describe '#value' do
81
+ it 'returns the value of the selected option' do
82
+ expect(browser.select_list(index: 0).value).to eq '2'
83
+ browser.select_list(index: 0).select(/Sweden/)
84
+ expect(browser.select_list(index: 0).value).to eq '3'
85
+ end
101
86
 
102
- describe '#text' do
103
- it 'returns the text of the selected option' do
104
- expect(browser.select_list(index: 0).text).to eq 'Norway'
105
- browser.select_list(index: 0).select(/Sweden/)
106
- expect(browser.select_list(index: 0).text).to eq 'Sweden'
107
- end
87
+ it 'returns the value of the selected options' do
88
+ browser.select_list(name: 'new_user_languages').select('1')
89
+ expect(browser.select_list(name: 'new_user_languages').value).to eq '1'
90
+ browser.select_list(name: 'new_user_languages').clear
91
+ browser.select_list(name: 'new_user_languages').select('NO')
92
+ expect(browser.select_list(name: 'new_user_languages').value).to eq '3'
93
+ end
108
94
 
109
- it "raises UnknownObjectException if the select list doesn't exist" do
110
- expect { browser.select_list(index: 1337).text }.to raise_unknown_object_exception
111
- end
112
- end
95
+ it 'returns null when no values selected' do
96
+ browser.select_list(name: 'new_user_languages').clear
97
+ expect(browser.select_list(name: 'new_user_languages').value).to be_nil
98
+ end
113
99
 
114
- describe '#respond_to?' do
115
- it 'returns true for all attribute methods' do
116
- expect(browser.select_list(index: 0)).to respond_to(:class_name)
117
- expect(browser.select_list(index: 0)).to respond_to(:id)
118
- expect(browser.select_list(index: 0)).to respond_to(:name)
119
- expect(browser.select_list(index: 0)).to respond_to(:value)
100
+ it "raises UnknownObjectException if the select list doesn't exist" do
101
+ expect { browser.select_list(index: 1337).value }.to raise_unknown_object_exception
102
+ end
120
103
  end
121
- end
122
104
 
123
- # Access methods
124
- describe '#enabled?' do
125
- it 'returns true if the select list is enabled' do
126
- expect(browser.select_list(name: 'new_user_country')).to be_enabled
127
- end
105
+ describe '#text' do
106
+ it 'returns the text of the selected option' do
107
+ expect(browser.select_list(index: 0).text).to eq 'Norway'
108
+ browser.select_list(index: 0).select(/Sweden/)
109
+ expect(browser.select_list(index: 0).text).to eq 'Sweden'
110
+ end
128
111
 
129
- it 'returns false if the select list is disabled' do
130
- expect(browser.select_list(name: 'new_user_role')).to_not be_enabled
112
+ it "raises UnknownObjectException if the select list doesn't exist" do
113
+ expect { browser.select_list(index: 1337).text }.to raise_unknown_object_exception
114
+ end
131
115
  end
132
116
 
133
- it "raises UnknownObjectException if the select_list doesn't exist" do
134
- expect { browser.select_list(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
117
+ describe '#respond_to?' do
118
+ it 'returns true for all attribute methods' do
119
+ expect(browser.select_list(index: 0)).to respond_to(:class_name)
120
+ expect(browser.select_list(index: 0)).to respond_to(:id)
121
+ expect(browser.select_list(index: 0)).to respond_to(:name)
122
+ expect(browser.select_list(index: 0)).to respond_to(:value)
123
+ end
135
124
  end
136
- end
137
125
 
138
- describe '#disabled?' do
139
- it 'returns true if the select list is disabled' do
140
- expect(browser.select_list(index: 2)).to be_disabled
141
- end
126
+ # Access methods
127
+ describe '#enabled?' do
128
+ it 'returns true if the select list is enabled' do
129
+ expect(browser.select_list(name: 'new_user_country')).to be_enabled
130
+ end
142
131
 
143
- it 'returns false if the select list is enabled' do
144
- expect(browser.select_list(index: 0)).to_not be_disabled
145
- end
132
+ it 'returns false if the select list is disabled' do
133
+ expect(browser.select_list(name: 'new_user_role')).not_to be_enabled
134
+ end
146
135
 
147
- it 'should raise UnknownObjectException when the select list does not exist' do
148
- expect { browser.select_list(index: 1337).disabled? }.to raise_unknown_object_exception
136
+ it "raises UnknownObjectException if the select_list doesn't exist" do
137
+ expect { browser.select_list(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
138
+ end
149
139
  end
150
- end
151
140
 
152
- # Other
153
- describe '#option' do
154
- it 'returns an instance of Option' do
155
- option = browser.select_list(name: 'new_user_country').option(text: 'Denmark')
156
- expect(option).to be_instance_of(Watir::Option)
157
- expect(option.value).to eq '1'
158
- end
159
- end
141
+ describe '#disabled?' do
142
+ it 'returns true if the select list is disabled' do
143
+ expect(browser.select_list(index: 2)).to be_disabled
144
+ end
160
145
 
161
- describe '#options' do
162
- it 'returns all the options' do
163
- options = browser.select_list(name: 'new_user_country').options
164
- expect(options.map(&:text)).to eq ['Denmark', 'Norway', 'Sweden', 'United Kingdom', 'USA', 'Germany']
165
- end
166
- end
146
+ it 'returns false if the select list is enabled' do
147
+ expect(browser.select_list(index: 0)).not_to be_disabled
148
+ end
167
149
 
168
- describe '#selected_options' do
169
- it "should raise UnknownObjectException if the select list doesn't exist" do
170
- expect { browser.select_list(name: 'no_such_name').selected_options }.to raise_unknown_object_exception
150
+ it 'raises UnknownObjectException when the select list does not exist' do
151
+ expect { browser.select_list(index: 1337).disabled? }.to raise_unknown_object_exception
152
+ end
171
153
  end
172
154
 
173
- it 'gets the currently selected item(s)' do
174
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Norway']
175
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN NO]
155
+ # Other
156
+ describe '#option' do
157
+ it 'returns an instance of Option' do
158
+ option = browser.select_list(name: 'new_user_country').option(text: 'Denmark')
159
+ expect(option).to be_instance_of(Watir::Option)
160
+ expect(option.value).to eq '1'
161
+ end
176
162
  end
177
- end
178
163
 
179
- describe '#clear' do
180
- it 'clears the selection when possible' do
181
- browser.select_list(name: 'new_user_languages').clear
182
- expect(browser.select_list(name: 'new_user_languages').selected_options).to be_empty
164
+ describe '#options' do
165
+ it 'returns all the options' do
166
+ options = browser.select_list(name: 'new_user_country').options
167
+ expect(options.map(&:text)).to eq ['Denmark', 'Norway', 'Sweden', 'United Kingdom', 'USA', 'Germany']
168
+ end
183
169
  end
184
170
 
185
- it 'does not clear selections if the select list does not allow multiple selections' do
186
- expect {
187
- browser.select_list(name: 'new_user_country').clear
188
- }.to raise_error(/you can only clear multi-selects/)
171
+ describe '#selected_options' do
172
+ it "raises UnknownObjectException if the select list doesn't exist" do
173
+ expect { browser.select_list(name: 'no_such_name').selected_options }.to raise_unknown_object_exception
174
+ end
189
175
 
190
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Norway']
176
+ it 'gets the currently selected item(s)' do
177
+ expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Norway']
178
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN NO]
179
+ end
191
180
  end
192
181
 
193
- it "raises UnknownObjectException if the select list doesn't exist" do
194
- expect { browser.select_list(name: 'no_such_name').clear }.to raise_unknown_object_exception
195
- end
182
+ describe '#clear' do
183
+ it 'clears the selection when possible' do
184
+ browser.select_list(name: 'new_user_languages').clear
185
+ expect(browser.select_list(name: 'new_user_languages').selected_options).to be_empty
186
+ end
196
187
 
197
- it 'fires onchange event' do
198
- browser.select_list(name: 'new_user_languages').clear
199
- expect(messages.size).to eq 2
200
- end
188
+ it 'does not clear selections if the select list does not allow multiple selections' do
189
+ expect {
190
+ browser.select_list(name: 'new_user_country').clear
191
+ }.to raise_error(/you can only clear multi-selects/)
201
192
 
202
- it "doesn't fire onchange event for already cleared option" do
203
- browser.select_list(name: 'new_user_languages').option.clear
204
- expect(messages.size).to eq 0
205
- end
206
- end
193
+ expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Norway']
194
+ end
207
195
 
208
- describe '#include?' do
209
- it 'returns true if the given option exists by text' do
210
- expect(browser.select_list(name: 'new_user_country')).to include('Denmark')
211
- end
196
+ it "raises UnknownObjectException if the select list doesn't exist" do
197
+ expect { browser.select_list(name: 'no_such_name').clear }.to raise_unknown_object_exception
198
+ end
212
199
 
213
- it 'returns true if the given option exists by label' do
214
- expect(browser.select_list(name: 'new_user_country')).to include('Germany')
215
- end
200
+ it 'fires onchange event' do
201
+ browser.select_list(name: 'new_user_languages').clear
202
+ expect(messages.size).to eq 2
203
+ end
216
204
 
217
- it "returns false if the given option doesn't exist" do
218
- expect(browser.select_list(name: 'new_user_country')).to_not include('Ireland')
205
+ it "doesn't fire onchange event for already cleared option" do
206
+ browser.select_list(name: 'new_user_languages').option.clear
207
+ expect(messages.size).to eq 0
208
+ end
219
209
  end
220
- end
221
210
 
222
- describe '#selected?' do
223
- it 'evaluates true by text' do
224
- browser.select_list(name: 'new_user_country').select('1')
225
- expect(browser.select_list(name: 'new_user_country')).to be_selected('Denmark')
226
- end
211
+ describe '#include?' do
212
+ it 'returns true if the given option exists by text' do
213
+ expect(browser.select_list(name: 'new_user_country')).to include('Denmark')
214
+ end
227
215
 
228
- it 'evaluates false by text' do
229
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Sweden')
230
- end
216
+ it 'returns true if the given option exists by label' do
217
+ expect(browser.select_list(name: 'new_user_country')).to include('Germany')
218
+ end
231
219
 
232
- it 'evaluates true exclusively by text' do
233
- browser.select_list(name: 'new_user_country').select('1')
234
- expect(browser.select_list(name: 'new_user_country')).to be_selected(text: 'Denmark')
220
+ it "returns false if the given option doesn't exist" do
221
+ expect(browser.select_list(name: 'new_user_country')).not_to include('Ireland')
222
+ end
235
223
  end
236
224
 
237
- it 'evaluates false exclusively by text' do
238
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected(text: 'Sweden')
239
- end
225
+ describe '#selected?' do
226
+ it 'evaluates true by text' do
227
+ browser.select_list(name: 'new_user_country').select('1')
228
+ expect(browser.select_list(name: 'new_user_country')).to be_selected('Denmark')
229
+ end
240
230
 
241
- it 'evaluates true by label' do
242
- browser.select_list(name: 'new_user_country').select('Germany')
243
- expect(browser.select_list(name: 'new_user_country')).to be_selected('Germany')
244
- end
231
+ it 'evaluates false by text' do
232
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected('Sweden')
233
+ end
245
234
 
246
- it 'evaluates false by label' do
247
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Germany')
248
- end
235
+ it 'evaluates true exclusively by text' do
236
+ browser.select_list(name: 'new_user_country').select('1')
237
+ expect(browser.select_list(name: 'new_user_country')).to be_selected(text: 'Denmark')
238
+ end
249
239
 
250
- it 'evaluates true exclusively by label' do
251
- browser.select_list(name: 'new_user_country').select('Germany')
252
- expect(browser.select_list(name: 'new_user_country')).to be_selected(label: 'Germany')
253
- end
240
+ it 'evaluates false exclusively by text' do
241
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected(text: 'Sweden')
242
+ end
254
243
 
255
- it 'evaluates false exclusively by label' do
256
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected(label: 'Germany')
257
- end
244
+ it 'evaluates true by label' do
245
+ browser.select_list(name: 'new_user_country').select('Germany')
246
+ expect(browser.select_list(name: 'new_user_country')).to be_selected('Germany')
247
+ end
258
248
 
259
- it 'evaluates true by value' do
260
- browser.select_list(name: 'new_user_country').select('USA')
261
- expect(browser.select_list(name: 'new_user_country')).to be_selected('5')
262
- end
249
+ it 'evaluates false by label' do
250
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected('Germany')
251
+ end
263
252
 
264
- it 'evaluates false by value' do
265
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected('5')
266
- end
253
+ it 'evaluates true exclusively by label' do
254
+ browser.select_list(name: 'new_user_country').select('Germany')
255
+ expect(browser.select_list(name: 'new_user_country')).to be_selected(label: 'Germany')
256
+ end
267
257
 
268
- it 'evaluates true exclusively by value' do
269
- browser.select_list(name: 'new_user_country').select('USA')
270
- expect(browser.select_list(name: 'new_user_country')).to be_selected(value: '5')
271
- end
258
+ it 'evaluates false exclusively by label' do
259
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected(label: 'Germany')
260
+ end
272
261
 
273
- it 'evaluates false exclusively by value' do
274
- expect(browser.select_list(name: 'new_user_country')).to_not be_selected(value: '5')
275
- end
262
+ it 'evaluates true by value' do
263
+ browser.select_list(name: 'new_user_country').select('USA')
264
+ expect(browser.select_list(name: 'new_user_country')).to be_selected('5')
265
+ end
276
266
 
277
- it "raises NoValueFoundException if the option doesn't exist" do
278
- expect { browser.select_list(name: 'new_user_country').selected?('missing_option') }
279
- .to raise_no_value_found_exception
280
- end
281
- end
267
+ it 'evaluates false by value' do
268
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected('5')
269
+ end
282
270
 
283
- describe '#select method' do
284
- context 'working with multiple select list' do
285
- before do
286
- @select_list = browser.select_list(name: 'new_user_languages')
287
- @select_list.clear
271
+ it 'evaluates true exclusively by value' do
272
+ browser.select_list(name: 'new_user_country').select('USA')
273
+ expect(browser.select_list(name: 'new_user_country')).to be_selected(value: '5')
288
274
  end
289
275
 
290
- context 'when finding by value' do
291
- it 'selects an option with a String' do
292
- @select_list.select('2')
293
- expect(@select_list.selected_options.first.text).to eq 'EN'
294
- end
276
+ it 'evaluates false exclusively by value' do
277
+ expect(browser.select_list(name: 'new_user_country')).not_to be_selected(value: '5')
278
+ end
295
279
 
296
- it 'selects an option with a Number' do
297
- @select_list.select(2)
298
- expect(@select_list.selected_options.first.text).to eq 'EN'
299
- end
280
+ it "raises NoValueFoundException if the option doesn't exist" do
281
+ expect { browser.select_list(name: 'new_user_country').selected?('missing_option') }
282
+ .to raise_no_value_found_exception
283
+ end
284
+ end
300
285
 
301
- it 'selects an option with a Regexp' do
302
- @select_list.select(/2|3/)
303
- expect(@select_list.selected_options.first.text).to eq 'EN'
286
+ describe '#select method' do
287
+ context 'when working with multiple select list' do
288
+ before do
289
+ @select_list = browser.select_list(name: 'new_user_languages')
290
+ @select_list.clear
304
291
  end
305
292
 
306
- it 'uses keyword with a String' do
307
- @select_list.select(value: '2')
308
- expect(@select_list.selected_options.first.text).to eq 'EN'
293
+ context 'when finding by value' do
294
+ it 'selects an option with a String' do
295
+ @select_list.select('2')
296
+ expect(@select_list.selected_options.first.text).to eq 'EN'
297
+ end
298
+
299
+ it 'selects an option with a Number' do
300
+ @select_list.select(2)
301
+ expect(@select_list.selected_options.first.text).to eq 'EN'
302
+ end
303
+
304
+ it 'selects an option with a Regexp' do
305
+ @select_list.select(/2|3/)
306
+ expect(@select_list.selected_options.first.text).to eq 'EN'
307
+ end
308
+
309
+ it 'uses keyword with a String' do
310
+ @select_list.select(value: '2')
311
+ expect(@select_list.selected_options.first.text).to eq 'EN'
312
+ end
313
+
314
+ it 'uses keyword with a Number' do
315
+ @select_list.select(value: 2)
316
+ expect(@select_list.selected_options.first.text).to eq 'EN'
317
+ end
318
+
319
+ it 'uses keyword with a Regexp' do
320
+ @select_list.select(value: /2|3/)
321
+ expect(@select_list.selected_options.first.text).to eq 'EN'
322
+ end
309
323
  end
310
324
 
311
- it 'uses keyword with a Number' do
312
- @select_list.select(value: 2)
313
- expect(@select_list.selected_options.first.text).to eq 'EN'
325
+ context 'when finding by text' do
326
+ it 'selects an option with a String' do
327
+ @select_list.select('Norwegian')
328
+ expect(@select_list.selected_options.first.value).to eq '3'
329
+ end
330
+
331
+ it 'selects an option with a Regexp' do
332
+ @select_list.select(/wegia/)
333
+ expect(@select_list.selected_options.first.value).to eq '3'
334
+ end
335
+
336
+ it 'uses keyword with a String' do
337
+ @select_list.select(text: 'Norwegian')
338
+ expect(@select_list.selected_options.first.value).to eq '3'
339
+ end
340
+
341
+ it 'uses keyword with a Regexp' do
342
+ @select_list.select(text: /wegia/)
343
+ expect(@select_list.selected_options.first.value).to eq '3'
344
+ end
314
345
  end
315
346
 
316
- it 'uses keyword with a Regexp' do
317
- @select_list.select(value: /2|3/)
318
- expect(@select_list.selected_options.first.text).to eq 'EN'
347
+ context 'when finding by label' do
348
+ it 'selects an option with a String' do
349
+ @select_list.select('NO')
350
+ expect(@select_list.selected_options.first.value).to eq '3'
351
+ end
352
+
353
+ it 'selects an option with a Regexp' do
354
+ @select_list.select(/^N/)
355
+ expect(@select_list.selected_options.first.value).to eq '3'
356
+ end
357
+
358
+ it 'uses keyword with a String' do
359
+ @select_list.select(label: 'NO')
360
+ expect(@select_list.selected_options.first.value).to eq '3'
361
+ end
362
+
363
+ it 'uses keyword with a Regexp' do
364
+ @select_list.select(label: /^N/)
365
+ expect(@select_list.selected_options.first.value).to eq '3'
366
+ end
319
367
  end
320
- end
321
368
 
322
- context 'when finding by text' do
323
- it 'selects an option with a String' do
324
- @select_list.select('Norwegian')
325
- expect(@select_list.selected_options.first.value).to eq '3'
369
+ it 'selects multiple options successively' do
370
+ @select_list.select('Danish')
371
+ @select_list.select('Swedish')
372
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
326
373
  end
327
374
 
328
- it 'selects an option with a Regexp' do
329
- @select_list.select(/wegia/)
330
- expect(@select_list.selected_options.first.value).to eq '3'
375
+ it 'selects each item in an Array' do
376
+ @select_list.select(%w[Danish Swedish])
377
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
331
378
  end
332
379
 
333
- it 'uses keyword with a String' do
334
- @select_list.select(text: 'Norwegian')
335
- expect(@select_list.selected_options.first.value).to eq '3'
380
+ it 'selects each item in a parameter list' do
381
+ @select_list.select('Danish', 'Swedish')
382
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
336
383
  end
337
384
 
338
- it 'uses keyword with a Regexp' do
339
- @select_list.select(text: /wegia/)
340
- expect(@select_list.selected_options.first.value).to eq '3'
385
+ it 'selects empty options',
386
+ except: {browser: :safari, reason: 'Safari throwing ElementNotInteractableError'} do
387
+ browser.select_list(id: 'delete_user_username').select('')
388
+ expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
341
389
  end
342
- end
343
390
 
344
- context 'when finding by label' do
345
- it 'selects an option with a String' do
346
- @select_list.select('NO')
347
- expect(@select_list.selected_options.first.value).to eq '3'
391
+ it 'returns the value selected' do
392
+ expect(@select_list.select('Danish')).to eq 'Danish'
348
393
  end
349
394
 
350
- it 'selects an option with a Regexp' do
351
- @select_list.select(/^N/)
352
- expect(@select_list.selected_options.first.value).to eq '3'
395
+ it 'fires onchange event when selecting or deselecting an item' do
396
+ @select_list.select('Danish')
397
+ expect(messages).to eq ['changed language', 'changed language', 'changed language']
353
398
  end
354
399
 
355
- it 'uses keyword with a String' do
356
- @select_list.select(label: 'NO')
357
- expect(@select_list.selected_options.first.value).to eq '3'
358
- end
400
+ it "doesn't fire onchange event when selecting an already selected item" do
401
+ @select_list.select('English')
402
+ expect(messages.size).to eq 3
359
403
 
360
- it 'uses keyword with a Regexp' do
361
- @select_list.select(label: /^N/)
362
- expect(@select_list.selected_options.first.value).to eq '3'
404
+ @select_list.select('English')
405
+ expect(messages.size).to eq 3
363
406
  end
364
407
  end
365
408
 
366
- it 'selects multiple options successively' do
367
- @select_list.select('Danish')
368
- @select_list.select('Swedish')
369
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
370
- end
371
-
372
- it 'selects each item in an Array' do
373
- @select_list.select(%w[Danish Swedish])
374
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
375
- end
376
-
377
- it 'selects each item in a parameter list' do
378
- @select_list.select('Danish', 'Swedish')
379
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
380
- end
381
-
382
- it 'selects empty options',
409
+ it 'returns an empty string when selecting an option that disappears when selected',
383
410
  except: {browser: :safari, reason: 'Safari throwing ElementNotInteractableError'} do
384
- browser.select_list(id: 'delete_user_username').select('')
385
- expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
386
- end
387
-
388
- it 'returns the value selected' do
389
- expect(@select_list.select('Danish')).to eq 'Danish'
390
- end
391
-
392
- it 'fires onchange event when selecting or deselecting an item' do
393
- @select_list.select('Danish')
394
- expect(messages).to eq ['changed language', 'changed language', 'changed language']
395
- end
396
-
397
- it "doesn't fire onchange event when selecting an already selected item" do
398
- @select_list.select('English')
399
- expect(messages.size).to eq 3
400
-
401
- @select_list.select('English')
402
- expect(messages.size).to eq 3
411
+ expect(browser.select_list(id: 'obsolete').select('sweden')).to eq ''
403
412
  end
404
- end
405
-
406
- it 'returns an empty string when selecting an option that disappears when selected',
407
- except: {browser: :safari, reason: 'Safari throwing ElementNotInteractableError'} do
408
- expect(browser.select_list(id: 'obsolete').select('sweden')).to eq ''
409
- end
410
-
411
- it 'selects options with a single-quoted value' do
412
- browser.select_list(id: 'single-quote').select("'foo'")
413
- end
414
-
415
- it 'waits to select an option' do
416
- browser.goto WatirSpec.url_for('wait.html')
417
- browser.a(id: 'add_select').click
418
- select_list = browser.select_list(id: 'languages')
419
- expect { select_list.select('No') }.to wait_and_raise_no_value_found_exception
420
- end
421
-
422
- it "raises NoValueFoundException if the option doesn't exist" do
423
- message = /#<Watir::Select: located: false; {:name=>"new_user_country", :tag_name=>"select"}>/
424
- expect { browser.select_list(name: 'new_user_country').select('missing_option') }
425
- .to raise_no_value_found_exception message
426
- expect { browser.select_list(name: 'new_user_country').select(/missing_option/) }
427
- .to raise_no_value_found_exception message
428
- end
429
-
430
- it 'raises ObjectDisabledException if the option is disabled', except: {browser: :safari} do
431
- expect { browser.select_list(name: 'new_user_languages').select('Russian') }
432
- .to raise_object_disabled_exception
433
- end
434
413
 
435
- it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
436
- expect { browser.select_list(id: 'new_user_languages').select(true) }.to raise_error(TypeError)
437
- end
414
+ it 'selects options with a single-quoted value as String' do
415
+ select_list = browser.select_list(id: 'single-quote')
416
+ select_list.select("'foo'")
438
417
 
439
- context 'multiple options' do
440
- it 'in an Array' do
441
- browser.select_list(name: 'new_user_languages').clear
442
- browser.select_list(name: 'new_user_languages').select(%w[Danish Swedish])
443
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
418
+ expect(select_list).to be_selected("'foo'")
444
419
  end
445
420
 
446
- it 'in a parameter list' do
447
- browser.select_list(name: 'new_user_languages').clear
448
- browser.select_list(name: 'new_user_languages').select('Danish', 'Swedish')
449
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
450
- end
421
+ it 'selects options with a single-quoted value as Regexp' do
422
+ select_list = browser.select_list(id: 'single-quote')
423
+ select_list.select(/'foo'/)
451
424
 
452
- it 'based on text' do
453
- browser.select_list(name: 'new_user_languages').clear
454
- browser.select_list(name: 'new_user_languages').select([/ish/])
455
- list = %w[Danish EN Swedish]
456
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
425
+ expect(select_list).to be_selected("'foo'")
457
426
  end
458
427
 
459
- it 'based on label and single regexp' do
460
- browser.select_list(name: 'new_user_languages').clear
461
- browser.select_list(name: 'new_user_languages').select([/NO|EN/])
462
- list = %w[EN NO]
463
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
428
+ it 'waits to select an option' do
429
+ browser.goto WatirSpec.url_for('wait.html')
430
+ browser.a(id: 'add_select').click
431
+ select_list = browser.select_list(id: 'languages')
432
+ expect { select_list.select('No') }.to wait_and_raise_no_value_found_exception
464
433
  end
465
434
 
466
- it 'based on label and multiple regexp' do
467
- browser.select_list(name: 'new_user_languages').clear
468
- browser.select_list(name: 'new_user_languages').select([/NO/, /EN/])
469
- list = %w[EN NO]
470
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
435
+ it "raises NoValueFoundException if the option doesn't exist" do
436
+ message = /#<Watir::Select: located: false; {:name=>"new_user_country", :tag_name=>"select"}>/
437
+ expect { browser.select_list(name: 'new_user_country').select('missing_option') }
438
+ .to raise_no_value_found_exception message
439
+ expect { browser.select_list(name: 'new_user_country').select(/missing_option/) }
440
+ .to raise_no_value_found_exception message
471
441
  end
472
442
 
473
- it 'from an Array' do
474
- browser.select_list(name: 'new_user_languages').clear
475
- browser.select_list(name: 'new_user_languages').select([/ish/, /Latin/])
476
- list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
477
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
443
+ it 'raises ObjectDisabledException if the option is disabled', except: {browser: :safari} do
444
+ expect { browser.select_list(name: 'new_user_languages').select('Russian') }
445
+ .to raise_object_disabled_exception
478
446
  end
479
447
 
480
- it 'from multiple arguments' do
481
- browser.select_list(name: 'new_user_languages').clear
482
- browser.select_list(name: 'new_user_languages').select(/ish/, /Latin/)
483
- list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
484
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
448
+ it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
449
+ expect { browser.select_list(id: 'new_user_languages').select(true) }.to raise_error(TypeError)
485
450
  end
486
451
 
487
- it 'returns the first matching value if there are multiple matches' do
488
- expect(browser.select_list(name: 'new_user_languages').select([/ish/])).to eq 'Danish'
489
- end
490
- end
491
- end
452
+ context 'when multiple options' do
453
+ it 'in an Array' do
454
+ browser.select_list(name: 'new_user_languages').clear
455
+ browser.select_list(name: 'new_user_languages').select(%w[Danish Swedish])
456
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
457
+ end
492
458
 
493
- describe '#select!' do
494
- context 'working with multiple select list' do
495
- before do
496
- @select_list = browser.select_list(name: 'new_user_languages')
497
- @select_list.clear
498
- end
459
+ it 'in a parameter list' do
460
+ browser.select_list(name: 'new_user_languages').clear
461
+ browser.select_list(name: 'new_user_languages').select('Danish', 'Swedish')
462
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
463
+ end
499
464
 
500
- context 'when finding by value' do
501
- it 'selects an option with a String' do
502
- @select_list.select!('2')
503
- expect(@select_list.selected_options.first.text).to eq 'EN'
465
+ it 'based on text' do
466
+ browser.select_list(name: 'new_user_languages').clear
467
+ browser.select_list(name: 'new_user_languages').select([/ish/])
468
+ list = %w[Danish EN Swedish]
469
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
504
470
  end
505
471
 
506
- it 'selects an option with a Number' do
507
- @select_list.select!(2)
508
- expect(@select_list.selected_options.first.text).to eq 'EN'
472
+ it 'based on label and single regexp' do
473
+ browser.select_list(name: 'new_user_languages').clear
474
+ browser.select_list(name: 'new_user_languages').select([/NO|EN/])
475
+ list = %w[EN NO]
476
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
509
477
  end
510
478
 
511
- it 'selects an option with a Regexp' do
512
- @select_list.select!(/2|3/)
513
- expect(@select_list.selected_options.first.text).to eq 'EN'
479
+ it 'based on label and multiple regexp' do
480
+ browser.select_list(name: 'new_user_languages').clear
481
+ browser.select_list(name: 'new_user_languages').select([/NO/, /EN/])
482
+ list = %w[EN NO]
483
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
514
484
  end
515
485
 
516
- it 'uses keyword with a String' do
517
- @select_list.select!(value: '2')
518
- expect(@select_list.selected_options.first.text).to eq 'EN'
486
+ it 'from an Array' do
487
+ browser.select_list(name: 'new_user_languages').clear
488
+ browser.select_list(name: 'new_user_languages').select([/ish/, /Latin/])
489
+ list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
490
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
519
491
  end
520
492
 
521
- it 'uses keyword with a Number' do
522
- @select_list.select!(value: 2)
523
- expect(@select_list.selected_options.first.text).to eq 'EN'
493
+ it 'from multiple arguments' do
494
+ browser.select_list(name: 'new_user_languages').clear
495
+ browser.select_list(name: 'new_user_languages').select(/ish/, /Latin/)
496
+ list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
497
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
524
498
  end
525
499
 
526
- it 'uses keyword with a Regexp' do
527
- @select_list.select!(value: /2|3/)
528
- expect(@select_list.selected_options.first.text).to eq 'EN'
500
+ it 'returns the first matching value if there are multiple matches' do
501
+ expect(browser.select_list(name: 'new_user_languages').select([/ish/])).to eq 'Danish'
529
502
  end
530
503
  end
504
+ end
531
505
 
532
- context 'when finding by text' do
533
- it 'selects an option with a String' do
534
- @select_list.select!('Danish')
535
- expect(@select_list.selected_options.first.value).to eq '1'
506
+ describe '#select!' do
507
+ context 'when working with multiple select list' do
508
+ before do
509
+ @select_list = browser.select_list(name: 'new_user_languages')
510
+ @select_list.clear
536
511
  end
537
512
 
538
- it 'selects an option with a Regexp' do
539
- @select_list.select!(/ani/)
540
- expect(@select_list.selected_options.first.value).to eq '1'
513
+ context 'when finding by value' do
514
+ it 'selects an option with a String' do
515
+ @select_list.select!('2')
516
+ expect(@select_list.selected_options.first.text).to eq 'EN'
517
+ end
518
+
519
+ it 'selects an option with a Number' do
520
+ @select_list.select!(2)
521
+ expect(@select_list.selected_options.first.text).to eq 'EN'
522
+ end
523
+
524
+ it 'selects an option with a Regexp' do
525
+ @select_list.select!(/2|3/)
526
+ expect(@select_list.selected_options.first.text).to eq 'EN'
527
+ end
528
+
529
+ it 'uses keyword with a String' do
530
+ @select_list.select!(value: '2')
531
+ expect(@select_list.selected_options.first.text).to eq 'EN'
532
+ end
533
+
534
+ it 'uses keyword with a Number' do
535
+ @select_list.select!(value: 2)
536
+ expect(@select_list.selected_options.first.text).to eq 'EN'
537
+ end
538
+
539
+ it 'uses keyword with a Regexp' do
540
+ @select_list.select!(value: /2|3/)
541
+ expect(@select_list.selected_options.first.text).to eq 'EN'
542
+ end
541
543
  end
542
544
 
543
- it 'uses keyword with a String' do
544
- @select_list.select!(text: 'Danish')
545
- expect(@select_list.selected_options.first.value).to eq '1'
545
+ context 'when finding by text' do
546
+ it 'selects an option with a String' do
547
+ @select_list.select!('Danish')
548
+ expect(@select_list.selected_options.first.value).to eq '1'
549
+ end
550
+
551
+ it 'selects an option with a Regexp' do
552
+ @select_list.select!(/ani/)
553
+ expect(@select_list.selected_options.first.value).to eq '1'
554
+ end
555
+
556
+ it 'uses keyword with a String' do
557
+ @select_list.select!(text: 'Danish')
558
+ expect(@select_list.selected_options.first.value).to eq '1'
559
+ end
560
+
561
+ it 'uses keyword with a Regexp' do
562
+ @select_list.select!(text: /ani/)
563
+ expect(@select_list.selected_options.first.value).to eq '1'
564
+ end
546
565
  end
547
566
 
548
- it 'uses keyword with a Regexp' do
549
- @select_list.select!(text: /ani/)
550
- expect(@select_list.selected_options.first.value).to eq '1'
567
+ context 'when finding by label' do
568
+ it 'selects an option with a String' do
569
+ @select_list.select!('NO')
570
+ expect(@select_list.selected_options.first.value).to eq '3'
571
+ end
572
+
573
+ it 'selects an option with a Regexp' do
574
+ @select_list.select!(/^N/)
575
+ expect(@select_list.selected_options.first.value).to eq '3'
576
+ end
577
+
578
+ it 'uses keyword with a String' do
579
+ @select_list.select!(label: 'NO')
580
+ expect(@select_list.selected_options.first.value).to eq '3'
581
+ end
582
+
583
+ it 'uses keyword with a Regexp' do
584
+ @select_list.select!(label: /^N/)
585
+ expect(@select_list.selected_options.first.value).to eq '3'
586
+ end
551
587
  end
552
- end
553
588
 
554
- context 'when finding by label' do
555
- it 'selects an option with a String' do
556
- @select_list.select!('NO')
557
- expect(@select_list.selected_options.first.value).to eq '3'
589
+ it 'selects multiple options successively' do
590
+ @select_list.select!('Danish')
591
+ @select_list.select!('Swedish')
592
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
558
593
  end
559
594
 
560
- it 'selects an option with a Regexp' do
561
- @select_list.select!(/^N/)
562
- expect(@select_list.selected_options.first.value).to eq '3'
595
+ it 'selects each item in an Array' do
596
+ @select_list.select!(%w[Danish Swedish])
597
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
563
598
  end
564
599
 
565
- it 'uses keyword with a String' do
566
- @select_list.select!(label: 'NO')
567
- expect(@select_list.selected_options.first.value).to eq '3'
600
+ it 'selects each item in a parameter list' do
601
+ @select_list.select!('Danish', 'Swedish')
602
+ expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
568
603
  end
569
604
 
570
- it 'uses keyword with a Regexp' do
571
- @select_list.select!(label: /^N/)
572
- expect(@select_list.selected_options.first.value).to eq '3'
605
+ it 'selects empty options' do
606
+ browser.select_list(id: 'delete_user_username').select!('')
607
+ expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
573
608
  end
574
- end
575
609
 
576
- it 'selects multiple options successively' do
577
- @select_list.select!('Danish')
578
- @select_list.select!('Swedish')
579
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
610
+ it 'returns the value selected' do
611
+ expect(@select_list.select!('Danish')).to eq 'Danish'
612
+ end
580
613
  end
581
614
 
582
- it 'selects each item in an Array' do
583
- @select_list.select!(%w[Danish Swedish])
584
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
585
- end
615
+ it 'selects options with a single-quoted value' do
616
+ select_list = browser.select_list(id: 'single-quote')
617
+ select_list.select!("'foo'")
586
618
 
587
- it 'selects each item in a parameter list' do
588
- @select_list.select!('Danish', 'Swedish')
589
- expect(@select_list.selected_options.map(&:text)).to eq %w[Danish Swedish]
619
+ expect(select_list).to be_selected("'foo'")
590
620
  end
591
621
 
592
- it 'selects empty options' do
593
- browser.select_list(id: 'delete_user_username').select!('')
594
- expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
622
+ it 'selects exact matches when using String' do
623
+ browser.select_list(name: 'new_user_languages').clear
624
+ browser.select_list(name: 'new_user_languages').select!('Latin')
625
+ selected_options = browser.select_list(name: 'new_user_languages').selected_options.map(&:text)
626
+ expect(selected_options).not_to include('Azeri - Latin')
627
+ expect(selected_options).to include('Latin')
595
628
  end
596
629
 
597
- it 'returns the value selected' do
598
- expect(@select_list.select!('Danish')).to eq 'Danish'
630
+ it "raises NoValueFoundException if the option doesn't exist" do
631
+ expect { browser.select_list(id: 'new_user_country').select!('missing_option') }
632
+ .to raise_no_value_found_exception
633
+ expect { browser.select_list(id: 'new_user_country').select!(/missing_option/) }
634
+ .to raise_no_value_found_exception
599
635
  end
600
- end
601
-
602
- it 'selects options with a single-quoted value' do
603
- browser.select_list(id: 'single-quote').select!("'foo'")
604
- end
605
-
606
- it 'selects exact matches when using String' do
607
- browser.select_list(name: 'new_user_languages').clear
608
- browser.select_list(name: 'new_user_languages').select!('Latin')
609
- selected_options = browser.select_list(name: 'new_user_languages').selected_options.map(&:text)
610
- expect(selected_options).not_to include('Azeri - Latin')
611
- expect(selected_options).to include('Latin')
612
- end
613
-
614
- it "raises NoValueFoundException if the option doesn't exist" do
615
- expect { browser.select_list(id: 'new_user_country').select!('missing_option') }
616
- .to raise_no_value_found_exception
617
- expect { browser.select_list(id: 'new_user_country').select!(/missing_option/) }
618
- .to raise_no_value_found_exception
619
- end
620
636
 
621
- it 'raises ObjectDisabledException if the option is disabled', except: {browser: :safari} do
622
- browser.select_list(id: 'new_user_languages').clear
623
- expect { browser.select_list(name: 'new_user_languages').select!('Russian') }
624
- .to raise_object_disabled_exception
625
- end
626
-
627
- it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
628
- expect { browser.select_list(id: 'new_user_languages').select!(true) }.to raise_error(TypeError)
629
- end
630
-
631
- context 'multiple options' do
632
- it 'in an Array' do
633
- browser.select_list(name: 'new_user_languages').clear
634
- browser.select_list(name: 'new_user_languages').select!(%w[Danish Swedish])
635
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
637
+ it 'raises ObjectDisabledException if the option is disabled', except: {browser: :safari} do
638
+ browser.select_list(id: 'new_user_languages').clear
639
+ expect { browser.select_list(name: 'new_user_languages').select!('Russian') }
640
+ .to raise_object_disabled_exception
636
641
  end
637
642
 
638
- it 'in a parameter list' do
639
- browser.select_list(name: 'new_user_languages').clear
640
- browser.select_list(name: 'new_user_languages').select!('Danish', 'Swedish')
641
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
643
+ it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
644
+ expect { browser.select_list(id: 'new_user_languages').select!(true) }.to raise_error(TypeError)
642
645
  end
643
646
 
644
- it 'based on text' do
645
- browser.select_list(name: 'new_user_languages').clear
646
- browser.select_list(name: 'new_user_languages').select!([/ish/])
647
- list = %w[Danish EN Swedish]
648
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
649
- end
647
+ context 'when multiple options' do
648
+ it 'in an Array' do
649
+ browser.select_list(name: 'new_user_languages').clear
650
+ browser.select_list(name: 'new_user_languages').select!(%w[Danish Swedish])
651
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
652
+ end
650
653
 
651
- it 'based on label and single regexp' do
652
- browser.select_list(name: 'new_user_languages').clear
653
- browser.select_list(name: 'new_user_languages').select!([/NO|EN/])
654
- list = %w[EN NO]
655
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
656
- end
654
+ it 'in a parameter list' do
655
+ browser.select_list(name: 'new_user_languages').clear
656
+ browser.select_list(name: 'new_user_languages').select!('Danish', 'Swedish')
657
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
658
+ end
657
659
 
658
- it 'based on label and multiple regexp' do
659
- browser.select_list(name: 'new_user_languages').clear
660
- browser.select_list(name: 'new_user_languages').select!([/NO/, /EN/])
661
- list = %w[EN NO]
662
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
663
- end
660
+ it 'based on text' do
661
+ browser.select_list(name: 'new_user_languages').clear
662
+ browser.select_list(name: 'new_user_languages').select!([/ish/])
663
+ list = %w[Danish EN Swedish]
664
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
665
+ end
664
666
 
665
- it 'from an Array' do
666
- browser.select_list(name: 'new_user_languages').clear
667
- browser.select_list(name: 'new_user_languages').select!([/ish/, /Latin/])
668
- list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
669
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
670
- end
667
+ it 'based on label and single regexp' do
668
+ browser.select_list(name: 'new_user_languages').clear
669
+ browser.select_list(name: 'new_user_languages').select!([/NO|EN/])
670
+ list = %w[EN NO]
671
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
672
+ end
671
673
 
672
- it 'from multiple arguments' do
673
- browser.select_list(name: 'new_user_languages').clear
674
- browser.select_list(name: 'new_user_languages').select!(/ish/, /Latin/)
675
- list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
676
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
677
- end
674
+ it 'based on label and multiple regexp' do
675
+ browser.select_list(name: 'new_user_languages').clear
676
+ browser.select_list(name: 'new_user_languages').select!([/NO/, /EN/])
677
+ list = %w[EN NO]
678
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
679
+ end
678
680
 
679
- it 'returns the first matching value if there are multiple matches' do
680
- expect(browser.select_list(name: 'new_user_languages').select!([/ish/])).to eq 'Danish'
681
+ it 'from an Array' do
682
+ browser.select_list(name: 'new_user_languages').clear
683
+ browser.select_list(name: 'new_user_languages').select!([/ish/, /Latin/])
684
+ list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
685
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
686
+ end
687
+
688
+ it 'from multiple arguments' do
689
+ browser.select_list(name: 'new_user_languages').clear
690
+ browser.select_list(name: 'new_user_languages').select!(/ish/, /Latin/)
691
+ list = ['Danish', 'EN', 'Swedish', 'Azeri - Latin', 'Latin']
692
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq list
693
+ end
694
+
695
+ it 'returns the first matching value if there are multiple matches' do
696
+ expect(browser.select_list(name: 'new_user_languages').select!([/ish/])).to eq 'Danish'
697
+ end
681
698
  end
682
699
  end
683
700
  end