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

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, &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') }


112
113
114
115
116
117
118
# File 'lib/howitzer/web/section_dsl.rb', line 112

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