class Capybara::PomPom::ElementFinder
Capybara::PomPom::ElementFinder
¶ ↑
ElementFinder
is used as a lambda to find elements when invoked by the Page
instance rather than when defined.
Attributes
locator[R]
type[R]
wrapper[R]
Public Class Methods
new(type, locator, wrapper: nil)
click to toggle source
Initializes a new ElementFinder
Parameters¶ ↑
-
type
: the capybara finder. E.g.find
,find_link
, etc… -
locator
: the locator used by capybara to find element. -
wrapper
(optional): an instance to wrap the found element in.
# File lib/capybara/pompom/element_finder.rb, line 17 def initialize(type, locator, wrapper: nil) @type = type @locator = locator @wrapper = wrapper end
Public Instance Methods
get(scope = nil)
click to toggle source
Returns the Capybara::Element or wrapper
if defined.
# File lib/capybara/pompom/element_finder.rb, line 24 def get(scope = nil) scope ||= self wrap_result(scope.send(type, locator)) end
Private Instance Methods
wrap_result(result)
click to toggle source
# File lib/capybara/pompom/element_finder.rb, line 31 def wrap_result(result) return result if wrapper.nil? if result.is_a?(Capybara::Result) return result.map { |r| wrapper.new(r) } end wrapper.new(result) end