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

Defined in:
lib/howitzer/web/element_dsl.rb

Overview

This module holds element dsl methods methods

Instance Method Summary collapse

Instance Method Details

#element(name, *args) ⇒ 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

Raises:



95
96
97
98
99
100
101
102
103
# File 'lib/howitzer/web/element_dsl.rb', line 95

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