Quite often you may want your automated test to wait until an object’s property gets a certain value. To implement this behavior novice users typically use loops. Here is a typical sample:
While this approach is alright, TestComplete offers a lot simpler and more powerful solution – the
WaitProperty method. This method is added to each test object: process, window, control and others. This method pauses the test execution until the specified property gets the specified value or until the specified timeout is reached. It returns True if the property gets the specified value within this time limit, otherwise it returns False. The method has the following syntax:
objectName.WaitProperty(PropertyName, PropertyValue, Timeout)
Below is a sample call to this method. It waits until the
VisibleOnScreen property of the
MyWindow object is equal to True, or until a 10 second timeout is reached (the timeout is specified in milliseconds):
Using the method rather than loops gives you a number of benefits:
You don’t have to implement the time tracking functionality. You simply specify the waiting time as the last parameter of the method.
The method calls make your test scripts shorter, simpler and more readable.
To make the timeout value more understandable, specify it using an expression rather than a hardcoded integer value:
The method supports wildcards (? and *) in the second parameter. This feature lets you use search patterns to verify string properties. If you use loops, you’ll have to implement this kind of check yourself.
As you can see, the
WaitProperty method is more powerful, easier-to-use and a lot more convenient than loops. However, there are some cases when you have to use loops:
WaitProperty method does not support indexed properties like
wItem(1). You cannot write something like
WaitProperty("wItems(1)", 1, 5000). To wait for these types of values and you have to use loops in this case.
WaitProperty method only works with one property. If you need to verify two or more property values, you have to use loops.
Hope this tip helps you create more powerful and flexible tests.
P.S. Despite the fact that in this post I use script code, you can also use this method from your keyword tests. To do this, you can use the Call Object Method, Run Code Snippet or On-Screen Action operations. I'll describe using the method in keyword tests in my next post.