This topic explains specifics of creating custom If Then
operations for your keyword tests.
About Conditional Operations
Conditional operations are keyword-test operations that check some conditions during test run and then execute or do not execute child operations based on the results of the check. Typical examples of conditional operations are the If... Then, If Object and If Browser operations built into TestComplete. You can create custom conditional keyword-test operations that check specific conditions like file or folder existence or availability of windows or controls under test.
About Creating Custom Conditional Operations
Creating conditional operations is very similar to creating any other keyword test operation. You need to do the following:
-
Declare the operation and define its parameters in the description.xml file.
-
Implement script code that will handle the operation’s events and implement the operation’s functionality.
For information on creating custom keyword-test operations, see topics of the Creating Keyword Test Operations section. This topic explains specifics of creating custom conditional operations.
Declaring Conditional Operations
-
You declare conditional operations in the same manner in which you declare other custom keyword-test operations. You can find an example below. For detailed information on elements and attributes, see Structure of the Description File.
-
Important: in order for the test engine to recognize your operation as a conditional operation, the OperationType attribute of the KDTOperation element must be equal to Condition. You should also specify handlers for events that are specific to conditional operations (see below for information on these events):
XML
[File: description.xml]
<?xml version="1.0" encoding="UTF-8"?>
<ScriptExtensionGroup>
<ScriptExtension Name="My Conditional Operation" Author="John Smith" Version="1.0" HomePage="someURL.com">
<Script Name="myUnit1.js">
<KDTOperation Name="My Conditional Operation" Category="My Category" Icon="clc-icon.bmp" OperationType="Condition">
<Data>
...
</Data>
<Events>
<Event Name="OnCreate" Routine="MyOp_OnCreate"/>
<Event Name="OnSetup" Routine="MyOp_OnSetup"/>
<Event Name="OnExecute" Routine="MyOp_OnExecute"/>
<Event Name="CanExecuteBody" Routine="MyOp_OnCanExecuteBody"/>
</Events>
<Columns>
...
</Columns>
</KDTOperation>
</Script>
<Description>
...
</Description>
</ScriptExtension>
</ScriptExtensionGroup> -
Like any other keyword-test operation, custom conditional operations can have parameters and fields. You may want to define some parameters that will specify the condition to be checked. For instance, if you create an operation that verifies whether a file or folder exists on hard drive, create a parameter that will specify the name of the desired file or folder. For information on defining parameters and fields, see Creating Operation Parameters and Fields.
Events to Be Implemented
The functionality of custom keyword-test operations is implemented by script event handlers that are called at needed points of time. Some of the events are triggered during the test run, and their event handlers implement the operation's behavior. Some other events occur at design time, and their event handlers let users configure the operation’s parameters. Below is a description of such events.
Run-Time Events
The following events are triggered at run time. Write event handlers for them to implement the operation’s behavior:
OnExecute
- Occurs when the test engine starts executing your conditional operation.CanExecuteBody
- Occurs after the OnExecute
event.Some notes on implementing event handlers:
-
The
CanExecuteBody
event handler should returntrue
orfalse
:true
indicates that the test engine should run child operations; andfalse
means the child operations should not be executed. -
Checking conditions can take some time. It is recommended that you perform all needed checks within the
OnExecute
event handler, save the results to some global script variable and use theCanExecuteBody
handler to return the variable’s value (that is, to return the results of the check).
Design-Time Events
Design-time events of custom loop operations do not differ from events of other operations. Here is information on some events for which you may want to create event handlers:
-
OnCreate
- This event is triggered only once, when your operation is added to a keyword test. Write an event handler for it to perform initialization actions for the operation. See Creating Operation Initialization Routine. -
OnSetup
- This event is triggered every time when a user modifies your operation’s properties. This happens, for instance, when the user adds the operation to their test, or the user double-clicks the operation in the Keyword Test editor to modify the operation’s properties. See Creating the Operation Setup Routine. -
You can also create script routines that handle column editing events:
StartEditing
,GetEditValue
,SetEditValue
, andApplyChanges
. See Implementing In-Place Editing Support.
See Also
Creating Conditional, Loop and Group Operations
Creating Keyword Test Operations
Creating Keyword Test Operations - Basic Concepts