Moving around XML code
This commit is contained in:
parent
f3ff8d4ad2
commit
53539eda09
@ -17,7 +17,7 @@ module Webrat
|
|||||||
require "rexml/document"
|
require "rexml/document"
|
||||||
else
|
else
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
require "webrat/core/nokogiri"
|
require "webrat/core/xml/nokogiri"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require "webrat/core/configuration"
|
require "webrat/core/configuration"
|
||||||
require "webrat/core/xml"
|
require "webrat/core/xml"
|
||||||
require "webrat/core/nokogiri"
|
require "webrat/core/xml/nokogiri"
|
||||||
require "webrat/core/logging"
|
require "webrat/core/logging"
|
||||||
require "webrat/core/elements/form"
|
require "webrat/core/elements/form"
|
||||||
require "webrat/core/scope"
|
require "webrat/core/scope"
|
||||||
|
@ -11,13 +11,6 @@ module Webrat
|
|||||||
".//form"
|
".//form"
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*args)
|
|
||||||
super
|
|
||||||
|
|
||||||
fields # preload
|
|
||||||
labels # preload
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_select_option(option_text)
|
def find_select_option(option_text)
|
||||||
select_fields = fields_by_type([SelectField])
|
select_fields = fields_by_type([SelectField])
|
||||||
|
|
||||||
@ -30,15 +23,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fields
|
def fields
|
||||||
@fields ||= Webrat::XML.xpath_search(@element, *Field.xpath_search).map do |element|
|
@fields ||= Field.load_all(@session, @element)
|
||||||
@session.element_to_webrat_element(element)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def labels
|
|
||||||
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
|
|
||||||
@session.element_to_webrat_element(element)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit
|
def submit
|
||||||
|
@ -10,7 +10,7 @@ module Webrat
|
|||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
@document = Webrat.nokogiri_document(stringlike)
|
@document = Webrat.nokogiri_document(stringlike)
|
||||||
else
|
else
|
||||||
@document = Webrat::XML.hpricot_document(stringlike)
|
@document = Webrat.hpricot_document(stringlike)
|
||||||
end
|
end
|
||||||
|
|
||||||
@element = Webrat::XML.inner_text(@document)
|
@element = Webrat::XML.inner_text(@document)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
require "webrat/core/nokogiri"
|
require "webrat/core/xml/nokogiri"
|
||||||
require "webrat/core/rexml"
|
require "webrat/core/xml/rexml"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Matchers
|
module Matchers
|
||||||
|
@ -29,11 +29,8 @@ module Webrat
|
|||||||
@session = session
|
@session = session
|
||||||
instance_eval(&block) if block_given?
|
instance_eval(&block) if block_given?
|
||||||
|
|
||||||
labels
|
# preload
|
||||||
fields
|
load_elements
|
||||||
forms # preload
|
|
||||||
areas # preload
|
|
||||||
links # preload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Verifies an input field or textarea exists on the current page, and stores a value for
|
# Verifies an input field or textarea exists on the current page, and stores a value for
|
||||||
@ -283,6 +280,14 @@ module Webrat
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def load_elements
|
||||||
|
labels
|
||||||
|
fields
|
||||||
|
forms
|
||||||
|
areas
|
||||||
|
links
|
||||||
|
end
|
||||||
|
|
||||||
def page_dom #:nodoc:
|
def page_dom #:nodoc:
|
||||||
return @response.dom if @response.respond_to?(:dom)
|
return @response.dom if @response.respond_to?(:dom)
|
||||||
dom = Webrat::XML.document(@response_body)
|
dom = Webrat::XML.document(@response_body)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
require "webrat/core/xml/nokogiri"
|
||||||
|
require "webrat/core/xml/hpricot"
|
||||||
|
require "webrat/core/xml/rexml"
|
||||||
|
|
||||||
module Webrat #:nodoc:
|
module Webrat #:nodoc:
|
||||||
module XML #:nodoc:
|
module XML #:nodoc:
|
||||||
|
|
||||||
@ -5,24 +9,7 @@ module Webrat #:nodoc:
|
|||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
Webrat.nokogiri_document(stringlike)
|
Webrat.nokogiri_document(stringlike)
|
||||||
else
|
else
|
||||||
# Webrat::XML.hpricot_document(stringlike)
|
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
||||||
Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.hpricot_document(stringlike)
|
|
||||||
return stringlike.dom if stringlike.respond_to?(:dom)
|
|
||||||
|
|
||||||
if Hpricot::Doc === stringlike
|
|
||||||
stringlike
|
|
||||||
elsif Hpricot::Elements === stringlike
|
|
||||||
stringlike
|
|
||||||
elsif StringIO === stringlike
|
|
||||||
Hpricot(stringlike.string)
|
|
||||||
elsif stringlike.respond_to?(:body)
|
|
||||||
Hpricot(stringlike.body.to_s)
|
|
||||||
else
|
|
||||||
Hpricot(stringlike.to_s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
19
lib/webrat/core/xml/hpricot.rb
Normal file
19
lib/webrat/core/xml/hpricot.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
module Webrat
|
||||||
|
|
||||||
|
def self.hpricot_document(stringlike)
|
||||||
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
||||||
|
|
||||||
|
if Hpricot::Doc === stringlike
|
||||||
|
stringlike
|
||||||
|
elsif Hpricot::Elements === stringlike
|
||||||
|
stringlike
|
||||||
|
elsif StringIO === stringlike
|
||||||
|
Hpricot(stringlike.string)
|
||||||
|
elsif stringlike.respond_to?(:body)
|
||||||
|
Hpricot(stringlike.body.to_s)
|
||||||
|
else
|
||||||
|
Hpricot(stringlike.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user