class PageObject::Elements::Table

Public Class Methods

new(element, platform) click to toggle source
# File lib/page-object/elements/table.rb, line 6
def initialize(element, platform)
  @element = element
  include_platform_for platform
end

Public Instance Methods

each() { |self| ... } click to toggle source

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

@return [PageObject::Elements::TableRow]

# 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_row() click to toggle source

return the first row

@return PageObject::Elements::TableRow

# File lib/page-object/elements/table.rb, line 27
def first_row
  self[0]
end
hashes() click to toggle source

return the table as hashes

@return Hash

# 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_row() click to toggle source

return the last row

@return PageObject::Elements::TableRow

# File lib/page-object/elements/table.rb, line 36
def last_row
  self[-1]
end

Protected Instance Methods

child_xpath() click to toggle source
# File lib/page-object/elements/table.rb, line 54
def child_xpath
  ".//child::tr"
end
include_platform_for(platform) click to toggle source
# File lib/page-object/elements/table.rb, line 63
def include_platform_for platform
  super
  if platform[:platform] == :watir_webdriver
    require 'page-object/platforms/watir_webdriver/table'
    self.class.send :include, PageObject::Platforms::WatirWebDriver::Table
  elsif platform[:platform] == :selenium_webdriver
    require 'page-object/platforms/selenium_webdriver/table'
    self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Table
  else
    raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
  end
end
initialize_row(row_element, platform) click to toggle source
# File lib/page-object/elements/table.rb, line 58
def initialize_row(row_element, platform)
  ::PageObject::Elements::TableRow.new(row_element, platform)
end