I am starting the process of converting my WATIR scripts to use WATIR webdriver.
There a couple of table methods I was using in my WATIR scripts to check the size (rows and columns) of a HTML table.
myTable.row_count
myTable.column_countThese methods don't exist in webdriver so I was looking for a good way of doing the same check.
For rows this seems to give the same result as the row_count method
myTable.rows.lengthFor column count of the table I've tried converting the table to an array of strings and getting the length of the first row, but the conversion to the string array is taking a while.
myCols = myTable.strings[0].lengthAfter asking the question on StackOverFlow the solution to find the number of columns in the table was to use;
myCols = myTable.row.cells.lengthThis assumes that the first row has the correct number of columns, which in our application should always be the case.
To avoid rewriting all the unit tests I've extended the Watir::Table class at the start of the script so that it contains the missing row_count and column_count methods.
class Watir::Tabledef row_countreturn self.rows.lengthenddef column_countreturn self.row.cells.lengthendend
The unit tests now run unaltered.
If your table has a uniform number of columns for each row then you could check the whole table by doing something like.
myTable.rows.each { |myRow|myCols = myRow.cells.lengthassert_equal(validColumnCount,myCols,"Column count mismatch")}
Doodle's Geek Monkey by Alastair Montgomery


0 comments:
Post a Comment