Switching FieldLabeledLocator to use elements

This commit is contained in:
Bryan Helmkamp 2008-11-30 14:59:33 -05:00
parent 28bd5f2533
commit e72bba29c7
4 changed files with 22 additions and 15 deletions

View File

@ -21,5 +21,17 @@ module Webrat
Webrat::XML.attribute(@element, "for")
end
def field
Field.load(@session, field_element)
end
def field_element
if for_id.blank?
Webrat::XML.xpath_at(@element, *Field.xpath_search)
else
Webrat::XML.css_search(@session.dom, "#" + for_id).first
end
end
end
end

View File

@ -21,7 +21,7 @@ module Webrat
end
def area_elements
Webrat::XML.css_search(@scope.dom, "area")
Webrat::XML.xpath_search(@scope.dom, Area.xpath_search)
end
def error_message

View File

@ -7,20 +7,7 @@ module Webrat
class FieldLabeledLocator < Locator
def locate
# TODO - Convert to using elements
@scope.send(:forms).detect_mapped do |form|
possible_fields = form.send(:fields_by_type, @field_types)
matching_fields = possible_fields.select do |possible_field|
possible_field.send(:labels).any? do |label|
text(label.element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
end
end
matching_fields.min { |a, b| a.label_text.length <=> b.label_text.length }
end
# matching_fields.min { |a, b| a.label_text.length <=> b.label_text.length }
matching_fields.min { |a, b| a.label_text.length <=> b.label_text.length }
end
def matching_fields
@ -38,6 +25,10 @@ module Webrat
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
end
end
def label_elements
Webrat::XML.xpath_search(@scope.dom, Label.xpath_search)
end
def error_message
"Could not find field labeled #{@value.inspect}"

View File

@ -200,6 +200,10 @@ module Webrat
@_page_scope ||= Scope.from_page(self, response, response_body)
end
def dom
page_scope.dom
end
def_delegators :current_scope, :fill_in, :fills_in
def_delegators :current_scope, :set_hidden_field
def_delegators :current_scope, :submit_form