Module: Howitzer::Web::IframeDsl::ClassMethods

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

Overview

This module holds frame dsl class methods

Instance Method Summary collapse

Instance Method Details

#iframe(name, *args) ⇒ Object

Note:

This method generates following dynamic methods:

frame_name_iframe - equals capybara #within_frame(…) method

has_frame_name_iframe? - equals capybara #has_selector(…) method

has_no_frame_name_iframe? - equals capybara #has_no_selector(…) method

Creates a group of methods to interact with described HTML frame on page

Examples:

Using in a page class

class FbPage < Howitzer::Web::Page
  element :like, :xpath, ".//*[text()='Like']"
  def like
    like_element.click
  end

  def liked?
    #some code here
  end
end

module Utils
  class GroupFbPage < Howitzer::Web::Page
  end
end

class HomePage < Howitzer::Web::Page
  iframe :fb, 1

 # frame with explicit class declaration
 # iframe :fb, FbPage, 1

 # frame with namespace
  iframe :utils_group_fb
end

HomePage.on do
  fb_iframe do |frame|
    frame.like
    expect(frame).to be_liked
  end
end
HomePage.on { is_expected.to have_fb_iframe }

Parameters:

  • name (Symbol, String)

    an unique iframe name

  • args (Array)

    original Capybara arguments. For details, see ‘Capybara::Session#within_frame`.

Raises:

  • (NameError)

    if page class can not be found



85
86
87
88
89
90
91
92
93
94
# File 'lib/howitzer/web/iframe_dsl.rb', line 85

def iframe(name, *args)
  raise ArgumentError, 'iframe selector arguments must be specified' if args.blank?

  klass = args.first.is_a?(Class) ? args.shift : find_matching_class(name)
  raise NameError, "class can not be found for #{name} iframe" if klass.blank?

  define_iframe(klass, name, args)
  define_has_iframe(name, args)
  define_has_no_iframe(name, args)
end