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)]
|
@session.elements[Webrat::XML.xpath_to(element)]
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
@ -24,11 +24,14 @@ module Webrat
|
|||||||
Webrat::XML.css_search(@scope.dom, "area")
|
Webrat::XML.css_search(@scope.dom, "area")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find area with name #{@value}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_area(id_or_title) #:nodoc:
|
def find_area(id_or_title) #:nodoc:
|
||||||
AreaLocator.new(self, id_or_title).locate ||
|
AreaLocator.new(self, id_or_title).locate!
|
||||||
raise(NotFoundError.new("Could not find area with name #{id_or_title}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -40,11 +40,14 @@ module Webrat
|
|||||||
Webrat::XML.xpath_search(@scope.dom, *ButtonField.xpath_search)
|
Webrat::XML.xpath_search(@scope.dom, *ButtonField.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find button #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_button(value) #:nodoc:
|
def find_button(value) #:nodoc:
|
||||||
ButtonLocator.new(self, value).locate ||
|
ButtonLocator.new(self, value).locate!
|
||||||
raise(NotFoundError.new("Could not find button #{value.inspect}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,12 +22,15 @@ module Webrat
|
|||||||
def field_elements
|
def field_elements
|
||||||
Webrat::XML.xpath_search(@scope.dom, *Field.xpath_search)
|
Webrat::XML.xpath_search(@scope.dom, *Field.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find field with id #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_with_id(id, *field_types)
|
def field_with_id(id, *field_types)
|
||||||
FieldByIdLocator.new(self, id, *field_types).locate ||
|
FieldByIdLocator.new(self, id, *field_types).locate!
|
||||||
raise(NotFoundError.new("Could not find field with id #{id.inspect}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,11 +12,14 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find field labeled #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_labeled(label, *field_types)
|
def field_labeled(label, *field_types)
|
||||||
FieldLabeledLocator.new(self, label, *field_types).locate ||
|
FieldLabeledLocator.new(self, label, *field_types).locate!
|
||||||
raise(NotFoundError.new("Could not find field labeled #{label.inspect}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,15 @@ module Webrat
|
|||||||
FieldNamedLocator.new(@scope, @value, *@field_types).locate ||
|
FieldNamedLocator.new(@scope, @value, *@field_types).locate ||
|
||||||
FieldLabeledLocator.new(@scope, @value, *@field_types).locate
|
FieldLabeledLocator.new(@scope, @value, *@field_types).locate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find field: #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def field(*args) # :nodoc:
|
||||||
|
FieldLocator.new(self, *args).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -27,11 +27,14 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find field named #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_named(name, *field_types)
|
def field_named(name, *field_types)
|
||||||
FieldNamedLocator.new(self, name, *field_types).locate ||
|
FieldNamedLocator.new(self, name, *field_types).locate!
|
||||||
raise(NotFoundError.new("Could not find field named #{name.inspect}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -52,11 +52,14 @@ module Webrat
|
|||||||
str.gsub(' ',' ').gsub(' ', ' ')
|
str.gsub(' ',' ').gsub(' ', ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
"Could not find link with text or title or id #{@value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_link(text_or_title_or_id) #:nodoc:
|
def find_link(text_or_title_or_id) #:nodoc:
|
||||||
LinkLocator.new(self, text_or_title_or_id).locate ||
|
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}"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,10 @@ module Webrat
|
|||||||
@field_types = field_types
|
@field_types = field_types
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def locate!
|
||||||
|
locate || raise(NotFoundError.new(error_message))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,19 +22,19 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def find_select_option(option_text, id_or_name_or_label) #:nodoc:
|
def find_select_option(option_text, id_or_name_or_label) #:nodoc:
|
||||||
option = SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate
|
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user