Testing or waiting for an expected property value

Last edited on

Overview

There are cases where you want to wait for an object to be visible and one of its properties

to have an expected value.

To make this easy to do for testers one can introduce a helper function (waitForPropertyValue() in the examples below).

JavaScript

function main()
{
    // Register squish_dir/examples/qt/addressbook
    // for this example code:
    startApplication("addressbook");

    // This will fail, unless you create a new
    // address book and add a single entry to it,
    // but it demonstrates how to use this
    // function:
    if not waitForPropertyValue("{type='QTableWidget' visible='1'}", "rowCount", 1, 20000) {
        test.fail("Property did not have the expected value");
    } else {
        test.passes("Property had the expected value");
    }
}


/**
 * Waits for property value of an already existing object
*/
function waitForPropertyValue(objectName, propertyName, expectedValue, timeoutInMilliseconds)
{
    var condition = "findObject(objectName)." + propertyName + " == expectedValue";
    return waitFor(condition, timeoutInMilliseconds));
}

Python

def main():
    # Register squish_dir/examples/qt/addressbook
    # for this example code:
    startApplication("addressbook")

    # This will fail, unless you create a new
    # address book and add a single entry to it,
    # but it demonstrates how to use this
    # function:
    if not waitForPropertyValue("{type='QTableWidget' visible='1'}", "rowCount", 1, 20000):
        test.fail("Property did not have the expected value")
    else:
        test.passes("Property had the expected value")


def waitForPropertyValue(objectName, propertyName, expectedValue, timeoutInMilliseconds):
    """Waits for property value of an already existing object"""

    condition = "findObject(objectName)." + propertyName + " == expectedValue";
    return waitFor(condition, timeoutInMilliseconds));