Class: Page

Inherits:
Object
  • Object
show all
Defined in:
lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb

Overview

Base class that every defined page will inherit from

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, field, value = nil) ⇒ Page

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.



16
17
18
19
20
21
# 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

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



5
6
7
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 5

def browser
  @browser
end

#displayed_fieldObject

Returns the value of attribute displayed_field.



4
5
6
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 4

def displayed_field
  @displayed_field
end

#displayed_valueObject

Returns the value of attribute displayed_value.



4
5
6
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 4

def displayed_value
  @displayed_value
end

#field_parameters_arrayObject

stores parameters of each field added to the page



6
7
8
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 6

def field_parameters_array
  @field_parameters_array
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 4

def name
  @name
end

Instance Method Details

#add_field(name, type, key, value) ⇒ Object

Defines methods to access the field of specified type, by specified key & value



72
73
74
75
# 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

#add_field_using_constructor_class(name, type, key, value) ⇒ Object

Defines methods to access the field of specified type, by specified key & value



86
87
88
# 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_page(page_object) ⇒ Object

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



79
80
81
82
83
# 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

#displayed?(wait = true) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

#wait_until_displayed(timeout = 5) ⇒ Object

Method to wait for the page to be displayed, up to <timeout> seconds Returns displayed status (true/false)



58
59
60
61
62
63
64
65
66
67
68
69
# 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