class Page
Base class that every defined page will inherit from
Attributes
Public Class Methods
Name : the name of this page, e.g. rsHomepage Field : the field used to determine if the page is displayed. More precisely, the name of the method that accesses the field. E.g. if the page has a field called 'page_title' defined, then its accessor method 'page_title_field' will have been generated . If the displayed? check is against an expected value, specify the field name corresponding to the read-method (e.g. page_title), and specify the value (String or Regexp). If the displayed? check is for a field to exist, specify the field's accessor method name (e.g. page_title_field), and keep value nil.
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 16 def initialize(name, field, value = nil) @name = name @displayed_field = field @displayed_value = value @field_parameters_array = [] end
Public Instance Methods
Defines methods to access the field of specified type, by specified key & value
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 72 def add_field(name, type, key, value) field_parameters_array << [name, type, key, value] add_field_using_constructor_class(name, type, key, value) end
Defines methods to access the field of specified type, by specified key & value
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 86 def add_field_using_constructor_class(name, type, key, value) PageFieldConstructor.add_fields(self, name, type, key, value) end
Add to self all fields that were defined on page_object E.g. the supplied page_object represents part of a panel/page that is common to several pages
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 79 def add_page(page_object) page_object.field_parameters_array.each do |field_parameters| add_field(field_parameters[0], field_parameters[1], field_parameters[2], field_parameters[3]) end end
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 23 def displayed?(wait = true) displayed = false puts "in displayed? for page #{@name}" if wait puts "will wait for page to be loaded" wait_until_displayed end puts "about to send to #{@displayed_field.to_sym.inspect}" begin field_or_value = self.send(@displayed_field.to_sym) rescue Watir::Exception::UnknownObjectException # cannot find the field on the page # do nothing, displayed will stay false rescue Selenium::WebDriver::Error::StaleElementReferenceError # TODO : fix! wait then call displayed? again? puts "hit StaleElementReferenceError for page #{@name}" end puts "field_or_value retrieved is of class #{field_or_value.class}" p field_or_value if @displayed_value == nil displayed = true if field_or_value.exists? else if @displayed_value.class == Regexp displayed = true if field_or_value =~ @displayed_value else displayed = true if field_or_value == @displayed_value end end displayed end
Method to wait for the page to be displayed, up to <timeout> seconds Returns displayed status (true/false)
# File lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb, line 58 def wait_until_displayed(timeout = 5) max = timeout * 10 count = 0 displayed = false while count < max displayed = displayed?(false) break if displayed sleep 0.2 count += 2 end displayed end