Sha256: aa28007ec52a3adb86a19888832b99d2e0f1b2c53c5c46d7699719a62af41538

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__).to_s)
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)
      raise 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

4 entries across 4 versions & 1 rubygems

Version Path
page_magic-1.2.5 lib/page_magic.rb
page_magic-1.2.5.alpha1 lib/page_magic.rb
page_magic-1.2.4 lib/page_magic.rb
page_magic-1.2.3 lib/page_magic.rb