watir 7.2.0 → 7.2.1

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