Module: PageMagic::Elements

Included in:
Element
Defined in:
lib/page_magic/elements.rb,
lib/page_magic/elements/types.rb,
lib/page_magic/elements/config.rb,
lib/page_magic/elements/inheritance_hooks.rb

Overview

module Elements - contains methods that add element definitions to the objects it is mixed in to

Defined Under Namespace

Modules: InheritanceHooks Classes: CONFIG_STRUCT, Config

Constant Summary collapse

INVALID_METHOD_NAME_MSG =
'a method already exists with this method name'
TYPES =
%i[field
fieldset
file_field
fillable_field
frame
link_or_button
option
radio_button
select
table
table_row
text_field
button
link
checkbox
select_list
radio
textarea
label].freeze

Instance Method Summary collapse

Instance Method Details

#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

#element_definitionsHash<Symbol,ElementDefinitionBuilder>

blocks that can be used to create unique instances of PageMagic::Element definitions

Returns:



83
84
85
# File 'lib/page_magic/elements.rb', line 83

def element_definitions
  @element_definitions ||= {}
end

#elements(*args, **capybara_options, &block) ⇒ Object

see docs for #element



70
71
72
73
74
75
76
# File 'lib/page_magic/elements.rb', line 70

def elements(*args, **capybara_options, &block)
  define_element(*args,
                 type: __callee__.to_s.singularize.to_sym,
                 query_class: PageMagic::Element::Query::MultipleResults,
                 **capybara_options,
                 &block)
end