Refactoring locators
This commit is contained in:
parent
04959ae457
commit
eb95f6cf09
@ -1,9 +1,6 @@
|
|||||||
class AreaLocator
|
require "webrat/core/locators/locator"
|
||||||
|
|
||||||
def initialize(scope, value)
|
class AreaLocator < Locator
|
||||||
@scope = scope
|
|
||||||
@value = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
@scope.area_by_element(area_element)
|
@scope.area_by_element(area_element)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
class ButtonLocator
|
require "webrat/core/locators/locator"
|
||||||
|
|
||||||
def initialize(scope, value)
|
class ButtonLocator < Locator
|
||||||
@scope = scope
|
|
||||||
@value = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
@scope.field_by_element(button_element)
|
@scope.field_by_element(button_element)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
class FieldByIdLocator
|
require "webrat/core/locators/locator"
|
||||||
|
|
||||||
def initialize(scope, value)
|
class FieldByIdLocator < Locator
|
||||||
@scope = scope
|
|
||||||
@value = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
@scope.field_by_element(field_element)
|
@scope.field_by_element(field_element)
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
class LinkLocator
|
require "webrat/core/locators/locator"
|
||||||
|
|
||||||
def initialize(scope, value)
|
class LinkLocator < Locator
|
||||||
@scope = scope
|
|
||||||
@value = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
# TODO - Convert to using elements
|
@scope.link_by_element(link_element)
|
||||||
|
|
||||||
matching_links = link_elements.select do |link_element|
|
|
||||||
matches_text?(link_element) ||
|
|
||||||
matches_id?(link_element)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if matching_links.any?
|
def link_element
|
||||||
link_element = matching_links.min { |a, b| Webrat::XML.inner_text(a).length <=> Webrat::XML.inner_text(b).length }
|
matching_links.min { |a, b| Webrat::XML.inner_text(a).length <=> Webrat::XML.inner_text(b).length }
|
||||||
@scope.link_by_element(link_element)
|
end
|
||||||
else
|
|
||||||
nil
|
def matching_links
|
||||||
|
@matching_links ||= link_elements.select do |link_element|
|
||||||
|
matches_text?(link_element) ||
|
||||||
|
matches_id?(link_element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
8
lib/webrat/core/locators/locator.rb
Normal file
8
lib/webrat/core/locators/locator.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Locator
|
||||||
|
|
||||||
|
def initialize(scope, value)
|
||||||
|
@scope = scope
|
||||||
|
@value = value
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user