Extract FieldNamedLocator object
This commit is contained in:
parent
eb95f6cf09
commit
d7eec20950
@ -38,18 +38,9 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def find_field_named(name, *field_types) #:nodoc:
|
def find_field_named(name, *field_types) #:nodoc:
|
||||||
if field_types.any?
|
require "webrat/core/locators/field_named_locator"
|
||||||
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
|
|
||||||
|
|
||||||
field_element = field_elements.detect do |field_element|
|
FieldNamedLocator.new(self, name, *field_types).locate
|
||||||
Webrat::XML.attribute(field_element, "name") == name.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
field_by_element(field_element)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_by_element(element)
|
def field_by_element(element)
|
||||||
|
27
lib/webrat/core/locators/field_named_locator.rb
Normal file
27
lib/webrat/core/locators/field_named_locator.rb
Normal file
@ -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
|
class Locator
|
||||||
|
|
||||||
def initialize(scope, value)
|
def initialize(scope, value, *field_types)
|
||||||
@scope = scope
|
@scope = scope
|
||||||
@value = value
|
@value = value
|
||||||
|
@field_types = field_types
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user