Refactoring label locating to use elements
This commit is contained in:
parent
67dd6d7c58
commit
27626ea389
@ -15,6 +15,7 @@ module Webrat
|
|||||||
@fields = nil
|
@fields = nil
|
||||||
|
|
||||||
fields # preload
|
fields # preload
|
||||||
|
labels # preload
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_select_option(option_text)
|
def find_select_option(option_text)
|
||||||
@ -46,7 +47,11 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def labels
|
def labels
|
||||||
@labels ||= Webrat::XML.css_search(element, "label").map { |element| Label.new(nil, element) }
|
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
|
||||||
|
label = Label.new(nil, element)
|
||||||
|
@session.elements[Webrat::XML.xpath_to(element)] = label
|
||||||
|
label
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit
|
def submit
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
class Label #:nodoc:
|
class Label #:nodoc:
|
||||||
|
|
||||||
|
def self.xpath_search
|
||||||
|
".//label"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(field, element)
|
def initialize(field, element)
|
||||||
@field = field
|
@field = field
|
||||||
@element = element
|
@element = element
|
||||||
|
@ -7,13 +7,27 @@ module Webrat
|
|||||||
class LabelLocator < Locator
|
class LabelLocator < Locator
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
# TODO - Convert to using elements
|
@scope.element_to_webrat_element(label_element)
|
||||||
|
end
|
||||||
@scope.send(:forms).detect_mapped do |form|
|
|
||||||
form.label_matching(@value)
|
def label_element
|
||||||
|
label_elements.detect do |label_element|
|
||||||
|
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def label_elements
|
||||||
|
Webrat::XML.xpath_search(@scope.dom, Label.xpath_search)
|
||||||
|
end
|
||||||
|
|
||||||
|
def text(label_element)
|
||||||
|
str = Webrat::XML.all_inner_text(label_element)
|
||||||
|
str.gsub!("\n","")
|
||||||
|
str.strip!
|
||||||
|
str.squeeze!(" ")
|
||||||
|
str
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user