Better error messages when fields/links/buttons not found
This commit is contained in:
parent
49574fa922
commit
0acee560a2
|
@ -80,20 +80,26 @@ private
|
|||
end
|
||||
|
||||
def find_link(locator)
|
||||
find_element("//a[@id='#{locator}']", %{//a[text()="#{locator}"]}, %{//a[@title="#{locator}"]})
|
||||
link = find_element("//a[@id='#{locator}']", %{//a[text()="#{locator}"]}, %{//a[@title="#{locator}"]})
|
||||
raise Webcat::ElementNotFound, "no button with value or id '#{locator}' found" unless link
|
||||
link
|
||||
end
|
||||
|
||||
def find_button(locator)
|
||||
find_element(
|
||||
button = find_element(
|
||||
"//input[@type='submit'][@id='#{locator}']",
|
||||
"//input[@type='submit'][@value='#{locator}']",
|
||||
"//input[@type='image'][@id='#{locator}']",
|
||||
"//input[@type='image'][@value='#{locator}']"
|
||||
)
|
||||
raise Webcat::ElementNotFound, "no link with title, id or text '#{locator}' found" unless button
|
||||
button
|
||||
end
|
||||
|
||||
def find_field(locator, *kinds)
|
||||
find_field_by_id(locator, *kinds) or find_field_by_label(locator, *kinds)
|
||||
field = find_field_by_id(locator, *kinds) || find_field_by_label(locator, *kinds)
|
||||
raise Webcat::ElementNotFound, "no field of kind #{kinds.inspect} with id or'#{locator}' found" unless field
|
||||
field
|
||||
end
|
||||
|
||||
FIELDS_PATHS = {
|
||||
|
@ -132,7 +138,7 @@ private
|
|||
element = find(locator).first
|
||||
return element if element
|
||||
end
|
||||
raise Webcat::ElementNotFound, "element not found"
|
||||
return nil
|
||||
end
|
||||
|
||||
def find(locator)
|
||||
|
|
|
@ -144,6 +144,14 @@ shared_examples_for "session" do
|
|||
extract_results(@session)['first_name'].should == 'John'
|
||||
end
|
||||
end
|
||||
|
||||
context "with a locator that doesn't exist" do
|
||||
it "should raise an error" do
|
||||
running do
|
||||
@session.click_button('does not exist')
|
||||
end.should raise_error(Webcat::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
it "should follow redirects" do
|
||||
@session.click_button('Go FAR')
|
||||
|
@ -193,6 +201,14 @@ shared_examples_for "session" do
|
|||
@session.click_button('awesome')
|
||||
extract_results(@session)['password'].should == 'supasikrit'
|
||||
end
|
||||
|
||||
context "with a locator that doesn't exist" do
|
||||
it "should raise an error" do
|
||||
running do
|
||||
@session.fill_in('does not exist', :with => 'Blah blah')
|
||||
end.should raise_error(Webcat::ElementNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#choose" do
|
||||
|
|
Loading…
Reference in New Issue