Extract FieldNamedLocator object
This commit is contained in:
parent
eb95f6cf09
commit
d7eec20950
|
@ -38,18 +38,9 @@ module Webrat
|
|||
end
|
||||
|
||||
def find_field_named(name, *field_types) #:nodoc:
|
||||
if field_types.any?
|
||||
xpath_searches = field_types.map { |field_type| field_type.xpath_search }.flatten
|
||||
field_elements = Webrat::XML.xpath_search(dom, xpath_searches)
|
||||
else
|
||||
field_elements = Webrat::XML.xpath_search(dom, *Field.xpath_search)
|
||||
end
|
||||
require "webrat/core/locators/field_named_locator"
|
||||
|
||||
field_element = field_elements.detect do |field_element|
|
||||
Webrat::XML.attribute(field_element, "name") == name.to_s
|
||||
end
|
||||
|
||||
field_by_element(field_element)
|
||||
FieldNamedLocator.new(self, name, *field_types).locate
|
||||
end
|
||||
|
||||
def field_by_element(element)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require "webrat/core/locators/locator"
|
||||
|
||||
class FieldNamedLocator < Locator
|
||||
|
||||
def locate
|
||||
@scope.field_by_element(field_element)
|
||||
end
|
||||
|
||||
def field_element
|
||||
field_elements.detect do |field_element|
|
||||
Webrat::XML.attribute(field_element, "name") == @value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def field_elements
|
||||
Webrat::XML.xpath_search(@scope.dom, *xpath_searches)
|
||||
end
|
||||
|
||||
def xpath_searches
|
||||
if @field_types.any?
|
||||
@field_types.map { |field_type| field_type.xpath_search }.flatten
|
||||
else
|
||||
Array(Field.xpath_search)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +1,9 @@
|
|||
class Locator
|
||||
|
||||
def initialize(scope, value)
|
||||
def initialize(scope, value, *field_types)
|
||||
@scope = scope
|
||||
@value = value
|
||||
@field_types = field_types
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue