Squish Tip: Synchronization with waitUntilObjectReady()

Squish Tip: Synchronization with waitUntilObjectReady()

waitUntilObjectReady() is a callback function that by default, does nothing, but it can be defined in your test scripts to do anything you want. The method is called just before waitForObject() returns, and gets as an argument, the object that Squish thinks is now ready to get events.

It can be used for synchronizing your tests with objects that may not quite be “ready” immediately after the waitForObject() function returns. This situation can arise when the AUT has extra pending events to process, or extra graphical operations to perform, and this extra processing possibly interferes with the responsiveness of the AUT’s event loop.

The simplest use case is to add a delay after each waitForObject(). For example:

def waitUntilObjectReady(obj):

In this case, we have added a half-second delay regardless of which object was ready. When you want to watch closely what is happening during playback, this can help you generally slow things down, allowing the human eye to follow what is going on more easily. This also gives (perhaps too much) extra time to your AUT to process all pending events before getting new ones from Squish.

We could narrow the scope of waitUntilObjectReady() so it only adds delays for certain objects. In the case of the JavaFX AddressBook example, the only place where I want to add a delay is just before entering the first name in the Add Contact dialog, but I want to make it happen from all test cases. Without this delay, on my particular machine, I get intermittent failures during playback because the first name is sometimes ‘missed’ when entered into the add dialog.

def waitUntilObjectReady(obj):
    if obj.id == "forenameText":

waitUntilObjectItemReady() – for Items in Views

The Squish API also allows you to define an analogous function for Items in Views (Lists, Tables,  Trees, Menus). Like its object counterpart mentioned above, this previously undocumented function is called just before waitForObjectItem returns, and it takes a single argument. In Squish for Qt, the argument may contain the QModelIndex of an item in a Table or Tree, while in Squish for Java, we might see a TableItemProxy for an item in a JTable. The type depends on the toolkit/API you are using. This callback is also invoked after waiting for menu items and tab buttons.

def waitUntilObjectItemReady(itemOrIndex):

waitUntilObjectReady() and waitUntilObjectItemReady() are very handy callbacks that can save you lots of time when working with AUTs (or browsers, or virtual machines) that are not fast or responsive enough to reliably play back your test cases.


Trainer and Consultant for Froglogic and Qt. Co-author of "Introduction to Design Patterns in C++ and Qt"


Leave a reply

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