Updating field_with_id to search DOM elements

This commit is contained in:
Bryan Helmkamp 2008-11-28 18:14:42 -05:00
parent 3dce02483b
commit ca0642e35c
3 changed files with 19 additions and 15 deletions

View File

@ -189,7 +189,7 @@ module Webrat
if collection_name? if collection_name?
super super
else else
checkbox_with_same_name = @form.field(name, CheckboxField) checkbox_with_same_name = @form.field_named(name, CheckboxField)
if checkbox_with_same_name.to_param.blank? if checkbox_with_same_name.to_param.blank?
super super

View File

@ -10,15 +10,10 @@ module Webrat
@element = element @element = element
@fields = nil @fields = nil
end end
def field(locator, *field_types)
field_with_id(locator, *field_types) ||
field_named(locator, *field_types) ||
field_labeled(locator, *field_types) ||
nil
end
def field_by_element(element, *field_types) def field_by_element(element, *field_types)
return nil if element.nil?
if Webrat.configuration.parse_with_nokogiri? if Webrat.configuration.parse_with_nokogiri?
expected_path = element.path expected_path = element.path
else else
@ -63,11 +58,6 @@ module Webrat
def submit def submit
@session.request_page(form_action, form_method, params) @session.request_page(form_action, form_method, params)
end end
def field_with_id(id, *field_types)
possible_fields = fields_by_type(field_types)
possible_fields.detect { |possible_field| possible_field.matches_id?(id) }
end
def field_named(name, *field_types) def field_named(name, *field_types)
possible_fields = fields_by_type(field_types) possible_fields = fields_by_type(field_types)

View File

@ -46,12 +46,26 @@ module Webrat
end end
end end
def find_field_with_id(id, *field_types) #:nodoc: def field_by_element(element, *field_types)
forms.detect_mapped do |form| forms.detect_mapped do |form|
form.field_with_id(id, *field_types) form.field_by_element(element, *field_types)
end end
end end
def find_field_with_id(id, *field_types) #:nodoc:
field_elements = Webrat::XML.css_search(dom, "button", "input", "textarea", "select")
field_element = field_elements.detect do |field_element|
if id.is_a?(Regexp)
Webrat::XML.attribute(field_element, "id") =~ id
else
Webrat::XML.attribute(field_element, "id") == id.to_s
end
end
field_by_element(field_element)
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:
if id_or_name_or_label if id_or_name_or_label
field = field(id_or_name_or_label, SelectField) field = field(id_or_name_or_label, SelectField)