Module: Howitzer::Web::ElementDsl::ClassMethods

Includes:
Utils::ArgumentConvertable
Defined in:
lib/howitzer/web/element_dsl.rb

Overview

This module holds element dsl methods

Instance Method Summary collapse

Instance Method Details

#element(name, *args, **options) ⇒ Object

Note:

This method generates following dynamic methods:

element_name_element - equals capybara #find(…) method

element_name_elements - equals capybara #all(…) method

element_name_elements.first - equals capybara #first(…) method

wait_for_element_name_element - equals capybara #find(…) method but returns nil

within_element_name_element - equals capybara #within(…) method

has_element_name_element? - equals capybara #has_selector(…) method

has_no_element_name_element? - equals capybara #has_no_selector(…) method

Creates a group of methods to interact with described HTML element(s) on page

Examples:

Using in a page class

class HomePage < Howitzer::Web::Page
  element :top_panel, '.top'
  element :bottom_panel, '.bottom'
  element :new_button, :xpath, ".//*[@name='New']"

  def press_top_new_button
    within_top_panel_element do
      new_button_element.click
    end
  end

  def press_bottom_new_button
    within_bottom_panel_element do
      new_button_element.click
    end
  end
end

HomePage.on do
  is_expected.to have_top_panel_element
  press_top_new_element
  is_expected.to have_no_new_button_element(match: :first)
end

Using in a section class

class MenuSection < Howitzer::Web::Section
  me '.main-menu'
  element :menu_item, '.item'

  def menu_items
    menu_item_elements.map(&:text)
  end
end

Parameters:

  • name (Symbol, String)

    an unique element name

  • args (Array)

    original Capybara arguments. For details, see ‘Capybara::Node::Finders#all`.

  • options (Hash)

    original Capybara options. For details, see ‘Capybara::Node::Finders#all`.

Raises:



74
75
76
77
78
79
80
81
82
# File 'lib/howitzer/web/element_dsl.rb', line 74

def element(name, *args, **options)
  validate_arguments!(args)
  define_element(name, args, options)
  define_elements(name, args, options)
  define_wait_for_element(name, args, options)
  define_within_element(name, args, options)
  define_has_element(name, args, options)
  define_has_no_element(name, args, options)
end