Class: PageObject::Elements::Table

Inherits:
Element
  • Object
show all
Includes:
Enumerable
Defined in:
lib/page-object/elements/table.rb

Instance Attribute Summary

Attributes inherited from Element

#element

Instance Method Summary collapse

Methods inherited from Element

#class_name, #click, #disabled?, #enabled?, #inspect, #method_missing, plural_form, selenium_identifier_for, #style, watir_identifier_for

Methods included from NestedElements

included

Constructor Details

#initialize(element, platform) ⇒ Table

Returns a new instance of Table.



6
7
8
9
# File 'lib/page-object/elements/table.rb', line 6

def initialize(element, platform)
  @element = element
  include_platform_for platform
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PageObject::Elements::Element

Instance Method Details

#eachPageObject::Elements::TableRow

iterator that yields with a PageObject::Elements::TableRow



16
17
18
19
20
# File 'lib/page-object/elements/table.rb', line 16

def each
  for index in 1..self.rows do
    yield self[index-1]
  end
end

#first_rowObject

return the first row

Returns:

  • PageObject::Elements::TableRow



27
28
29
# File 'lib/page-object/elements/table.rb', line 27

def first_row
  self[0]
end

#hashesObject

return the table as hashes

Returns:

  • Hash



45
46
47
48
49
50
# File 'lib/page-object/elements/table.rb', line 45

def hashes
  headers = self.first_row.map(&:text)
  self.entries[1..-1].map do |row|
    Hash[headers.zip(row.map(&:text))]
  end
end

#last_rowObject

return the last row

Returns:

  • PageObject::Elements::TableRow



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

def last_row
  self[-1]
end