Refactoring locators

This commit is contained in:
Bryan Helmkamp 2008-11-29 01:54:49 -05:00
parent 04959ae457
commit eb95f6cf09
6 changed files with 30 additions and 35 deletions

View File

@ -1,9 +1,6 @@
class AreaLocator
require "webrat/core/locators/locator"
def initialize(scope, value)
@scope = scope
@value = value
end
class AreaLocator < Locator
def locate
@scope.area_by_element(area_element)

View File

@ -1,9 +1,6 @@
class ButtonLocator
require "webrat/core/locators/locator"
def initialize(scope, value)
@scope = scope
@value = value
end
class ButtonLocator < Locator
def locate
@scope.field_by_element(button_element)

View File

@ -1,9 +1,6 @@
class FieldByIdLocator
require "webrat/core/locators/locator"
def initialize(scope, value)
@scope = scope
@value = value
end
class FieldByIdLocator < Locator
def locate
@scope.field_by_element(field_element)

View File

@ -1,23 +1,19 @@
class LinkLocator
require "webrat/core/locators/locator"
def initialize(scope, value)
@scope = scope
@value = value
end
class LinkLocator < Locator
def locate
# TODO - Convert to using elements
matching_links = link_elements.select do |link_element|
matches_text?(link_element) ||
matches_id?(link_element)
@scope.link_by_element(link_element)
end
if matching_links.any?
link_element = matching_links.min { |a, b| Webrat::XML.inner_text(a).length <=> Webrat::XML.inner_text(b).length }
@scope.link_by_element(link_element)
else
nil
def link_element
matching_links.min { |a, b| Webrat::XML.inner_text(a).length <=> Webrat::XML.inner_text(b).length }
end
def matching_links
@matching_links ||= link_elements.select do |link_element|
matches_text?(link_element) ||
matches_id?(link_element)
end
end

View File

@ -0,0 +1,8 @@
class Locator
def initialize(scope, value)
@scope = scope
@value = value
end
end