Module: WatirRobot::Table

Included in:
KeywordLibrary
Defined in:
lib/watir_robot/keywords/table.rb

Overview

Functionality related to HTMl tables, including headers, bodies, footers, and cells

Instance Method Summary (collapse)

Instance Method Details

- (String) get_table_cell(loc, row, col)

Get contents of a single table cell

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • row (String)

    with the top-most row as 1, the number of the row in question

  • col (String)

    with the left-most row as 1, the number of the column in question

Returns:

  • (String)

    the text contained within the targeted table cell



18
19
20
21
22
# File 'lib/watir_robot/keywords/table.rb', line 18

def get_table_cell(loc, row, col)
  row = row.to_i - 1
  col = col.to_i - 1
  @browser.table(parse_location(loc))[row][col].text
end

- (Object) table_cell_should_contain(loc, row, col, text)

Verify that table cell contains certain contents

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • row (String)

    with the top-most row as 1, the number of the row in question

  • col (String)

    with the left-most row as 1, the number of the column in question

  • text (String)

    the text to compare against

Raises:

  • (ElementMatchError)


35
36
37
38
39
40
# File 'lib/watir_robot/keywords/table.rb', line 35

def table_cell_should_contain(loc, row, col, text)
  row = row.to_i - 1
  col = col.to_i - 1
  raise(ElementMatchError, "The table cell at row #{row} and column #{col}, located in the table at #{loc}, does not contain the text #{text}") unless
    @browser.table(parse_location(loc))[row][col].text.include? text
end

- (Object) table_column_should_contain(loc, col, text)

Verify that a table column contains certain contents

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • col (String)

    with the left-most row as 1, the number of the column in question

  • text (String)

    the text to compare against

Raises:



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/watir_robot/keywords/table.rb', line 49

def table_column_should_contain(loc, col, text)
  # There's no "nice" way to do this, so we run through each row and snag
  #   the cell at offset y
  col = col.to_i - 1
  content = ''
  @browser.table(parse_location(loc)).rows.each do |row|
    content << ' '
    content << row[col].text
  end
  
  raise(Exception::ElementMatchError, "The table column number #{c} in the table located at #{loc} does not contain the text #{text}") unless
    content.include? text
end

- (Object) table_header_should_contain(loc, text)

Verify that a table's header contains certain contents

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to compare against

Raises:



69
70
71
72
# File 'lib/watir_robot/keywords/table.rb', line 69

def table_header_should_contain(loc, text)
  raise(Exception::ElementMatchError, "The table header of the table located at #{loc} does not contain the text #{text}") unless
    @browser.table(parse_location(loc)).thead.text.include? text
end

- (Object) table_row_should_contain(loc, row, text)

Verify that a table row conatins certain contents

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • row (String)

    with the top-most row as 1, the number of the row in question

  • text (String)

    the text to compare against

Raises:



81
82
83
84
85
# File 'lib/watir_robot/keywords/table.rb', line 81

def table_row_should_contain(loc, row, text)
  row = row.to_i - 1
  raise(Exception::ElementMatchError, "The table row number #{row} in the table located at #{loc} does not contain the text #{text}") unless
    @browser.table(parse_location(loc))[row].text.include? text
end

- (Object) table_should_contain(loc, text)

Verify that certain content is contained somewhere within an entire HTML table

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to compare against

Raises:



93
94
95
96
# File 'lib/watir_robot/keywords/table.rb', line 93

def table_should_contain(loc, text)
  raise(Exception::ElementMatchError, "The table located at #{loc} does not contain the text #{text}") unless
    @browser.table(parse_location(loc)).text.include? text
end