Module: PageMagic::InstanceMethods

Includes:
Element::Locators, SessionMethods, WaitMethods, Watchers
Defined in:
lib/page_magic/instance_methods.rb

Overview

module InstanceMethods - provides instance level methods for page objects

Constant Summary

Constants included from Watchers

Watchers::ELEMENT_MISSING_MSG

Constants included from Element::Locators

Element::Locators::ELEMENT_NOT_DEFINED_MSG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Watchers

#changed?, #watch, #watcher, #watchers

Methods included from SessionMethods

#execute_script, #page, #path, #url

Methods included from WaitMethods

#wait_until

Methods included from Element::Locators

#element_by_name

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

proxy to the defined page element definitions

Returns:

  • (Object)

    the result of accessing the requested page element through its definition



36
37
38
# File 'lib/page_magic/instance_methods.rb', line 36

def method_missing(method, *args)
  element_context.send(method, *args)
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



6
7
8
# File 'lib/page_magic/instance_methods.rb', line 6

def browser
  @browser
end

#browser_elementObject (readonly)

Returns the value of attribute browser_element.



6
7
8
# File 'lib/page_magic/instance_methods.rb', line 6

def browser_element
  @browser_element
end

#sessionObject (readonly)

Returns the value of attribute session.



6
7
8
# File 'lib/page_magic/instance_methods.rb', line 6

def session
  @session
end

Instance Method Details

#element_definitionsArray<ElementDefinitionBuilder>

Returns class level defined element definitions.

Returns:



23
24
25
# File 'lib/page_magic/instance_methods.rb', line 23

def element_definitions
  self.class.element_definitions
end

#execute_on_loadElement

executes block stored using ClassMethods#on_load against self

Returns:



29
30
31
32
# File 'lib/page_magic/instance_methods.rb', line 29

def execute_on_load
  instance_eval(&self.class.on_load)
  self
end

#initialize(session = Session.new(Capybara.current_session)) ⇒ Object

Creates a new instance

Parameters:

  • session (Session) (defaults to: Session.new(Capybara.current_session))

    session that provides gateway to the browser throw the users chosen browser



15
16
17
18
19
20
# File 'lib/page_magic/instance_methods.rb', line 15

def initialize(session = Session.new(Capybara.current_session))
  @browser = session.raw_session
  @session = session

  @browser_element = browser
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/page_magic/instance_methods.rb', line 40

def respond_to_missing?(*args)
  contains_element?(args.first) || super
end

#textObject

Returns the page text.

Returns:

  • the page text



50
51
52
# File 'lib/page_magic/instance_methods.rb', line 50

def text
  browser.text
end

#text_on_page?(string) ⇒ Boolean

check for the presense of specific text on the page

Parameters:

  • string (String)

    the string to check for

Returns:

  • (Boolean)


57
58
59
# File 'lib/page_magic/instance_methods.rb', line 57

def text_on_page?(string)
  text.downcase.include?(string.downcase)
end

#titleObject

Returns the current page title.

Returns:

  • the current page title



45
46
47
# File 'lib/page_magic/instance_methods.rb', line 45

def title
  browser.title
end