module PageMagic::ClassMethods

module ClassMethods - contains class level methods for PageObjects

Constants

DEFAULT_ON_LOAD

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

Public Instance Methods

load(source) click to toggle source

create an new page object instance based on top of the source supplied @param [String] source html source code @return [Object<InstanceMethods>] instance of class with all the same methods as normal PageMagic page objects.

# File lib/page_magic/class_methods.rb, line 12
def load(source)
  new(Session.new(Capybara::Node::Simple.new(source)))
end
on_load(&block) click to toggle source

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

# File lib/page_magic/class_methods.rb, line 18
def on_load(&block)
  return @on_load || DEFAULT_ON_LOAD unless block

  @on_load = block
end
url(url = nil) click to toggle source

getter setter for storing the page url @param [String] url the url of the page

# File lib/page_magic/class_methods.rb, line 26
def url(url = nil)
  @url = url if url
  @url
end
visit(application: nil, browser: :rack_test, options: {}) click to toggle source

Visit this page based on the class level registered url @param [Object] application rack application (optional) @param [Symbol] browser name of browser driver to use @param [Hash] options browser driver specific options @return [Session] active session configured to be using an instance of the page object modeled by this class

# File lib/page_magic/class_methods.rb, line 36
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