-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
select_list_spec.rb
66 lines (50 loc) · 2.19 KB
/
select_list_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Select List' do
let(:driver) { start_session }
before do
driver.get('https://www.selenium.dev/selenium/web/formPage.html')
end
it 'select options' do
select_element = driver.find_element(name: 'selectomatic')
select = Selenium::WebDriver::Support::Select.new(select_element)
two_element = driver.find_element(css: 'option[value=two]')
four_element = driver.find_element(css: 'option[value=four]')
count_element = driver.find_element(css: "option[value='still learning how to count, apparently']")
select.select_by(:text, 'Four')
expect(four_element).to be_selected
select.select_by(:value, 'two')
expect(two_element).to be_selected
select.select_by(:index, 3)
expect(count_element).to be_selected
end
it 'select multiple options' do
select_element = driver.find_element(name: 'multi')
select = Selenium::WebDriver::Support::Select.new(select_element)
ham_element = driver.find_element(css: 'option[value=ham]')
gravy_element = driver.find_element(css: "option[value='onion gravy']")
egg_element = driver.find_element(css: 'option[value=eggs]')
sausage_element = driver.find_element(css: "option[value='sausages']")
option_elements = select_element.find_elements(tag_name: 'option')
option_list = select.options
expect(option_elements).to eq option_list
selected_option_list = select.selected_options
expected_selection = [egg_element, sausage_element]
expect(selected_option_list).to eq expected_selection
select.select_by(:value, 'ham')
select.select_by(:value, 'onion gravy')
expect(ham_element).to be_selected
expect(gravy_element).to be_selected
select.deselect_by(:value, 'eggs')
select.deselect_by(:value, 'sausages')
expect(egg_element).not_to be_selected
expect(sausage_element).not_to be_selected
end
it 'disabled options' do
select_element = driver.find_element(name: 'single_disabled')
select = Selenium::WebDriver::Support::Select.new(select_element)
expect {
select.select_by(:value, 'disabled')
}.to raise_exception(Selenium::WebDriver::Error::UnsupportedOperationError)
end
end