Sha256: f3c91b68365885747318ddc474b94aafbb5796e699cc72a544a72ca237afa999

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

module PageMagic
  # module ClassMethods - contains class level methods for PageObjects
  module ClassMethods
    # Default block to be run when a page is loaded. This is used if a specific handler is not registered
    DEFAULT_ON_LOAD = proc {}

    # 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
    def on_load(&block)
      return @on_load || DEFAULT_ON_LOAD unless block
      @on_load = block
    end

    # getter setter for storing the page url
    # @param [String] url the url of the page
    def url(url = nil)
      @url = url if url
      @url
    end

    # Visit this page based on the class level registered url
    # @param [Object] application rack application (optional)
    # @param [Symbol] browser name of browser
    # @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
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
page_magic-1.1.0 lib/page_magic/class_methods.rb
page_magic-1.0.4 lib/page_magic/class_methods.rb
page_magic-1.0.3 lib/page_magic/class_methods.rb
page_magic-1.0.2 lib/page_magic/class_methods.rb
page_magic-1.0.1 lib/page_magic/class_methods.rb
page_magic-1.0.0 lib/page_magic/class_methods.rb