From 857625840fd363c609103149be583ab16814747c Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 29 Nov 2008 00:49:00 -0500 Subject: [PATCH] Adding Webrat::XML.xpath_to method --- lib/webrat/core/area.rb | 6 +----- lib/webrat/core/field.rb | 6 +----- lib/webrat/core/form.rb | 6 +----- lib/webrat/core/locators.rb | 6 +----- lib/webrat/core/session.rb | 2 ++ lib/webrat/core/xml.rb | 8 ++++++++ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/webrat/core/area.rb b/lib/webrat/core/area.rb index fd38183..715bb26 100644 --- a/lib/webrat/core/area.rb +++ b/lib/webrat/core/area.rb @@ -15,11 +15,7 @@ module Webrat end def path - if Webrat.configuration.parse_with_nokogiri? - @element.path - else - @element.xpath - end + Webrat::XML.xpath_to(@element) end protected diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 82cff97..f52a002 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -27,11 +27,7 @@ module Webrat end def path - if Webrat.configuration.parse_with_nokogiri? - @element.path - else - @element.xpath - end + Webrat::XML.xpath_to(@element) end def matches_name?(name) diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index 36bb619..47bd006 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -18,11 +18,7 @@ module Webrat def field_by_element(element, *field_types) return nil if element.nil? - if Webrat.configuration.parse_with_nokogiri? - expected_path = element.path - else - expected_path = element.xpath - end + expected_path = Webrat::XML.xpath_to(element) fields_by_type(field_types).detect do |possible_field| possible_field.path == expected_path diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index 7e8a3be..6971c11 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -55,11 +55,7 @@ module Webrat def area_by_element(element) return nil if element.nil? - if Webrat.configuration.parse_with_nokogiri? - expected_path = element.path - else - expected_path = element.xpath - end + expected_path = Webrat::XML.xpath_to(element) areas.detect do |possible_area| possible_area.path == expected_path diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 2b52a96..8c0765f 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -38,6 +38,7 @@ module Webrat @data = {} @default_headers = {} @custom_headers = {} + @elements = {} @context = context end @@ -110,6 +111,7 @@ module Webrat 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? + @elements = {} @_scopes = nil @_page_scope = nil @current_url = url diff --git a/lib/webrat/core/xml.rb b/lib/webrat/core/xml.rb index 4572edc..b2c8cb1 100644 --- a/lib/webrat/core/xml.rb +++ b/lib/webrat/core/xml.rb @@ -62,6 +62,14 @@ module Webrat #:nodoc: 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) return element[attribute_name] if element.is_a?(Hash)