Skip to content

Commit

Permalink
Revert "[rb] do not allow Select class to work with disabled selects"
Browse files Browse the repository at this point in the history
This reverts commit 3b691c4.
  • Loading branch information
titusfortner committed Oct 28, 2022
1 parent 833b0a0 commit fe4c149
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
5 changes: 1 addition & 4 deletions rb/lib/selenium/webdriver/support/select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ class Select
#

def initialize(element)
unless element.enabled?
raise Error::UnsupportedOperationError, 'Select element is disabled and may not be used.'
end

tag_name = element.tag_name

raise ArgumentError, "unexpected tag name #{tag_name.inspect}" unless tag_name.casecmp('select').zero?

@element = element
Expand Down
5 changes: 0 additions & 5 deletions rb/spec/integration/selenium/webdriver/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ module Support
it 'raises exception if not a select element' do
expect { Select.new(driver.find_element(id: 'checky')) }.to raise_exception(ArgumentError)
end

it 'raises exception if select is not enabled' do
no_select = driver.find_element(name: 'no-select')
expect { Select.new(no_select) }.to raise_exception(Error::UnsupportedOperationError)
end
end

describe '#multiple?' do
Expand Down
44 changes: 22 additions & 22 deletions rb/spec/unit/selenium/webdriver/support/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ module WebDriver
module Support
describe Select do
let(:select) do
select_element = instance_double(Element, tag_name: 'select', enabled?: true)
select_element = instance_double(Element, tag_name: 'select')
allow(select_element).to receive(:dom_attribute).with(:multiple)
select_element
end

let(:multi_select) do
select_element = instance_double(Element, tag_name: 'select', enabled?: true)
select_element = instance_double(Element, tag_name: 'select')
allow(select_element).to receive(:dom_attribute).with(:multiple).and_return 'multiple'
select_element
end

it 'raises ArgumentError if passed a non-select Element' do
link = instance_double(Element, tag_name: 'a', enabled?: true)
link = instance_double(Element, tag_name: 'a')

expect {
Select.new link
}.to raise_error(ArgumentError)
end

it 'indicates whether a select is multiple correctly' do
selects = Array.new(4) { instance_double(Element, tag_name: 'select', enabled?: true) }
selects = Array.new(4) { instance_double(Element, tag_name: 'select') }

allow(selects[0]).to receive(:dom_attribute).with(:multiple).and_return('false')
allow(selects[1]).to receive(:dom_attribute).with(:multiple).and_return(nil)
Expand All @@ -69,8 +69,8 @@ module Support
end

it 'returns all selected options' do
bad_option = instance_double(Element, selected?: false, enabled?: true)
good_option = instance_double(Element, selected?: true, enabled?: true)
bad_option = instance_double(Element, selected?: false)
good_option = instance_double(Element, selected?: true)

expect(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
Expand All @@ -84,8 +84,8 @@ module Support
end

it 'returns the first selected option' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, selected?: true, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: true)

expect(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
Expand All @@ -97,7 +97,7 @@ module Support
end

it 'raises a NoSuchElementError if nothing is selected' do
option = instance_double(Element, selected?: false, enabled?: true)
option = instance_double(Element, selected?: false)

expect(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
Expand All @@ -110,7 +110,7 @@ module Support
end

it 'allows options to be selected by visible text' do
option = instance_double(Element, selected?: false, enabled?: true)
option = instance_double(Element, selected?: false)

expect(multi_select).to receive(:find_elements)
.with(xpath: './/option[normalize-space(.) = "fish"]')
Expand All @@ -123,8 +123,8 @@ module Support
end

it 'allows options to be selected by index' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, selected?: false, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: false)

allow(first_option).to receive(:property).with(:index).and_return 0
expect(first_option).not_to receive(:click)
Expand All @@ -143,7 +143,7 @@ module Support
end

it 'allows options to be selected by returned value' do
first_option = instance_double(Element, selected?: false, enabled?: true)
first_option = instance_double(Element, selected?: false)
allow(multi_select).to receive(:find_elements)
.with(xpath: './/option[@value = "b"]')
.and_return([first_option])
Expand All @@ -155,8 +155,8 @@ module Support
end

it 'can deselect all when select supports multiple selections' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, selected?: false, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: false)

expect(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
Expand All @@ -176,8 +176,8 @@ module Support
end

it 'can deselect options by visible text' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, selected?: false, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: false)

allow(multi_select).to receive(:find_elements)
.with(xpath: './/option[normalize-space(.) = "b"]')
Expand All @@ -191,8 +191,8 @@ module Support
end

it 'can deselect options by index' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element)

allow(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
Expand All @@ -209,8 +209,8 @@ module Support
end

it 'can deselect options by returned value' do
first_option = instance_double(Element, selected?: true, enabled?: true)
second_option = instance_double(Element, selected?: false, enabled?: true)
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: false)

allow(multi_select).to receive(:find_elements)
.with(xpath: './/option[@value = "b"]')
Expand All @@ -224,7 +224,7 @@ module Support
end

it 'should fall back to slow lookups when "get by visible text fails" and there is a space' do
first_option = instance_double(Element, selected?: false, text: 'foo bar', enabled?: true)
first_option = instance_double(Element, selected?: false, text: 'foo bar')

xpath1 = './/option[normalize-space(.) = "foo bar"]'
xpath2 = './/option[contains(., "foo")]'
Expand Down

0 comments on commit fe4c149

Please sign in to comment.