Checking Conditions

Applies to TestComplete 15.69, last modified on November 13, 2024

While working with application objects and controls, you may need to perform certain actions depending on the state of certain objects or controls. This topic describes the approaches that you can use to create conditional statements in your keyword tests.

Using the If Object Operation

This operation is intended for checking the following conditions:

  • Exists
  • Does not exist
  • Enabled
  • Disabled
  • Visible
  • Invisible

To configure checking of a condition, do the following:

  • Add the If Object operation to your keyword test. This will invoke the wizard.

  • Specify the object or control whose state you want to check. Press Next.

  • Specify the condition to be checked. For detailed information on specifying conditions, see the operation’s description.

  • After you specify the needed condition, press Finish.

  • Add the operations to be executed if the condition is met as the child operations of the If Object operation.

  • Add the operations to be executed if the condition is broken. To do this, add the Else operation right after the If Object operation and add the needed operations as the child items of the Else operation.

The following image shows a sample keyword test that checks if Notepad is running (that is, if Notepad's process exists in the system):

Using the If..Then Operation

The If Object operation lets you check only a limited number of object states. If you want to perform advanced checking (for example, if you need to check whether a check box control is checked or unchecked), use the If..Then operation.

To configure checking of a condition, do the following:

  • Add the If..Then operation to your keyword test.

  • In the ensuing dialog, specify the condition to be met and press OK. For detailed information on specifying conditions, see the If..Then operation description.

  • To specify the operations that will be executed if the condition is met, add the needed operations to the test as child items of the If..Then operation.

  • To specify the operations to be executed if the condition is broken, add the Else operation right after the If..Then operation and add the needed operations as child items of the Else operation.

The following image shows a sample keyword test that checks whether the specified check box is in the checked state.

Tip: You can also modify parameters of the operations that are already added to the test. To do this, use the special dialogs and in-place editors of the Keyword Test editor.

See Also

Keyword Tests
Creating Keyword Tests - Common Tasks

Highlight search results