Skip to content
bfaloona edited this page Sep 13, 2010 · 5 revisions

WatirCraft offers specialized table definitions that make verifing and
accessing tables much easier.

To define table on a page, you must first add an element to wrap the entire table,
then the table and its fields:

element(:items_table) {browser.table(:index, 1)}
table(:items) do
  field(:quantity) {row.cell(:index, 1)}
  field(:description) {row.cell(:index, 2)}
end
field(:total) {browser.cell(:id, 'totalcell')}

You can then test specific rows in the table:

some_page.items.row(:description => 'Pragmatic Testing').quantity.should == "3"

There are several things going on here:

  1. The row method of the “items” table allows you to select a specific row of
    the table by reference to any of the fields defined on the table.
  2. You can use any of the defined fields on the selected row.

Additional points:

  1. If no row matchs the selector, the row method will return nil.
  2. You can define input fields, just like with pages. This is useful, e.g.,
    if there are checkboxes in the table.
  3. You can define elements, just like with pages. This is usefule, e.g.,
    if there are buttons in the table.
  4. Index values are 1 based
Clone this wiki locally