Class: OLE_QA::Framework::Page
- Inherits:
-
Common_Object
- Object
- Common_Object
- OLE_QA::Framework::Page
- Includes:
- Page_Helpers
- Defined in:
- lib/common/page.rb
Overview
An OLE Page object
Direct Known Subclasses
DocStore::Results, DocStore::Search, OLEFS::E_Doc, OLEFS::Lookup, OLEFS::Main_Menu, OLELS::Batch_Job_Details, OLELS::Batch_Job_Report, OLELS::Batch_Process, OLELS::Batch_Profile, OLELS::E_Doc, OLELS::Editor, OLELS::Item_Lookup, OLELS::Loan, OLELS::Lookup, OLELS::Main_Menu, OLELS::Request, OLELS::Return, OLELS::Staff_Upload
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
An array containing the name (Symbol) of each line object on the page object.
-
#url ⇒ Object
readonly
The URL to open a given page.
-
#wait_on ⇒ Object
readonly
An array containing the elements (Symbol) to wait on before the page is considered loaded.
Attributes inherited from Common_Object
Instance Method Summary collapse
-
#initialize(ole_session, url, lookup_url = nil) ⇒ Page
constructor
A new instance of Page.
-
#lookup(doc_id) ⇒ Object
Open the page by lookup URL and return true if successful, false if not.
-
#lookup_url(doc_id) ⇒ Object
Return the URL used to open a specific document by given document number.
-
#open(url = @url) ⇒ Object
Open the page via URL.
-
#set_elements ⇒ Object
Set screen elements common to most or all pages across the OLE interface.
-
#set_functions ⇒ Object
Set functions common to most or all pages across the OLE interface.
-
#wait_for_element(element) ⇒ Object
Use this method on subclasses to define elements that must be loaded for the page to be considered completely loaded.
-
#wait_for_elements ⇒ Object
Define this method on a subclass.
-
#wait_for_page_to_load ⇒ Object
Call this method on a page that has wait_for_elements defined to wait for all required elements on that page to load.
Methods included from Page_Helpers
Methods included from Helpers
#browser, #load_yml, #set_element, #set_function
Constructor Details
#initialize(ole_session, url, lookup_url = nil) ⇒ Page
Returns a new instance of Page.
38 39 40 41 42 43 44 45 46 |
# File 'lib/common/page.rb', line 38 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 |
Instance Attribute Details
#lines ⇒ Object (readonly)
An array containing the name (Symbol) of each line object on the page object.
27 28 29 |
# File 'lib/common/page.rb', line 27 def lines @lines end |
#url ⇒ Object (readonly)
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.
The URL to open a given page.
24 25 26 |
# File 'lib/common/page.rb', line 24 def url @url end |
#wait_on ⇒ Object (readonly)
An array containing the elements (Symbol) to wait on before the page is considered loaded.
30 31 32 |
# File 'lib/common/page.rb', line 30 def wait_on @wait_on end |
Instance Method Details
#lookup(doc_id) ⇒ Object
Open the page by lookup URL and return true if successful, false if not.
65 66 67 68 69 70 71 72 |
# File 'lib/common/page.rb', line 65 def lookup(doc_id) if !@lookup_url.nil? @browser.goto(lookup_url(doc_id)) true else false end end |
#lookup_url(doc_id) ⇒ Object
Return the URL used to open a specific document by given document number.
60 61 62 |
# File 'lib/common/page.rb', line 60 def lookup_url(doc_id) @lookup_url.nil? ? nil : (@ole.url + @lookup_url.gsub('_DOC_ID_', doc_id.to_s)) end |
#open(url = @url) ⇒ Object
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 #.
This method will invoke the wait_for_elements method if it is defined on a page.
If a page has declared elements to wait on, invoking this method will return an array of the symbols used to call those methods.
Open the page via URL.
54 55 56 57 |
# File 'lib/common/page.rb', line 54 def open(url = @url) @browser.goto(url) wait_for_page_to_load end |
#set_elements ⇒ Object
Set screen elements common to most or all pages across the OLE interface.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/common/page.rb', line 103 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 ⇒ Object
Set functions common to most or all pages across the OLE interface.
115 116 117 118 119 120 121 122 123 |
# File 'lib/common/page.rb', line 115 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) ; .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) { .click ; login_confirmation.present? ? false : true} end |
#wait_for_element(element) ⇒ Object
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.
88 89 90 |
# File 'lib/common/page.rb', line 88 def wait_for_element(element) self.send(element).wait_until_present(@ole.explicit_wait) end |
#wait_for_elements ⇒ Object
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
83 84 |
# File 'lib/common/page.rb', line 83 def wait_for_elements end |
#wait_for_page_to_load ⇒ Object
Call this method on a page that has wait_for_elements defined to wait for all required elements on that page to load.
94 95 96 97 98 99 100 |
# File 'lib/common/page.rb', line 94 def wait_for_page_to_load @wait_on.each { |element| wait_for_element(element) } .wait_while_present if .present? true rescue Watir::Wait::TimeoutError false end |