Could you help to advise some script to validate a table cells for empty values? I need to validate that there are no empty cells in table.
tableFG = page.table(:id => 'FinancialsGrid')
tableFG.rows.each do |row|
row.cells.each do |cell|
expect(cell.tableFG_element.text).should_not be_nil
end
end
May be there is another way to check for empty values.
The one thing I do not like about manually writing a loop to iterate through and validate each cell is that you only see the result of the first failure. If there are say two cells that are blank, the test failure will only show one.
As a result, I try to make use of the built-in expectation matchers that check each element (ex
all
). For example, the following gets the length of text of each cell and makes sure that it is at least 1 character long. Note that Watir strips leading/trailing whitespaces, so a length of 1 should be an actual character.A failed expectation would look like the following and include each cell that fails:
Using the page-object gem would be similar (with slightly different methods). Assuming the table is defined in the page as the
financials_grid
: