watir 7.0.0.beta1 → 7.0.0.beta5

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +7 -3
  3. data/.rubocop.yml +2 -7
  4. data/CHANGES.md +32 -0
  5. data/lib/watir/browser.rb +21 -7
  6. data/lib/watir/capabilities.rb +52 -7
  7. data/lib/watir/elements/date_field.rb +4 -1
  8. data/lib/watir/elements/date_time_field.rb +4 -1
  9. data/lib/watir/elements/element.rb +32 -3
  10. data/lib/watir/elements/font.rb +1 -0
  11. data/lib/watir/elements/iframe.rb +0 -1
  12. data/lib/watir/elements/radio.rb +2 -2
  13. data/lib/watir/elements/select.rb +63 -40
  14. data/lib/watir/has_window.rb +2 -0
  15. data/lib/watir/locators.rb +4 -0
  16. data/lib/watir/locators/element/matcher.rb +1 -1
  17. data/lib/watir/locators/element/selector_builder.rb +0 -3
  18. data/lib/watir/locators/element/selector_builder/xpath.rb +2 -1
  19. data/lib/watir/locators/option/matcher.rb +24 -0
  20. data/lib/watir/locators/option/selector_builder.rb +8 -0
  21. data/lib/watir/locators/option/selector_builder/xpath.rb +37 -0
  22. data/lib/watir/logger.rb +3 -74
  23. data/lib/watir/radio_set.rb +1 -0
  24. data/lib/watir/screenshot.rb +2 -8
  25. data/lib/watir/user_editable.rb +10 -3
  26. data/lib/watir/version.rb +1 -1
  27. data/lib/watir/window.rb +15 -4
  28. data/lib/watir/window_collection.rb +9 -0
  29. data/lib/watirspec.rb +4 -2
  30. data/lib/watirspec/guards.rb +1 -1
  31. data/lib/watirspec/remote_server.rb +2 -6
  32. data/lib/watirspec/server.rb +1 -1
  33. data/spec/spec_helper.rb +0 -10
  34. data/spec/unit/capabilities_spec.rb +198 -48
  35. data/spec/unit/match_elements/element_spec.rb +11 -0
  36. data/spec/watirspec/after_hooks_spec.rb +22 -45
  37. data/spec/watirspec/browser_spec.rb +185 -206
  38. data/spec/watirspec/cookies_spec.rb +47 -52
  39. data/spec/watirspec/drag_and_drop_spec.rb +5 -7
  40. data/spec/watirspec/elements/area_spec.rb +1 -5
  41. data/spec/watirspec/elements/button_spec.rb +4 -8
  42. data/spec/watirspec/elements/checkbox_spec.rb +2 -4
  43. data/spec/watirspec/elements/date_field_spec.rb +13 -16
  44. data/spec/watirspec/elements/date_time_field_spec.rb +14 -13
  45. data/spec/watirspec/elements/dd_spec.rb +3 -4
  46. data/spec/watirspec/elements/del_spec.rb +10 -12
  47. data/spec/watirspec/elements/div_spec.rb +41 -50
  48. data/spec/watirspec/elements/dl_spec.rb +4 -12
  49. data/spec/watirspec/elements/element_spec.rb +155 -89
  50. data/spec/watirspec/elements/elements_spec.rb +8 -9
  51. data/spec/watirspec/elements/filefield_spec.rb +5 -7
  52. data/spec/watirspec/elements/form_spec.rb +1 -1
  53. data/spec/watirspec/elements/forms_spec.rb +3 -5
  54. data/spec/watirspec/elements/frame_spec.rb +17 -22
  55. data/spec/watirspec/elements/iframe_spec.rb +21 -27
  56. data/spec/watirspec/elements/ins_spec.rb +10 -12
  57. data/spec/watirspec/elements/link_spec.rb +24 -26
  58. data/spec/watirspec/elements/links_spec.rb +8 -9
  59. data/spec/watirspec/elements/radio_spec.rb +11 -14
  60. data/spec/watirspec/elements/select_list_spec.rb +248 -117
  61. data/spec/watirspec/elements/span_spec.rb +10 -12
  62. data/spec/watirspec/elements/table_nesting_spec.rb +31 -34
  63. data/spec/watirspec/elements/table_spec.rb +11 -13
  64. data/spec/watirspec/elements/tbody_spec.rb +10 -12
  65. data/spec/watirspec/elements/td_spec.rb +4 -6
  66. data/spec/watirspec/elements/text_field_spec.rb +10 -12
  67. data/spec/watirspec/elements/tr_spec.rb +5 -7
  68. data/spec/watirspec/support/rspec_matchers.rb +1 -1
  69. data/spec/watirspec/user_editable_spec.rb +26 -28
  70. data/spec/watirspec/wait_spec.rb +255 -258
  71. data/spec/watirspec/window_switching_spec.rb +199 -200
  72. data/spec/watirspec_helper.rb +34 -31
  73. data/watir.gemspec +1 -1
  74. metadata +7 -8
  75. data/spec/implementation_spec.rb +0 -24
  76. data/spec/unit/logger_spec.rb +0 -81
@@ -47,15 +47,13 @@ describe 'Frame' do
47
47
  expect(browser.frame(xpath: "//frame[@id='no_such_id']")).to_not exist
48
48
  end
49
49
 
50
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1255946', :firefox do
51
- it 'handles nested frames' do
52
- browser.goto(WatirSpec.url_for('nested_frames.html'))
50
+ it 'handles nested frames' do
51
+ browser.goto(WatirSpec.url_for('nested_frames.html'))
53
52
 
54
- browser.frame(id: 'two').frame(id: 'three').link(id: 'four').click
53
+ browser.frame(id: 'two').frame(id: 'three').link(id: 'four').click
55
54
 
56
- Watir::Wait.until { browser.title == 'definition_lists' }
57
- expect { browser.goto(WatirSpec.url_for('nested_frames.html')) }.to_not raise_exception
58
- end
55
+ browser.wait_until(title: 'definition_lists')
56
+ expect { browser.goto(WatirSpec.url_for('nested_frames.html')) }.to_not raise_exception
59
57
  end
60
58
 
61
59
  it "raises TypeError when 'what' argument is invalid" do
@@ -88,24 +86,21 @@ describe 'Frame' do
88
86
  expect(browser.frame(index: 0).text_field(name: 'senderElement').value).to eq 'new value'
89
87
  end
90
88
 
91
- bug 'Safari does not strip text', :safari do
92
- it "can access the frame's parent element after use" do
93
- el = browser.frameset
94
- el.frame.text_field.value
95
- expect(el.attribute_value('cols')).to be_kind_of(String)
96
- end
89
+ it "can access the frame's parent element after use" do
90
+ el = browser.frameset
91
+ el.frame.text_field.value
92
+ expect(el.attribute_value('cols')).to be_kind_of(String)
97
93
  end
98
94
 
99
95
  describe '#execute_script' do
100
- bug 'Safari does not strip text', :safari do
101
- it 'executes the given javascript in the specified frame' do
102
- frame = browser.frame(index: 0)
103
- expect(frame.div(id: 'set_by_js').text).to eq ''
104
- inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
105
- frame.execute_script(%{document.getElementById('set_by_js').innerHTML = '#{inner_html}'})
106
- text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
107
- expect(frame.div(id: 'set_by_js').text).to eq text
108
- end
96
+ it 'executes the given javascript in the specified frame',
97
+ except: {browser: :safari, reason: 'Safari does not strip text'} do
98
+ frame = browser.frame(index: 0)
99
+ expect(frame.div(id: 'set_by_js').text).to eq ''
100
+ inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
101
+ frame.execute_script(%{document.getElementById('set_by_js').innerHTML = '#{inner_html}'})
102
+ text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
103
+ expect(frame.div(id: 'set_by_js').text).to eq text
109
104
  end
110
105
  end
111
106
 
@@ -9,18 +9,13 @@ describe 'IFrame' do
9
9
  browser.goto(WatirSpec.url_for('iframes.html'))
10
10
  end
11
11
 
12
- not_compliant_on :safari do
13
- bug 'Firefox 58 broke this, appears to be working in Nightly',
14
- %i[firefox linux] do
15
- it 'handles crossframe javascript' do
16
- browser.goto WatirSpec.url_for('iframes.html')
12
+ it 'handles crossframe javascript' do
13
+ browser.goto WatirSpec.url_for('iframes.html')
17
14
 
18
- expect(browser.iframe(id: 'iframe_1').text_field(name: 'senderElement').value).to eq 'send_this_value'
19
- expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'old_value'
20
- browser.iframe(id: 'iframe_1').button(id: 'send').click
21
- expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'send_this_value'
22
- end
23
- end
15
+ expect(browser.iframe(id: 'iframe_1').text_field(name: 'senderElement').value).to eq 'send_this_value'
16
+ expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'old_value'
17
+ browser.iframe(id: 'iframe_1').button(id: 'send').click
18
+ expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'send_this_value'
24
19
  end
25
20
 
26
21
  it 'locates an element defined by Selenium Element' do
@@ -116,13 +111,13 @@ describe 'IFrame' do
116
111
  expect(browser.iframe(id: 'no_such_id').element).to_not exist
117
112
  end
118
113
 
119
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1255946', :firefox do
120
- it 'handles nested iframes' do
121
- browser.goto(WatirSpec.url_for('nested_iframes.html'))
122
- browser.iframe(id: 'two').iframe(id: 'three').link(id: 'four').click
114
+ it 'handles nested iframes' do
115
+ browser.goto(WatirSpec.url_for('nested_iframes.html'))
116
+ browser.iframe(id: 'two').iframe(id: 'three').link(id: 'four').click
123
117
 
124
- Watir::Wait.until { browser.title == 'definition_lists' }
125
- end
118
+ expect {
119
+ browser.wait_until { |b| b.title == 'definition_lists' }
120
+ }.not_to raise_exception
126
121
  end
127
122
 
128
123
  it "raises TypeError when 'what' argument is invalid" do
@@ -200,16 +195,15 @@ describe 'IFrame' do
200
195
  end
201
196
 
202
197
  describe '#execute_script' do
203
- bug 'Safari does not strip text', :safari do
204
- it 'executes the given javascript in the specified frame' do
205
- frame = browser.iframe(index: 0)
206
- expect(frame.div(id: 'set_by_js').text).to eq ''
207
- inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
208
- script = "document.getElementById('set_by_js').innerHTML = '#{inner_html}'"
209
- frame.execute_script script
210
- text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
211
- expect(frame.div(id: 'set_by_js').text).to eq text
212
- end
198
+ it 'executes the given javascript in the specified frame',
199
+ except: {browser: :safari, reason: 'Safari does not strip text'} do
200
+ frame = browser.iframe(index: 0)
201
+ expect(frame.div(id: 'set_by_js').text).to eq ''
202
+ inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
203
+ script = "document.getElementById('set_by_js').innerHTML = '#{inner_html}'"
204
+ frame.execute_script script
205
+ text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
206
+ expect(frame.div(id: 'set_by_js').text).to eq text
213
207
  end
214
208
  end
215
209
 
@@ -94,18 +94,16 @@ describe 'Ins' do
94
94
  end
95
95
 
96
96
  # Other
97
- not_compliant_on :headless do
98
- describe '#click' do
99
- it 'fires events' do
100
- expect(browser.ins(class: 'footer').text).to_not include('Javascript')
101
- browser.ins(class: 'footer').click
102
- expect(browser.ins(class: 'footer').text).to include('Javascript')
103
- end
104
-
105
- it "raises UnknownObjectException if the ins doesn't exist" do
106
- expect { browser.ins(id: 'no_such_id').click }.to raise_unknown_object_exception
107
- expect { browser.ins(title: 'no_such_title').click }.to raise_unknown_object_exception
108
- end
97
+ describe '#click', except: {headless: true} do
98
+ it 'fires events' do
99
+ expect(browser.ins(class: 'footer').text).to_not include('Javascript')
100
+ browser.ins(class: 'footer').click
101
+ expect(browser.ins(class: 'footer').text).to include('Javascript')
102
+ end
103
+
104
+ it "raises UnknownObjectException if the ins doesn't exist" do
105
+ expect { browser.ins(id: 'no_such_id').click }.to raise_unknown_object_exception
106
+ expect { browser.ins(title: 'no_such_title').click }.to raise_unknown_object_exception
109
107
  end
110
108
  end
111
109
  end
@@ -14,9 +14,7 @@ describe 'Link' do
14
14
  expect(browser.link(title: /link_title_2/)).to exist
15
15
  expect(browser.link(text: 'Link 2')).to exist
16
16
  expect(browser.link(text: /Link 2/i)).to exist
17
- not_compliant_on :internet_explorer do
18
- expect(browser.link(href: 'non_control_elements.html')).to exist
19
- end
17
+ expect(browser.link(href: 'non_control_elements.html')).to exist
20
18
  expect(browser.link(href: /non_control_elements.html/)).to exist
21
19
  expect(browser.link(index: 1)).to exist
22
20
  expect(browser.link(xpath: "//a[@id='link_2']")).to exist
@@ -123,35 +121,36 @@ describe 'Link' do
123
121
  end
124
122
 
125
123
  # Manipulation methods
124
+ # Note: the #wait_until calls are hacks for Safari specifically
126
125
  describe '#click' do
127
126
  it 'finds an existing link by (text: String) and clicks it' do
128
- browser.link(text: 'Link 3').click
129
- expect(browser.text.include?('User administration')).to be true
127
+ element = browser.link(text: 'Link 3')
128
+ element.wait_until { |link| !link.exist? || link.click }
129
+ expect(browser.h1(text: 'User administration')).to exist
130
130
  end
131
131
 
132
132
  it 'finds an existing link by (text: Regexp) and clicks it' do
133
- browser.link(href: /forms_with_input_elements/).click
134
- expect(browser.text.include?('User administration')).to be true
133
+ element = browser.link(href: /forms_with_input_elements/)
134
+ element.wait_until { |link| !link.exist? || link.click }
135
+ expect(browser.h1(text: 'User administration')).to exist
135
136
  end
136
137
 
137
- bug 'sometimes safari does not work on the first click', :safari do
138
- it 'finds an existing link by (index: Integer) and clicks it' do
139
- browser.link(index: 2).click
140
- expect(browser.text.include?('User administration')).to be true
141
- end
138
+ it 'finds an existing link by (index: Integer) and clicks it' do
139
+ element = browser.link(index: 2)
140
+ element.wait_until { |link| !link.exist? || link.click }
141
+ expect(browser.h1(text: 'User administration')).to exist
142
142
  end
143
143
 
144
144
  it "raises an UnknownObjectException if the link doesn't exist" do
145
145
  expect { browser.link(index: 1337).click }.to raise_unknown_object_exception
146
146
  end
147
147
 
148
- bug 'Safari throws a not interactable error', :safari do
149
- it 'clicks a link with no text content but an img child' do
150
- browser.goto WatirSpec.url_for('images.html')
151
- browser.link(href: /definition_lists.html/).click
152
- Watir::Wait.while { browser.title == 'Images' || browser.title == '' }
153
- expect(browser.title).to eq 'definition_lists'
154
- end
148
+ it 'clicks a link with no text content but an img child',
149
+ except: {browser: :safari, reason: 'Safari throws a not interactable error'} do
150
+ browser.goto WatirSpec.url_for('images.html')
151
+ browser.link(href: /definition_lists.html/).click
152
+ browser.wait_while(title: /^(Images|)$/)
153
+ expect(browser.title).to eq 'definition_lists'
155
154
  end
156
155
  end
157
156
 
@@ -167,14 +166,13 @@ describe 'Link' do
167
166
  expect(browser.link(visible_text: /Link 2/, class: 'external')).to exist
168
167
  end
169
168
 
170
- bug 'Safari is not filtering out hidden text', :safari do
171
- it 'finds links in spite of hidden text' do
172
- browser.goto WatirSpec.url_for('non_control_elements.html')
169
+ it 'finds links in spite of hidden text',
170
+ except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
171
+ browser.goto WatirSpec.url_for('non_control_elements.html')
173
172
 
174
- expect(browser.link(visible_text: 'some visible')).to exist
175
- expect(browser.link(visible_text: 'none visible')).not_to exist
176
- expect(browser.link(visible_text: /none visible/)).not_to exist
177
- end
173
+ expect(browser.link(visible_text: 'some visible')).to exist
174
+ expect(browser.link(visible_text: 'none visible')).not_to exist
175
+ expect(browser.link(visible_text: /none visible/)).not_to exist
178
176
  end
179
177
 
180
178
  it 'raises exception unless value is a String or a RegExp' do
@@ -49,15 +49,14 @@ describe 'Links' do
49
49
  expect(container.links(visible_text: /some visible/).count).to eq(1)
50
50
  end
51
51
 
