class OLE_QA::Framework::Page

An OLE Page object

Attributes

lines[R]

An array containing the name (Symbol) of each line object on the page object.

url[R]

The URL to open a given page. @note Do not use this value for the URL to open a new page of a given

document type.  If the page object represents an e-Document in OLEFS
or OLELS, instead use the :new_url accessor set on the e-Doc object.
wait_on[R]

An array containing the elements (Symbol) to wait on before the page is considered loaded.

Public Class Methods

new(ole_session, url, lookup_url = nil) click to toggle source

@param ole_session [Object] The OLE_QA::Framework::Session instance in which the page should load. @param url [String] The URL (if any) used to open the page. (Set to “” if unused.) @param lookup_url [String] The URL (if any) by which a document represented by the page can be opened.

- The string must contain the replacement token '_DOC_ID_' where a document ID is to be inserted.
Calls superclass method OLE_QA::Framework::Common_Object::new
# File lib/common/page.rb, line 36
def initialize(ole_session, url, lookup_url = nil)
  super(ole_session)
  @url = url
  @lookup_url = lookup_url
  @wait_on = Array.new
  @lines = Array.new
  wait_for_elements if defined?(self.wait_for_elements)
  set_lines if defined?(self.set_lines)
end

Public Instance Methods

line(name, klas, force = false)
Alias for: set_line
lookup(doc_id) click to toggle source

Open the page by lookup URL and return true if successful, false if not.

# File lib/common/page.rb, line 63
def lookup(doc_id)
  if !@lookup_url.nil?
    @browser.goto(lookup_url(doc_id))
    true
  else
    false
  end
end
lookup_url(doc_id) click to toggle source

Return the URL used to open a specific document by given document number.

# File lib/common/page.rb, line 58
def lookup_url(doc_id)
  @lookup_url.nil? ? nil : (@ole.url + @lookup_url.gsub('_DOC_ID_', doc_id.to_s))
end
open(url = @url) click to toggle source

Open the page via URL. @note Some pages may not have custom open URLs. If this is the case,

this method can be passed a lookup URL with a document ID #.

@note This method will invoke the wait_for_elements method if it is defined on a page. @note If a page has declared elements to wait on, invoking this method will return

an array of the symbols used to call those methods.
# File lib/common/page.rb, line 52
def open(url = @url)
  @browser.goto(url)
  wait_for_page_to_load
end
set_elements() click to toggle source

Set screen elements common to most or all pages across the OLE interface.

# File lib/common/page.rb, line 126
def set_elements
  # These elements exist outside of any frame, so @browser is used to force
  #   Watir-Webdriver to give access to a bare browser even on a page with a frame.
  #   See {OLE_QA::Framework::Helpers#browser} for frame handling.
  element(:login_field)           {@browser.text_field(:name => 'backdoorId')}
  element(:login_button)          {@browser.input(:class => 'go', :value => 'Login')}
  element(:logout_button)         {@browser.input(:class => 'go', :value => 'Logout')}
  element(:login_confirmation)    {@browser.div(:id => 'login-info').strong(:text => /Impersonating User\:/)}
  element(:loading_message)       {@browser.img(:alt => 'Loading...')}
end
set_functions() click to toggle source

Set functions common to most or all pages across the OLE interface.

# File lib/common/page.rb, line 138
def set_functions
  # Login as a given user.
  # @param username [String] The username to use.
  # @return [Boolean] Whether the login process succeeded.
  function(:login)                {|as_who = 'ole-khuntley'| raise OLE_QA::Framework::Error,"Login field not present on this page: #{self.class.name}" unless login_field.present? ; login_field.set(as_who) ; login_button.click ; if login_confirmation.present? then login_confirmation.text.match(/#{as_who}/) ? true : false else false end}
  # Logout from previous login.
  # @return [Boolean] Whether the logout process succeeded.
  function(:logout)               { logout_button.click ; login_confirmation.present? ? false : true}
end
set_line(name, klas, force = false) click to toggle source

Set a line object definition on a page object.

  • A line object created with this method becomes an accessor attribute associated with an instance variable on the page or data object on which it is created.

@param name [Symbol] The name the new line object will have on the object.

(This will be an instance variable, so it cannot contain spaces.)

@param klas [Class] The class to instantiate for the new line object.

(An error will be returned if the class given is not defined.)

@param force [Boolean] If set to true, this method can be used to override an existing line object definition.

@raise StandardError if a parameter is of an incorrect type. @raise StandardError if an instance method already exists for a line object with the same name.

(Suppress with force = true.)
# File lib/common/page.rb, line 115
def set_line(name, klas, force = false)
  raise StandardError, "Name must be a symbol.  Given:  #{name}  (#{name.class})" unless name.instance_of?(Symbol)
  raise StandardError, "Klas must be a class.  Given:  #{klas}  (#{klas.class})"  unless klas.instance_of?(Class)
  raise StandardError, "Line object is already defined.  (Use the 'force = true' option to suppress this error.)" if @lines.include?(name) && ! force
  instance_variable_set("@#{name}", klas.new(@ole, 1))
  make_reader(name) unless force
  @lines << name unless force
end
Also aliased as: line
wait_for_element(element) click to toggle source

Use this method on subclasses to define elements that must be loaded for the page to be considered completely loaded. This method can be called individually or will be called on an open command if .wait_for_elements is defined on the subclass.

# File lib/common/page.rb, line 86
def wait_for_element(element)
  self.send(element).wait_until_present(@ole.explicit_wait)
end
wait_for_elements() click to toggle source

Define this method on a subclass. Add element symbols to the @wait_on array. This will require the open method to wait for each of these elements to be present before it finishes.

e.g.
def wait_for_elements
  @wait_on << :title
  @wait_on << :close_button
  super
end
# File lib/common/page.rb, line 81
def wait_for_elements
end
wait_for_page_to_load() click to toggle source

Call this method on a page that has wait_for_elements defined to wait for all required elements on that page to load.

# File lib/common/page.rb, line 92
def wait_for_page_to_load
  @wait_on.each { |element| wait_for_element(element) }
  loading_message.wait_while_present if loading_message.present?
  true
rescue
  false
end