Adding Webrat::XML.xpath_to method

This commit is contained in:
Bryan Helmkamp 2008-11-29 00:49:00 -05:00
parent 6316faae44
commit 857625840f
6 changed files with 14 additions and 20 deletions

View File

@ -15,11 +15,7 @@ module Webrat
end end
def path def path
if Webrat.configuration.parse_with_nokogiri? Webrat::XML.xpath_to(@element)
@element.path
else
@element.xpath
end
end end
protected protected

View File

@ -27,11 +27,7 @@ module Webrat
end end
def path def path
if Webrat.configuration.parse_with_nokogiri? Webrat::XML.xpath_to(@element)
@element.path
else
@element.xpath
end
end end
def matches_name?(name) def matches_name?(name)

View File

@ -18,11 +18,7 @@ module Webrat
def field_by_element(element, *field_types) def field_by_element(element, *field_types)
return nil if element.nil? return nil if element.nil?
if Webrat.configuration.parse_with_nokogiri? expected_path = Webrat::XML.xpath_to(element)
expected_path = element.path
else
expected_path = element.xpath
end
fields_by_type(field_types).detect do |possible_field| fields_by_type(field_types).detect do |possible_field|
possible_field.path == expected_path possible_field.path == expected_path

View File

@ -55,11 +55,7 @@ module Webrat
def area_by_element(element) def area_by_element(element)
return nil if element.nil? return nil if element.nil?
if Webrat.configuration.parse_with_nokogiri? expected_path = Webrat::XML.xpath_to(element)
expected_path = element.path
else
expected_path = element.xpath
end
areas.detect do |possible_area| areas.detect do |possible_area|
possible_area.path == expected_path possible_area.path == expected_path

View File

@ -38,6 +38,7 @@ module Webrat
@data = {} @data = {}
@default_headers = {} @default_headers = {}
@custom_headers = {} @custom_headers = {}
@elements = {}
@context = context @context = context
end end
@ -110,6 +111,7 @@ module Webrat
save_and_open_page if exception_caught? && Webrat.configuration.open_error_files? save_and_open_page if exception_caught? && Webrat.configuration.open_error_files?
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code? raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
@elements = {}
@_scopes = nil @_scopes = nil
@_page_scope = nil @_page_scope = nil
@current_url = url @current_url = url

View File

@ -62,6 +62,14 @@ module Webrat #:nodoc:
end end
end end
def self.xpath_to(element)
if Webrat.configuration.parse_with_nokogiri?
element.path
else
element.xpath
end
end
def self.attribute(element, attribute_name) def self.attribute(element, attribute_name)
return element[attribute_name] if element.is_a?(Hash) return element[attribute_name] if element.is_a?(Hash)