52
- bug 'Safari is not filtering out hidden text', :safari do
53
- it 'finds links in spite of hidden text' do
54
- browser.goto WatirSpec.url_for('non_control_elements.html')
55
- container = browser.div(id: 'visible_text')
56
-
57
- expect(container.divs(visible_text: 'some visible').count).to eq(1)
58
- expect(container.divs(visible_text: 'none visible').count).to eq(0)
59
- expect(container.divs(visible_text: /none visible/).count).to eq(0)
60
- end
52
+ it 'finds links in spite of hidden text',
53
+ except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
54
+ browser.goto WatirSpec.url_for('non_control_elements.html')
55
+ container = browser.div(id: 'visible_text')
56
+
57
+ expect(container.divs(visible_text: 'some visible').count).to eq(1)
58
+ expect(container.divs(visible_text: 'none visible').count).to eq(0)
59
+ expect(container.divs(visible_text: /none visible/).count).to eq(0)
61
60
  end
62
61
  end
63
62
  end
@@ -205,20 +205,17 @@ describe 'Radio' do
205
205
  expect(messages).to eq ['clicked: new_user_newsletter_no', 'clicked: new_user_newsletter_yes']
206
206
  end
207
207
 
208
- # http://webbugtrack.blogspot.com/2007/11/bug-193-onchange-does-not-fire-properly.html
209
- not_compliant_on :internet_explorer do
210
- it 'fires the onchange event' do
211
- browser.radio(value: 'certainly').set
212
- expect(messages).to eq ['changed: new_user_newsletter']
213
-
214
- browser.radio(value: 'certainly').set
215
- expect(messages).to eq ['changed: new_user_newsletter'] # no event fired here - didn't change
216
-
217
- browser.radio(value: 'yes').set
218
- browser.radio(value: 'certainly').set
219
- list = ['changed: new_user_newsletter', 'clicked: new_user_newsletter_yes', 'changed: new_user_newsletter']
220
- expect(messages).to eq list
221
- end
208
+ it 'fires the onchange event' do
209
+ browser.radio(value: 'certainly').set
210
+ expect(messages).to eq ['changed: new_user_newsletter']
211
+
212
+ browser.radio(value: 'certainly').set
213
+ expect(messages).to eq ['changed: new_user_newsletter'] # no event fired here - didn't change
214
+
215
+ browser.radio(value: 'yes').set
216
+ browser.radio(value: 'certainly').set
217
+ list = ['changed: new_user_newsletter', 'clicked: new_user_newsletter_yes', 'changed: new_user_newsletter']
218
+ expect(messages).to eq list
222
219
  end
223
220
 
224
221
  it "raises UnknownObjectException if the radio button doesn't exist" do
@@ -220,107 +220,192 @@ describe 'SelectList' do
220
220
  end
221
221
 
222
222
  describe '#selected?' do
223
- it 'returns true if the given option is selected by text' do
224
- browser.select_list(name: 'new_user_country').select('Denmark')
223
+ it 'evaluates true by text' do
224
+ browser.select_list(name: 'new_user_country').select('1')
225
225
  expect(browser.select_list(name: 'new_user_country')).to be_selected('Denmark')
226
226
  end
227
227
 
228
- it 'returns false if the given option is not selected by text' do
228
+ it 'evaluates false by text' do
229
229
  expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Sweden')
230
230
  end
231
231
 
232
- it 'returns true if the given option is selected by label' do
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')
235
+ end
236
+
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
240
+
241
+ it 'evaluates true by label' do
233
242
  browser.select_list(name: 'new_user_country').select('Germany')
234
243
  expect(browser.select_list(name: 'new_user_country')).to be_selected('Germany')
235
244
  end
236
245
 
237
- it 'returns false if the given option is not selected by label' do
246
+ it 'evaluates false by label' do
238
247
  expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Germany')
239
248
  end
240
249
 
241
- it "raises UnknownObjectException if the option doesn't exist" do
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
254
+
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
258
+
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
263
+
264
+ it 'evaluates false by value' do
265
+ expect(browser.select_list(name: 'new_user_country')).to_not be_selected('5')
266
+ end
267
+
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
272
+
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
276
+
277
+ it "raises NoValueFoundException if the option doesn't exist" do
242
278
  expect { browser.select_list(name: 'new_user_country').selected?('missing_option') }
243
- .to raise_unknown_object_exception
279
+ .to raise_no_value_found_exception
244
280
  end
245
281
  end
246
282
 
247
- describe '#select' do
248
- context 'when finding by value' do
249
- it 'selects an option with a String' do
250
- browser.select_list(name: 'new_user_languages').clear
251
- browser.select_list(name: 'new_user_languages').select('2')
252
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
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
253
288
  end
254
289
 
255
- it 'selects an option with a Regexp' do
256
- browser.select_list(name: 'new_user_languages').clear
257
- browser.select_list(name: 'new_user_languages').select(/2|3/)
258
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
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
295
+
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
300
+
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'
304
+ end
305
+
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'
309
+ end
310
+
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'
314
+ end
315
+
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'
319
+ end
259
320
  end
260
- end
261
321
 
262
- context 'when finding by text' do
263
- it 'selects an option with a String' do
264
- browser.select_list(name: 'new_user_country').select('Denmark')
265
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Denmark']
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'
326
+ end
327
+
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'
331
+ end
332
+
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'
336
+ end
337
+
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'
341
+ end
266
342
  end
267
343
 
268
- it 'selects an option with a Regexp' do
269
- browser.select_list(name: 'new_user_country').select(/Denmark/)
270
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Denmark']
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'
348
+ end
349
+
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'
353
+ end
354
+
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
359
+
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'
363
+ end
271
364
  end
272
- end
273
365
 
274
- context 'when finding by label' do
275
- it 'selects an option with a String' do
276
- browser.select_list(name: 'new_user_languages').clear
277
- browser.select_list(name: 'new_user_languages').select('NO')
278
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq ['NO']
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]
279
370
  end
280
371
 
281
- it 'selects an option with a Regexp' do
282
- browser.select_list(name: 'new_user_languages').clear
283
- browser.select_list(name: 'new_user_languages').select(/^N/)
284
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq ['NO']
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]
285
375
  end
286
- end
287
376
 
288
- it 'selects multiple options successively' do
289
- browser.select_list(name: 'new_user_languages').clear
290
- browser.select_list(name: 'new_user_languages').select('Danish')
291
- browser.select_list(name: 'new_user_languages').select('Swedish')
292
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
293
- end
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
294
381
 
295
- bug 'Safari is returning click intercepted error', :safari do
296
- it 'selects empty options' do
382
+ it 'selects empty options',
383
+ except: {browser: :safari, reason: 'Safari throwing ElementNotInteractableError'} do
297
384
  browser.select_list(id: 'delete_user_username').select('')
298
385
  expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
299
386
  end
300
- end
301
387
 
302
- it 'returns the value selected' do
303
- expect(browser.select_list(name: 'new_user_languages').select('Danish')).to eq 'Danish'
304
- end
388
+ it 'returns the value selected' do
389
+ expect(@select_list.select('Danish')).to eq 'Danish'
390
+ end
305
391
 
306
- it 'fires onchange event when selecting an item' do
307
- browser.select_list(id: 'new_user_languages').select('Danish')
308
- expect(messages).to eq ['changed language']
309
- end
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
310
396
 
311
- it "doesn't fire onchange event when selecting an already selected item" do
312
- browser.select_list(id: 'new_user_languages').clear # removes the two pre-selected options
313
- browser.select_list(id: 'new_user_languages').select('English')
314
- expect(messages.size).to eq 3
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
315
400
 
316
- browser.select_list(id: 'new_user_languages').select('English')
317
- expect(messages.size).to eq 3
401
+ @select_list.select('English')
402
+ expect(messages.size).to eq 3
403
+ end
318
404
  end
319
405
 
320
- bug 'Safari is returning click intercepted error', :safari do
321
- it 'returns an empty string when selecting an option that disappears when selected' do
322
- expect(browser.select_list(id: 'obsolete').select('sweden')).to eq ''
323
- end
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 ''
324
409
  end
325
410
 
326
411
  it 'selects options with a single-quoted value' do
@@ -342,15 +427,13 @@ describe 'SelectList' do
342
427
  .to raise_no_value_found_exception message
343
428
  end
344
429
 
345
- bug 'Safari is returning object enabled instead of disabled', :safari do
346
- it 'raises ObjectDisabledException if the option is disabled' do
347
- expect { browser.select_list(name: 'new_user_languages').select('Russian') }
348
- .to raise_object_disabled_exception
349
- end
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
350
433
  end
