Sha256: ed44b3ca1601ca4d63fdd45562694985e088face04532f1767b24df8cf618b23

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

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

    include Element::Locators
    include WaitMethods
    include SessionMethods
    include Watchers

    # 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 [Array<ElementDefinitionBuilder>] 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

    # 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_missing?(*args)
      contains_element?(args.first) || super
    end

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

    # @return the page text
    def text
      browser.text
    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

    private

    def contains_element?(method)
      element_definitions.keys.include?(method)
    end

    def element_context
      ElementContext.new(self)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
page_magic-2.0.13 lib/page_magic/instance_methods.rb
page_magic-2.0.12 lib/page_magic/instance_methods.rb
page_magic-2.0.11 lib/page_magic/instance_methods.rb
page_magic-2.0.10 lib/page_magic/instance_methods.rb
page_magic-2.0.9 lib/page_magic/instance_methods.rb
page_magic-2.0.6 lib/page_magic/instance_methods.rb
page_magic-2.0.5 lib/page_magic/instance_methods.rb
page_magic-2.0.4 lib/page_magic/instance_methods.rb
page_magic-2.0.3 lib/page_magic/instance_methods.rb
page_magic-2.0.2 lib/page_magic/instance_methods.rb
page_magic-2.0.1 lib/page_magic/instance_methods.rb
page_magic-2.0.0 lib/page_magic/instance_methods.rb