Waiting for a Property Value

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:

  • The 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.

  • The 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.


Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox