Sha256: 1efa90bc8fa3eb5473131106af777fc24a724a9e04a2b3ee13dfb08eabe7fa60
Contents?: true
Size: 1.35 KB
Versions: 6
Compression:
Stored size: 1.35 KB
Contents
module PageMagic # Builder for creating ElementDefinitions class ElementDefinitionBuilder INVALID_SELECTOR_MSG = 'Pass a locator/define one on the class' attr_reader :definition_class, :options, :selector, :type, :element def initialize(definition_class:, selector:, type:, options:{}, element: nil) unless element selector ||= definition_class.selector fail UndefinedSelectorException, INVALID_SELECTOR_MSG if selector.nil? || selector.empty? end @definition_class = definition_class @selector = selector @type = type @options = options @element = element end # @return [Capybara::Query] query to find this element in the browser def build_query Element::Query.find(type).build(selector, options) end # Create new instance of the ElementDefinition modeled by this builder # @param [Object] browser_element capybara browser element corresponding to the element modelled by this builder # @return [Element] element definition def build(browser_element) definition_class.new(browser_element) end def ==(other) return false unless other.is_a?(ElementDefinitionBuilder) this = [options, selector, type, element, definition_class] this == [other.options, other.selector, other.type, other.element, other.definition_class] end end end
Version data entries
6 entries across 6 versions & 1 rubygems