Module: PageMagic::ClassMethods

Defined in:
lib/page_magic/class_methods.rb

Overview

module ClassMethods - contains class level methods for PageObjects

Constant Summary collapse

DEFAULT_ON_LOAD =

Default block to be run when a page is loaded. This is used if a specific handler is not registered

proc {}

Instance Method Summary collapse

Instance Method Details

#on_load(&block) ⇒ Object

sets block to run when page has loaded if one has not been set on the page object class it will return a default block that does nothing



9
10
11
12
# File 'lib/page_magic/class_methods.rb', line 9

def on_load(&block)
  return @on_load || DEFAULT_ON_LOAD unless block
  @on_load = block
end

#url(url = nil) ⇒ Object

getter setter for storing the page url

Parameters:

  • url (String) (defaults to: nil)

    the url of the page



16
17
18
19
# File 'lib/page_magic/class_methods.rb', line 16

def url(url = nil)
  @url = url if url
  @url
end

#visit(application: nil, browser: :rack_test, options: {}) ⇒ Session

Visit this page based on the class level registered url

Parameters:

  • application (Object) (defaults to: nil)

    rack application (optional)

  • browser (Symbol) (defaults to: :rack_test)

    name of browser

  • options (Hash) (defaults to: {})

    browser driver specific options

Returns:

  • (Session)

    active session configured to be using an instance of the page object modeled by this class



26
27
28
29
30
31
32
33
# File 'lib/page_magic/class_methods.rb', line 26

def visit(application: nil, browser: :rack_test, options: {})
  session_options = { browser: browser, options: options, url: url }
  session_options[:application] = application if application

  PageMagic.session(session_options).tap do |session|
    session.visit(self, url: url)
  end
end