How to verify a custom table widget?

Squish GUI Tester operates the Application Under Test (AUT) to run through test steps. Of course that is not enough. It also needs to verify that the right thing has happened. There are various ways to achieve that: Squish has verification points for single properties, the visual appearance of a widget or window - and whole tables. The Table Verification Point only works for a number of supported GUI controls though. So how can you do the same for your custom table widget?

There is one basic requirement for verifying table contents: Squish needs access to individual table cells. Consequently, the table widget needs to have getters to fetch the number of rows and columns as well as individual cell contents. For the expected data, we can leverage Squish's TestData API. That way we can load expectations from different file formats.

For the sake of writing a script function, let's pretend Qt's QTableWidget did not work with Table VPs in Squish. We would need a function that takes the table to verify and the file name for expected data:

def checkTableAgainstTestdata(table, testDataFileName):
dataset = testData.dataset(testDataFileName) columns = table.columnCount rows = table.rowCount
   tableName = objectMap.symbolicName(table)
  test.log(f"Verifying table {tableName}")
testDataColumns = len(testData.fieldNames(dataset[0])) if columns != testDataColumns: test.fail("Table does not match test data", f"Table has a different number of columns than the test data " f"in {testDataFileName}:\n{tableName}") return for row, record in enumerate(testData.dataset(testDataFileName)): if row >= rows: test.fail("Table does not match test data", f"Table has different number of rows than the test data " f"in {testDataFileName}:\n{tableName}") return for col in range(columns): expectedText = testData.field(record, col) actualText = table.item(row, col).text() test.compare(expectedText, actualText, f"({row}|{col})")

The test data file is expected to live in either the test case's "testdata" directory or in the shared testdata directory. Given that data, it fetches the number of rows and columns from the table. Then it iterates over the table cells and verifies each cell's contents by calling test.compare(...). The results of that comparison will end up in Squish's test report.

A sample invocation might look like this:

def main():
# Do some testing here...

table = waitForObject("{type='QTableWidget' visible='1'}")
testDataFileName = "expectedvalues.tsv"
checkTableAgainstTestdata(table, testDataFileName)

Squish Free Trial

Try Squish out for free with a fully-supported and fully-functional trial of any Squish edition.

Comments

    The Qt Company acquired froglogic GmbH in order to bring the functionality of their market-leading automated testing suite of tools to our comprehensive quality assurance offering.