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



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

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

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



4
5
6
# File 'lib/page_magic/instance_methods.rb', line 4

def browser
  @browser
end

#browser_elementObject (readonly)

Returns the value of attribute browser_element.



4
5
6
# File 'lib/page_magic/instance_methods.rb', line 4

def browser_element
  @browser_element
end

#sessionObject (readonly)

Returns the value of attribute session.



4
5
6
# File 'lib/page_magic/instance_methods.rb', line 4

def session
  @session
end

Instance Method Details

#element_definitionsArray

Returns class level defined element definitions.

Returns:

  • (Array)

    class level defined element definitions



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

def element_definitions
  self.class.element_definitions
end

#execute_on_loadElement

executes block stored using ClassMethods#on_load against self

Returns:



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

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



10
11
12
13
14
15
# File 'lib/page_magic/instance_methods.rb', line 10

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

  @browser_element = browser
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#textObject

Returns the page text.

Returns:

  • the page text



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

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)


52
53
54
# File 'lib/page_magic/instance_methods.rb', line 52

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

#titleObject

Returns the current page title.

Returns:

  • the current page title



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

def title
  browser.title
end