Class: PageObject::IndexedProperties::TableOfElements

Inherits:
Object
  • Object
show all
Includes:
PageObject
Defined in:
lib/page-object/indexed_properties.rb

Constant Summary

Constants included from PageObject

VERSION

Instance Attribute Summary

Attributes included from PageObject

#browser, #platform

Instance Method Summary collapse

Methods included from PageObject

add_framework, #alert, #attach_to_window, #back, #clear_cookies, #confirm, #current_url, default_element_wait, default_element_wait=, default_page_wait, default_page_wait=, #element_with_focus, #execute_script, #forward, #html, #in_frame, #in_iframe, included, #initialize_browser, javascript_framework=, #method_missing, #modal_dialog, #navigate_to, #prompt, #refresh, register_widget, #respond_to_missing?, #save_screenshot, #text, #title, #wait_for_ajax, #wait_until

Methods included from PagePopulator

#populate_page_with

Methods included from ElementLocators

#element, included

Constructor Details

#initialize(browser, identifier_list) ⇒ TableOfElements


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/page-object/indexed_properties.rb', line 6

def initialize (browser, identifier_list)
  initialize_browser(browser)
  @identifier_list = identifier_list
  @indexed_property_class = Class.new {
    include PageObject
    extend Accessors

    def initialize (browser, index, identifier_list)
      initialize_browser(browser)

      identifier_list.each do |identifier|
        type = identifier[0]
        name = identifier[1]
        how_and_what = identifier[2].clone # Cannot modify the original...
        how_and_what.each do |key, value|
          next if value.is_a? Regexp # Cannot format Regexp with %
          if key == :index
            how_and_what[key] = (value % index).to_i
          elsif key == :frame
            how_and_what[key] = value #passthrough frame without modification
          else
            how_and_what[key] = value % index
          end
        end
        self.class.send type, name, how_and_what unless Class.instance_methods.include? name
      end
    end
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PageObject

Instance Method Details

#[](index) ⇒ Object


36
37
38
# File 'lib/page-object/indexed_properties.rb', line 36

def [] (index)
  @indexed_property_class.new(@browser, index, @identifier_list)
end