等待对象 属性 在 squish 中设置

Wait for an object property to be set in squish

我正在使用 Squish 6.3 Qt。我正在测试的应用程序包含一个 QLabel ,其内容动态变化。 是否可以等待标签设置为特定值? 我不能使用 waitForObject,因为对象始终存在,只有它的文本值不断变化。

这个例子来自Example - Testing or waiting for an expected property value:

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));

添加 TimeoutMilliseconds 不起作用,所以我添加了 time.sleep(Seconds),这对我来说效果更好。

根据的回答,正确的条件实现是:

condition = "findObject('{}').".format(objectName) + propertyName + "==" + str(expectedValue);