Adding Locator#locate! method for error raising
This commit is contained in:
parent
53ba0cc691
commit
87a4ff91ca
@ -22,11 +22,5 @@ module Webrat
|
||||
@session.elements[Webrat::XML.xpath_to(element)]
|
||||
end
|
||||
|
||||
def field(*args) # :nodoc:
|
||||
# This is the default locator strategy
|
||||
FieldLocator.new(self, *args).locate ||
|
||||
raise(NotFoundError.new("Could not find field: #{args.inspect}"))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -24,11 +24,14 @@ module Webrat
|
||||
Webrat::XML.css_search(@scope.dom, "area")
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find area with name #{@value}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def find_area(id_or_title) #:nodoc:
|
||||
AreaLocator.new(self, id_or_title).locate ||
|
||||
raise(NotFoundError.new("Could not find area with name #{id_or_title}"))
|
||||
AreaLocator.new(self, id_or_title).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -40,11 +40,14 @@ module Webrat
|
||||
Webrat::XML.xpath_search(@scope.dom, *ButtonField.xpath_search)
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find button #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def find_button(value) #:nodoc:
|
||||
ButtonLocator.new(self, value).locate ||
|
||||
raise(NotFoundError.new("Could not find button #{value.inspect}"))
|
||||
ButtonLocator.new(self, value).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -23,11 +23,14 @@ module Webrat
|
||||
Webrat::XML.xpath_search(@scope.dom, *Field.xpath_search)
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find field with id #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def field_with_id(id, *field_types)
|
||||
FieldByIdLocator.new(self, id, *field_types).locate ||
|
||||
raise(NotFoundError.new("Could not find field with id #{id.inspect}"))
|
||||
FieldByIdLocator.new(self, id, *field_types).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,11 +12,14 @@ module Webrat
|
||||
end
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find field labeled #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def field_labeled(label, *field_types)
|
||||
FieldLabeledLocator.new(self, label, *field_types).locate ||
|
||||
raise(NotFoundError.new("Could not find field labeled #{label.inspect}"))
|
||||
FieldLabeledLocator.new(self, label, *field_types).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -11,6 +11,14 @@ module Webrat
|
||||
FieldLabeledLocator.new(@scope, @value, *@field_types).locate
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find field: #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def field(*args) # :nodoc:
|
||||
FieldLocator.new(self, *args).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -27,11 +27,14 @@ module Webrat
|
||||
end
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find field named #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def field_named(name, *field_types)
|
||||
FieldNamedLocator.new(self, name, *field_types).locate ||
|
||||
raise(NotFoundError.new("Could not find field named #{name.inspect}"))
|
||||
FieldNamedLocator.new(self, name, *field_types).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -52,11 +52,14 @@ module Webrat
|
||||
str.gsub(' ',' ').gsub(' ', ' ')
|
||||
end
|
||||
|
||||
def error_message
|
||||
"Could not find link with text or title or id #{@value.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def find_link(text_or_title_or_id) #:nodoc:
|
||||
LinkLocator.new(self, text_or_title_or_id).locate ||
|
||||
raise(NotFoundError.new("Could not find link with text or title or id #{text_or_title_or_id.inspect}"))
|
||||
LinkLocator.new(self, text_or_title_or_id).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -9,6 +9,10 @@ module Webrat
|
||||
@field_types = field_types
|
||||
end
|
||||
|
||||
def locate!
|
||||
locate || raise(NotFoundError.new(error_message))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -23,18 +23,18 @@ module Webrat
|
||||
end
|
||||
end
|
||||
|
||||
def error_message
|
||||
if @id_or_name_or_label
|
||||
"The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
|
||||
else
|
||||
"Could not find option #{@option_text.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def find_select_option(option_text, id_or_name_or_label) #:nodoc:
|
||||
option = SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate
|
||||
return option if option
|
||||
|
||||
if id_or_name_or_label
|
||||
select_box_text = " in the #{id_or_name_or_label.inspect} select box"
|
||||
raise NotFoundError.new("The '#{option_text}' option was not found#{select_box_text}")
|
||||
else
|
||||
raise NotFoundError.new("Could not find option #{option_text.inspect}")
|
||||
end
|
||||
SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate!
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user