351
434
 
352
435
  it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
353
- expect { browser.select_list(id: 'new_user_languages').select({}) }.to raise_error(TypeError)
436
+ expect { browser.select_list(id: 'new_user_languages').select(true) }.to raise_error(TypeError)
354
437
  end
355
438
 
356
439
  context 'multiple options' do
@@ -408,61 +491,112 @@ describe 'SelectList' do
408
491
  end
409
492
 
410
493
  describe '#select!' do
411
- context 'when finding by value' do
412
- it 'selects an option with a String' do
413
- browser.select_list(name: 'new_user_languages').clear
414
- browser.select_list(name: 'new_user_languages').select!('2')
415
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
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
416
498
  end
417
499
 
418
- it 'selects an option with a Regex' do
419
- browser.select_list(name: 'new_user_languages').clear
420
- browser.select_list(name: 'new_user_languages').select!(/2/)
421
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
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'
504
+ end
505
+
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'
509
+ end
510
+
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'
514
+ end
515
+
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'
519
+ end
520
+
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'
524
+ end
525
+
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'
529
+ end
422
530
  end
423
- end
424
531
 
425
- context 'when finding by text' do
426
- it 'selects an option with a String' do
427
- browser.select_list(name: 'new_user_country').select!('Denmark')
428
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Denmark']
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'
536
+ end
537
+
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'
541
+ end
542
+
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'
546
+ end
547
+
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'
551
+ end
429
552
  end
430
553
 
431
- it 'selects an option with a Regexp' do
432
- browser.select_list(name: 'new_user_country').select!(/Denmark/)
433
- expect(browser.select_list(name: 'new_user_country').selected_options.map(&:text)).to eq ['Denmark']
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'
558
+ end
559
+
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'
563
+ end
564
+
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'
568
+ end
569
+
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'
573
+ end
434
574
  end
435
- end
436
575
 
437
- context 'when finding by label' do
438
- it 'selects an option with a String' do
439
- browser.select_list(name: 'new_user_languages').clear
440
- browser.select_list(name: 'new_user_languages').select!('NO')
441
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq ['NO']
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]
442
580
  end
443
581
 
444
- it 'selects an option with a Regexp' do
445
- browser.select_list(name: 'new_user_languages').clear
446
- browser.select_list(name: 'new_user_languages').select!(/NO/)
447
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq ['NO']
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]
448
585
  end
449
- end
450
586
 
451
- it 'selects multiple items successively' do
452
- browser.select_list(name: 'new_user_languages').clear
453
- browser.select_list(name: 'new_user_languages').select!('Danish')
454
- browser.select_list(name: 'new_user_languages').select!('Swedish')
455
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[Danish Swedish]
456
- end
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]
590
+ end
457
591
 
458
- it 'selects empty options' do
459
- browser.select_list(id: 'delete_user_username').select!('')
460
- expect(browser.select_list(id: 'delete_user_username').selected_options.map(&:text)).to eq ['']
461
- end
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 ['']
595
+ end
462
596
 
463
- it 'returns the value selected' do
464
- browser.select_list(name: 'new_user_languages').clear
465
- expect(browser.select_list(name: 'new_user_languages').select!('Danish')).to eq 'Danish'
597
+ it 'returns the value selected' do
598
+ expect(@select_list.select!('Danish')).to eq 'Danish'
599
+ end
466
600
  end
467
601
 
468
602
  it 'selects options with a single-quoted value' do
@@ -484,17 +618,14 @@ describe 'SelectList' do
484
618
  .to raise_no_value_found_exception
485
619
  end
486
620
 
487
- bug 'Safari is returning object enabled instead of disabled', :safari do
488
- it 'raises ObjectDisabledException if the option is disabled' do
489
- browser.select_list(id: 'new_user_languages').clear
490
- expect { browser.select_list(id: 'new_user_languages').select!('Russian') }
491
- .to raise_object_disabled_exception
492
- end
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
493
625
  end
494
626
 
495
627
  it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
496
- browser.select_list(id: 'new_user_languages').clear
497
- expect { browser.select_list(id: 'new_user_languages').select!({}) }.to raise_error(TypeError)
628
+ expect { browser.select_list(id: 'new_user_languages').select!(true) }.to raise_error(TypeError)
498
629
  end
499
630
 
500
631
  context 'multiple options' do