Squish offers a number of verification points, or VPs: object property verification, screenshot verification, table verification or visual verification. We can create verification points during the initial recording of a test case or while recording a snippet. When doing so we need to select an object that we want to verify, which is easily done using the Pick Tool, a tool that allows us to point to the object. But what if we want to verify multiple objects in the GUI and picking all of them is not convenient? For example, we might want to verify a size of all labels on the screen or validate all cells in a given table column. This article describes how such bulk verifications can be done easly.

The presented solution takes advantage of the findAllObjects function introduced in Squish 6.4. All code snippets are written in Python for an example Qt Widgets application.

Verify All Labels

To verify all labels in a given window, let’s first define a helper function to find all objects by type:

def findObjectsByTypeOnWindow(objType, window):
return findAllObjects({"type": objType, "visible": 1, "window": window})

Here is an example usage of the above function to verify the size and style of the labels:

labels = findObjectsByTypeOnWindow('QLabel',names.address_Book_Add_Dialog)
for obj in labels:
test.startSection("Verify label: " + str(obj.text))
test.compare(obj.font.pointSize, 8, "pointSize is 8")
test.compare(obj.font.bold, False, "is not bold")
test.compare(obj.font.italic, False, "is not italic")

Verify All Cells in a Column

Static tables can be verified using table verification points. This approach is good when we want to verify the entire table which always has the same size. But what if table size varies, and we would like to verify just one column? Imagine, also, that we don’t want to check the exact values, but we would like to define a condition for the values.

Let’s start by defining a validator function with a condition that a cell must meet. In the example below, we implement a function which verifies if a cell has a positive integer value. You can easily create your own validators that can check other conditions, for example if a value is in a given range or if it matches a string pattern.

def positiveValidator(n):
return n.isdigit()

Now, let’s define a function which validates all cells in a column.

def validateCellsInColumn(column, table, validator):
cells = findAllObjects({"column": column, "container": table,"type": "QModelIndex"})
for cell in cells:
test.verify(validator(cell.text), "Validate cell with text: " + cell.text)

Finally, a code snippet from a test case where this function is called:

validateCellsInColumn(3, names.address_Book_Unnamed_File_QTableWidget, positiveValidator)

1 Comment

Thank you! I was looking for a way to do something like this, and just found your article!

I’m trying to work through nested lists, with further nested values in a Windows 10 desktop app, using Squish, Robot Framework and Python. Could you point me to any other related examples? I’ve been trying to convert your examples above for my purposes, but so far, no success. I’m a relative newbie to this…

Within the app, the LHS window list of labels is always displayed, but the RHS changes to display a new list of labels and data according to what was clicked on the LHS. This is a common theme in this Windows 10 desktop app, so understanding how verify items in bulk would be very helpful.

Thank you again.


Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap