Load fields and labels directly from the scope
This commit is contained in:
parent
40e0272dff
commit
4594a39327
@ -30,27 +30,14 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fields
|
def fields
|
||||||
return @fields if @fields
|
@fields ||= Webrat::XML.xpath_search(@element, *Field.xpath_search).map do |element|
|
||||||
|
@session.element_to_webrat_element(element)
|
||||||
@fields = []
|
|
||||||
|
|
||||||
[SelectField, TextareaField, ButtonField, CheckboxField, PasswordField,
|
|
||||||
RadioField, FileField, ResetField, TextField, HiddenField].each do |field_class|
|
|
||||||
@fields += Webrat::XML.xpath_search(@element, *field_class.xpath_search).map do |element|
|
|
||||||
field = field_class.new(@session, element)
|
|
||||||
@session.elements[Webrat::XML.xpath_to(element)] = field
|
|
||||||
field
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@fields
|
|
||||||
end
|
|
||||||
|
|
||||||
def labels
|
def labels
|
||||||
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
|
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
|
||||||
label = Label.new(@session, element)
|
@session.element_to_webrat_element(element)
|
||||||
@session.elements[Webrat::XML.xpath_to(element)] = label
|
|
||||||
label
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ module Webrat
|
|||||||
@session = session
|
@session = session
|
||||||
instance_eval(&block) if block_given?
|
instance_eval(&block) if block_given?
|
||||||
|
|
||||||
|
labels
|
||||||
|
fields
|
||||||
forms # preload
|
forms # preload
|
||||||
areas # preload
|
areas # preload
|
||||||
links # preload
|
links # preload
|
||||||
@ -340,5 +342,30 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
return @fields if @fields
|
||||||
|
|
||||||
|
@fields = []
|
||||||
|
|
||||||
|
[SelectField, TextareaField, ButtonField, CheckboxField, PasswordField,
|
||||||
|
RadioField, FileField, ResetField, TextField, HiddenField].each do |field_class|
|
||||||
|
@fields += Webrat::XML.xpath_search(dom, *field_class.xpath_search).map do |element|
|
||||||
|
field = field_class.new(self, element)
|
||||||
|
@session.elements[Webrat::XML.xpath_to(element)] = field
|
||||||
|
field
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@fields
|
||||||
|
end
|
||||||
|
|
||||||
|
def labels
|
||||||
|
@labels ||= Webrat::XML.css_search(dom, "label").map do |element|
|
||||||
|
label = Label.new(self, element)
|
||||||
|
@session.elements[Webrat::XML.xpath_to(element)] = label
|
||||||
|
label
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user