Waiting for Property Values in Keyword-Driven Tests
In my previous post I wrote about using the
WaitProperty method in test scripts to pause the test execution until an object’s property has a certain value. In this post I will explain how to do this in keyword-driven tests.
To make the explanation closer to real life, let’s use Notepad and create test commands that pauses the test execution until the Size box of Notepad’s Font dialog displays 20.
- Launch Notepad.
- Select Format | Font from Notepad’s main menu. The Font dialog will appear.
- In the dialog, make sure the Size box display any value other than 20.
Create a new keyword test:
- Create a new test project in TestComplete.
- Add a new empty keyword test to the project:
- Right-click the KeywordTests node in the Project Explorer panel and choose Add | New Item from the context menu. This will call the following dialog:
- Click OK.
TestComplete will append a new keyword test to the project and open the test for editing.
Let’s now add test commands:
- In the test editor, expand the Test Actions category and drag the On-Screen Action operation to your test.
- After you drop the operation to the test, TestComplete will display the Operation Parameters wizard.
On the first page of the wizard you should select the object that will work with the operation.
To do this, drag the Finder tool () icon to the Size box of Notepad’s Font dialog:
TestComplete will display the object name in the wizard:
- The next page displays the list of methods and properties that the selected object contains.
WaitProperty method in the list. To do this faster, simply click within the list and type
WaitProperty. TestComplete will search as you are typing.
Click Next to continue.
- On the next page we need to specify the parameter of the WaitProperty method. Set the following values:
|PropertyName: ||wText (wText is the property that contains the edit box value.) |
|PropertyValue: ||20 (This is the desired value to wait for.) |
|Timeout: ||15000 (Timeout is specified in millisecond. This value corresponds to a 15 second delay.) |
- Click Finish to close the wizard. The new operation will be displayed in the test:
The On-Screen Action operation returns the same result as the method it calls, so in our case it returns the result of the
WaitProperty method. To check the method result use the If… Then operation and post messages to the log to notify us whether or not the property has the desired value.
Let’s now set another value for comparison:
- Click the ellipsis button of the Value2 cell.
- In the ensuing Edit Value dialog, enter the following values:
|Mode: ||Constant |
|Type: ||Boolean |
|Value: ||True |
- Click OK to close the Operation Parameters wizard. The If… Then operation will appear in the test.
Let’s now add operations that will post a “success” message to the log:
- In the keyword test editor, expand the Logging category and add the Log Message operation to the test. Drag the operation to the If… Then operation to make it a child of the If… Then operation.
- In the Operation Parameters dialog enter wText equals to 20. and click Finish to add the operation to the test:
Now our test looks like this:
Before running it, make sure Notepad is launched and its Font dialog is open. If you enter 20 within 15 seconds when running this test, you’ll see a “successful” message in the log. Otherwise, the log will not contain any messages. That’s all that’s needed to wait for a property value and we hope this tip helps you when you need to wait for a property value during your testing.