Skip to main content

A Demo Mode or Using Highlighting for more "Visual" Test Script Execution

Since version 6.3 Squish offers highlightObject(), which highlights the specified object on the screen, similar to how it is done when selecting an object in the "Application Objects" view of the Squish IDE:


 

Since this is a function we can use it in our test scripts:
[code language="python" highlight="6" title="test.py"]def main():
startApplication("itemviews")

# Highlight the object we are going to click
# on next:
highlightObject(waitForObjectItem("{occurrence='2' type='QListView'}", "All's Well That Ends Well"))
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "All's Well That Ends Well"), 64, 11, 0, Qt.LeftButton)

mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "Pericles, Prince of Tyre"), 11, 8, 0, Qt.LeftButton)
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "The Winter's Tale"), 66, 13, 0, Qt.LeftButton)

[/code]
But what if we want to use this to highlight not only a single object, but all objects that are about to be clicked? If we follow the above approach we would need to call highlightObject() before every mouseClick(), activateItem(), etc. So in the above example we would need to add two more calls to highlightObject().

 

Fortunately there is an easier way to achieve this:

In this blog article we already mentioned the functions waitUntilObjectReady() and waitUntilObjectItemReady().

These functions are being called after Squish found an object and determined that it is ready for interaction via waitForObject() and waitForObjectItem() respectively. What if we combine these functions with highlightObject()? The result is a very easy way to add GUI object highlighting in a centralized manner:
[code language="python" highlight="8-10, 12-13" title="test.py"]def main():
startApplication("itemviews")
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "All's Well That Ends Well"), 64, 11, 0, Qt.LeftButton)
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "Pericles, Prince of Tyre"), 11, 8, 0, Qt.LeftButton)
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "The Winter's Tale"), 66, 13, 0, Qt.LeftButton)
mouseClick(waitForObjectItem("{occurrence='2' type='QListView'}", "All's Well That Ends Well"), 64, 11, 0, Qt.LeftButton)

def waitUntilObjectReady(obj):
snooze(0.5)
highlightObject(obj, 500)

def waitUntilObjectItemReady(obj):
waitUntilObjectReady(obj)

[/code]
 

Executing the above test script results in each of the GUI objects being highlighted:


 

Since the above approach changes the timing of the script execution and its access to the AUT (Application Under Test), it is to be expected that this may cover up timing issues that usually result in object not found errors when executing the test script without the above functionality.

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.