Sha256: 4c5438ea0ab766c58b91ae3ea09ef546fc1b4930f68bc932b8e30c1dfff1fea5

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

module PageMagic
  # module InstanceMethods - provides instance level methods for page objects
  module InstanceMethods
    attr_reader :browser, :session, :browser_element

    # Creates a new instance
    # @param [Session] session session that provides gateway to the browser throw the users chosen browser
    def initialize(session = Session.new(Capybara.current_session))
      @browser = session.raw_session
      @session = session

      @browser_element = browser
    end

    # @return the current page title
    def title
      browser.title
    end

    # check for the presense of specific text on the page
    # @param [String] string the string to check for
    # @return [Boolean]
    def text_on_page?(string)
      text.downcase.include?(string.downcase)
    end

    # Visit this page based on the class level registered url
    def visit
      browser.visit self.class.url
      execute_on_load
    end

    # @return the page text
    def text
      browser.text
    end

    # proxy to the defined page element definitions
    # @return [Object] the result of accessing the requested page element through its definition
    def method_missing(method, *args)
      element_context.send(method, *args)
    end

    def respond_to?(*args)
      super || element_context.respond_to?(*args)
    end

    # @return [Array] class level defined element definitions
    def element_definitions
      self.class.element_definitions
    end

    # executes block stored using {ClassMethods#on_load} against self
    # @return [Element] self
    def execute_on_load
      instance_eval(&self.class.on_load)
      self
    end

    private

    def element_context
      ElementContext.new(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
page_magic-1.0.0.alpha20 lib/page_magic/instance_methods.rb
page_magic-1.0.0.alpha19 lib/page_magic/instance_methods.rb