warn when attempting to select a disabled option
This commit is contained in:
parent
ae662272f6
commit
7932c2e429
|
@ -114,6 +114,7 @@ module Capybara
|
|||
# Select this node if is an option element inside a select tag
|
||||
#
|
||||
def select_option
|
||||
warn "Attempt to select disabled option: #{value || text}" if disabled?
|
||||
synchronize { base.select_option }
|
||||
end
|
||||
|
||||
|
@ -148,7 +149,7 @@ module Capybara
|
|||
def double_click
|
||||
synchronize { base.double_click }
|
||||
end
|
||||
|
||||
|
||||
##
|
||||
#
|
||||
# Send Keystrokes to the Element
|
||||
|
@ -215,7 +216,7 @@ module Capybara
|
|||
# :f10
|
||||
# :f11
|
||||
# :f12
|
||||
# :meta
|
||||
# :meta
|
||||
# :command - alias of :meta
|
||||
#
|
||||
def send_keys(*args)
|
||||
|
|
|
@ -36,6 +36,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|||
end
|
||||
|
||||
def select_option
|
||||
return if disabled?
|
||||
if select_node['multiple'] != 'multiple'
|
||||
select_node.find_xpath(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
|
||||
end
|
||||
|
|
|
@ -108,6 +108,18 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
end
|
||||
|
||||
context "on a disabled option" do
|
||||
it "should not select" do
|
||||
@session.select('Other', :from => 'form_title')
|
||||
expect(@session.find_field('form_title').value).not_to eq 'Other'
|
||||
end
|
||||
|
||||
it "should warn" do
|
||||
expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once
|
||||
@session.select('Other', :from => 'form_title')
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple select" do
|
||||
it "should return an empty value" do
|
||||
expect(@session.find_field('Language').value).to eq([])
|
||||
|
|
Loading…
Reference in New Issue