Sha256: f6cad7bf154756493ccaec2012dd3e158af754a322a56550289b6cdaac72ef75

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
require 'capybara'
require 'page_magic/exceptions'
require 'page_magic/wait_methods'
require 'page_magic/watchers'
require 'page_magic/session'
require 'page_magic/session_methods'
require 'page_magic/elements'
require 'page_magic/element_context'
require 'page_magic/element'
require 'page_magic/class_methods'
require 'page_magic/instance_methods'
require 'page_magic/drivers'

# module PageMagic - PageMagic is an api for modelling pages in a website.
module PageMagic
  extend SingleForwardable

  # @!method matcher
  # define match critera for loading a page object class
  # @see Matcher#initialize
  # @return [Matcher]
  def_delegator Matcher, :new, :matcher

  class << self
    # @return [Drivers] registered drivers
    def drivers
      @drivers ||= Drivers.new.tap(&:load)
    end

    def included(clazz)
      clazz.class_eval do
        include(InstanceMethods)
        extend(Elements, ClassMethods)
      end
    end

    # Visit this page based on the class level registered url
    # @param [Object] application rack application (optional)
    # @param [Symbol] browser name of browser
    # @param [String] url url to start the session on
    # @param [Hash] options browser driver specific options
    # @return [Session] configured sessoin
    def session(application: nil, browser: :rack_test, url:, options: {})
      driver = drivers.find(browser)
      fail UnspportedBrowserException unless driver

      Capybara.register_driver browser do |app|
        driver.build(app, browser: browser, options: options)
      end

      Session.new(Capybara::Session.new(browser, application), url)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
page_magic-1.2.1 lib/page_magic.rb
page_magic-1.2.0 lib/page_magic.rb
page_magic-1.1.0 lib/page_magic.rb