Sha256: fa34ff7d58d23d10926e5953a2f4f822cdf24b0a2734cc5fce00ded7bc2f81e2

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

require "capybara_objects/registry_methods"
require "capybara_objects/initialize_methods"
require "capybara_objects/scoped_finders"
require "capybara_objects/location_methods"
require "capybara_objects/validation_methods"
require "capybara_objects/convenience_methods"
module CapybaraObjects
  #
  # A page object
  #
  class PageObject
    include RegistryMethods
    include InitializeMethods
    include LocationMethods
    include ValidationMethods
    include ConvenienceMethods
    include ScopedFinders
    attr_accessor :url
    class << self
      # Registers a "ptype" alias for this class
      # @param [String] type The alias or type to register this class with.
      def ptype(type)
        registry.register_ptype type, self
      end

      # Defines the default url. Can be overriden in the instance
      # @param [String] url The default url
      def url(url)
        self.default_url = url
      end
    end

    def initialize(options = {})
      super
      self.url ||= default_url
    end

    # Visits the pre configured URL to make this page available
    # @raise ::CapybaraPageObjects::Exceptions::MissingUrl
    # @return [::CapybaraObjects::PageObject] self - allows chaining of methods
    def visit
      raise ::CapybaraObjects::Exceptions::MissingUrl unless url.present?
      page.visit url
      validate!
      self
    end

    # Attaches the page object to the current page
    # @return [::CapybaraObjects::PageObject] self - allows chaining of methods
    def attach(options = {})
      validate!
      self
    end

    private
    cattr_accessor :default_url


  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
capybara_objects-0.1.2 lib/capybara_objects/page_object.rb
capybara_objects-0.1.1 lib/capybara_objects/page_object.rb
capybara_objects-0.1.0 lib/capybara_objects/page_object.rb