Bulk Verifications of Similar Objects

Bulk Verifications of Similar Objects

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")
test.endSection()

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)

Tomasz started the adventure with Squish and GUI Testing in 2011. In 2014 he joined froglogic and is conducting Squish trainings and consulting for many companies in Europe, India and the USA.

0 Avis

Laisser une réponse

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*