Nicer warnings when option not found for select
This commit is contained in:
parent
c9ca5cab5d
commit
297dd7349b
|
@ -7,6 +7,7 @@ module Capybara
|
||||||
class CapybaraError < StandardError; end
|
class CapybaraError < StandardError; end
|
||||||
class DriverNotFoundError < CapybaraError; end
|
class DriverNotFoundError < CapybaraError; end
|
||||||
class ElementNotFound < CapybaraError; end
|
class ElementNotFound < CapybaraError; end
|
||||||
|
class OptionNotFound < ElementNotFound; end
|
||||||
class NotSupportedByDriverError < CapybaraError; end
|
class NotSupportedByDriverError < CapybaraError; end
|
||||||
class TimeoutError < CapybaraError; end
|
class TimeoutError < CapybaraError; end
|
||||||
class InfiniteRedirectError < TimeoutError; end
|
class InfiniteRedirectError < TimeoutError; end
|
||||||
|
|
|
@ -19,6 +19,9 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
|
|
||||||
def select(option)
|
def select(option)
|
||||||
node.select(option)
|
node.select(option)
|
||||||
|
rescue
|
||||||
|
options = all(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
|
||||||
|
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def click
|
def click
|
||||||
|
|
|
@ -33,7 +33,12 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
|
|
||||||
def select(option)
|
def select(option)
|
||||||
node.xpath(".//option").each { |node| node.remove_attribute("selected") }
|
node.xpath(".//option").each { |node| node.remove_attribute("selected") }
|
||||||
node.xpath(".//option[contains(.,'#{option}')]").first["selected"] = 'selected'
|
if option_node = node.xpath(".//option[contains(.,'#{option}')]").first
|
||||||
|
option_node["selected"] = 'selected'
|
||||||
|
else
|
||||||
|
options = node.xpath(".//option").map { |o| "'#{o.text}'" }.join(', ')
|
||||||
|
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def click
|
def click
|
||||||
|
|
|
@ -29,6 +29,9 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
||||||
|
|
||||||
def select(option)
|
def select(option)
|
||||||
node.find_element(:xpath, ".//option[contains(.,'#{option}')]").select
|
node.find_element(:xpath, ".//option[contains(.,'#{option}')]").select
|
||||||
|
rescue
|
||||||
|
options = node.find_elements(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
|
||||||
|
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def click
|
def click
|
||||||
|
|
|
@ -21,5 +21,11 @@ shared_examples_for "select" do
|
||||||
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
|
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with an option that doesn't exist" do
|
||||||
|
it "should raise an error" do
|
||||||
|
running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue