Module: Howitzer::Web::SectionDsl::ClassMethods

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

Overview

This module holds section dsl class methods

Defined Under Namespace

Classes: SectionScope

Instance Method Summary collapse

Instance Method Details

#section(name, *args, **options, &block) ⇒ Object

Note:

This method generates following dynamic methods:

section_name_section - equals capybara #find(…) method

section_name_sections - equals capybara #all(…) method

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

has_section_name_section? - equals capybara #has_selector(…) method

has_no_section_name_section? - equals capybara #has_no_selector(…) method

Note:

It is possible to use nested anonymous sections

DSL method which defines named or anonymous section within a page or a section

Examples:

Named section

class MenuSection < Howitzer::Web::Section
  me :xpath, ".//*[@id='panel']"
end
class HomePage < Howitzer::Web::Page
  section :menu
end
HomePage.on { is_expected.to have_menu_section }

Anonymous section

class HomePage < Howitzer::Web::Page
  section :info_panel, '#panel' do
    element :edit_button, '.edit'
    element :title_field, '.title'

    def edit_info(title: nil)
      edit_button_element.click
      title_field_element.set(title)
    end
  end
end
HomePage.on { info_panel.edit_info(title: 'Test Title') }

Anonymous nested section

class HomePage < Howitzer::Web::Page
  section :info_panel, '#panel' do
    element :edit_button, '.edit'

    section :form, '.form' do
      element :title_field, '.title'
    end
  end
end
HomePage.on { info_panel_section.edit_info(title: 'Test Title') }

Parameters:

  • name (Symbol, String)

    an unique section name

  • args (Array)

    original Capybara arguments. For details, see ‘Capybara::Node::Finders#all. (In most cases should be ommited for named sections because the section selector is specified with `#me` method. But must be specified for anonymous sections)

  • options (Hash)

    original Capybara options. For details, see ‘Capybara::Node::Finders#all. (In most cases should be ommited for named sections because the section selector is specified with `#me` method. But may be specified for anonymous sections)

  • block (Proc)

    this block can contain nested sections and elements



127
128
129
130
131
132
133
# File 'lib/howitzer/web/section_dsl.rb', line 127

def section(name, *args, **options, &block)
  scope = SectionScope.new(name, *args, **options, &block)
  define_section_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)
  define_sections_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)
  define_has_section_method(name, *scope.finder_args, **scope.finder_options)
  define_has_no_section_method(name, *scope.finder_args, **scope.finder_options)
end