Method: PageMagic::Elements#element

Defined in:
lib/page_magic/elements.rb

#element(name, selector, &block) ⇒ Object #element(element_class, &block) ⇒ Object #element(name, element_class, &block) ⇒ Object #element(name, element_class, selector, &block) ⇒ Object

Creates an Element definition This method is aliased to each of the names specified in TYPES Element definitions contain specifications for locating them and other sub elements.

Examples:

element :widget, id: 'widget' do
  link :next, text: 'next'
end

Overloads:

  • #element(name, selector, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • selector (Hash<Symbol,String>)

      a key value pair defining the method for locating this element

    • optional (Hash<Symbol,String>)

      capybara_options

    Options Hash (selector):

    • :text (String)

      text contained within the element

    • :css (String)

      css selector

    • :id (String)

      the id of the element

    • :name (String)

      the value of the name attribute belonging to the element

    • :label (String)

      value of the label tied to the require field

  • #element(element_class, &block) ⇒ Object

    Parameters:

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element. the name of the element is derived from the class name. the Class name coverted to snakecase. The selector must be defined on the class itself.

    • optional (Hash<Symbol,String>)

      capybara_options

  • #element(name, element_class, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element. The selector must be defined on the class itself.

    • optional (Hash<Symbol,String>)

      capybara_options

  • #element(name, element_class, selector, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element.

    • optional (Hash<Symbol,String>)

      capybara_options

Yields:

  • if a block is specified then it will be executed against the element definition.



61
62
63
64
65
66
67
# File 'lib/page_magic/elements.rb', line 61

def element(*args, **capybara_options, &block)
  define_element(*args,
                 type: __callee__,
                 query_class: PageMagic::Element::Query::SingleResult,
                 **capybara_options,
                 &block)
end