class Parfait::Application

Public Class Methods

find(name) click to toggle source

Find an application object by name

Options

name

specifies the name of the application to search for

Example

blog_app = Parfait::Application.find("Blog App")
# File lib/parfait/application.rb, line 51
def self.find(name)
  @@all[name]
end
new(opts = {}) click to toggle source

Define an application

Options

Takes a hash as input where the current options are:

name

specifies the name of the application

  • :browser optionally specifies the browser object used in the current thread. Storing this value will allow the browser object to be retrieved via Parfait.browser invocation when defining get and set routines for controls.

Example

mybrowser = Watir::Browser.new()
Parfait::Application.new(
  :name => "Blog",
  :browser => mybrowser
)
Calls superclass method
# File lib/parfait/application.rb, line 24
def initialize(opts = {})
  o = {
    :name => nil,
    :browser => nil
  }.merge(opts)

  @name = o[:name]
  raise "Application name must be specified" unless @name

  set_browser(o[:browser])

  @pages = Hash.new
  @@all[@name] = self
  super
end

Public Instance Methods

add_page(page) click to toggle source

Add a page to this Application

Options

page

specifies a Parfait::Page object

Example

blog_posts = Parfait::Page.new(:name => "Blog Posts")
blogapp.add_page(blog_posts)
# File lib/parfait/application.rb, line 109
def add_page(page)

  if page
    if page.is_a?(Parfait::Page)
      @pages[page.name] = page
      if page.aliases
        page.aliases.each do |my_alias|
          @pages[my_alias] = page
        end
      end
    else
      raise "Page must be a Parfait::Page when being adding to an application"
    end
  else
    raise "Page must be specified when adding a page to an application"
  end
  self
end
browser() click to toggle source

Get the browser object used by the current thread.

This will be particularly useful when defining directives for a Parfait::Control.

Options

none

Example

mycontrol.add_get{ |opts|
  Parfait::browser.text_field(:id => "body").when_present.value
}
# File lib/parfait/application.rb, line 89
def browser()
  #If the browser is non-nil, then it passed validation in the configure method
  unless Thread.current[:parfait_browser]
    raise "Parfait: browser requested, but it is undefined"
  end
  Thread.current[:parfait_browser]
end
page(requested_name) click to toggle source

Retrieve a page object by name or alias.

Under the covers, if there is an existence directive defined for this page, it will be run on the current browser to confirm that we are indeed on it.

Options

name

specifies the name or alias of the page

Example

myapp.page("Login Page")
# File lib/parfait/application.rb, line 142
def page(requested_name)
  page = @pages[requested_name] 
  if page
    # Confirm that we are in the requested application
    verify_presence "Cannot navigate to page \"#{requested_name}\" because application presence check failed"

    # Pass the browser through to any subsequently called methods
    Thread.current[:parfait_region] = Thread.current[:parfait_browser]

    return page
  else
    raise "Invalid page name requested: \"#{requested_name}\""
  end
end
set_browser(browser) click to toggle source

Set the browser object for the current thread.

Options

none

Example

b = Watir::browser.new
myapplication.set_browser(b)
# File lib/parfait/application.rb, line 67
def set_browser(browser)
  Thread.current[:parfait_browser] = browser 
  unless Thread.current[:parfait_browser] == nil or 
         Thread.current[:parfait_browser].is_a?(Watir::Browser)
    raise "Parfait browser parameter must be a Watir Browser object"
  end
end