1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

add useful error message to locate when specifying a :css or :xpath. fixes #96

This commit is contained in:
Joseph Anthony Pasquale Holsten 2010-06-30 12:26:46 -05:00 committed by Jonas Nicklas
parent a1a13d06e4
commit 35e81a434f
2 changed files with 7 additions and 1 deletions

View file

@ -237,7 +237,7 @@ module Capybara
def locate(kind_or_locator, locator=nil, fail_msg = nil)
node = wait_conditionally_until { find(kind_or_locator, locator) }
ensure
raise Capybara::ElementNotFound, fail_msg || "Unable to locate '#{kind_or_locator}'" unless node
raise Capybara::ElementNotFound, fail_msg || "Unable to locate '#{locator || kind_or_locator}'" unless node
return node
end

View file

@ -38,6 +38,12 @@ shared_examples_for "locate" do
end.should raise_error(Capybara::ElementNotFound, "arghh")
end
it "should raise ElementNotFound with a useful default message if nothing was found" do
running do
@session.locate(:xpath, '//div[@id="nosuchthing"]').should be_nil
end.should raise_error(Capybara::ElementNotFound, "Unable to locate '//div[@id=\"nosuchthing\"]'")
end
it "should accept an XPath instance and respect the order of paths" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')