The code of a custom keyword test operation consists of a number of script routines. These are:
- A routine that is executed by the operation during the test run.
- A routine that is executed when an operation instance is created (see Creating Operation Initialization Routine).
- A routine that is executed when the operation is being set up (see Creating the Operation Setup Routine).
- Routines that return data to be displayed in the Keyword Test editor (see Customizing KeywordTest Editor Contents).
- Routines that handle events of in-place editors used by the operation in the Keyword Test editor (see Implementing In-Place Editing Support).
- Routines that add recording support for the operation (see Implementing Recording Support).
All of these routines are optional, however, an operation should at least have the routine to run during the test execution. The rest of this topic discusses the creation of these routines.
Each keyword test operation (except for helper operations, such as Comment) is supposed to perform certain actions during the test run. For example, simulate user actions over the tested application’s objects, perform certain verifications, read data from or save it to a file, and so on. This functionality is provided by the script routine that handles the operation’s
The routine to be used as the
OnExecute event handler must meet the following requirements:
It must have the Data argument, which provides access to the operation fields (if any), plus a number of arguments that correspond to individual parameters of the operation. The parameters must be listed in the same order as they are defined in the script extension’s description.xml file.
If the operation is supposed to return a value, the routine must return this value, that is, it must be a function. Otherwise, the routine must have no return value, that is, it must be a procedure.
Put the code that performs the desired action in the routine body. For instance, if the operation provides a custom checkpoint, this routine could perform the appropriate verification actions and return the check result - True if verification succeeded and False if it failed. Note, that in the operation code you can use not only intrinsic functionality of the chosen scripting language, but also some of TestComplete objects (see Objects Available to Script Extensions).
The following example provides the code of a sample Copy File operation, which is a wrapper over the
<Category Name="Keyword Test Operations">
<ScriptExtension Name="Copy File Operation" Author="SmartBear Software" Version="1.0">
<Script Name=""> <!-- Specify the script file name here -->
<KDTOperation Name="Copy File" Category="Files and Directories">
<Column Name="Item" Value="Copy File" />
<Column Name="Value" Editable="True" EditorType="Parameters" />
<Event Name="OnCreate" Routine="CopyFile_OnCreate" />
<Event Name="OnSetup" Routine="CopyFile_OnSetup" />
<Event Name="OnExecute" Routine="CopyFile_OnExecute" />
function CopyFile_OnCreate (Data, Parameters)
Parameters.Source = "";
Parameters.Destination = "";
Parameters.RenameOnCollision = true;
function CopyFile_OnSetup(Data, Parameters)
function CopyFile_OnExecute (Data, Source, Destination, RenameOnCollision)
var result = aqFileSystem.CopyFile(Source, Destination, RenameOnCollision);
if (! result)
Log.Error("Failed to copy the \"" + Source + "\" file.");
Sub CopyFile_OnCreate (Data, Parameters)
Parameters.Source = ""
Parameters.Destination = ""
Parameters.RenameOnCollision = True
Function CopyFile_OnSetup(Data, Parameters)
CopyFile_OnSetup = True
Function CopyFile_OnExecute (Data, Source, Destination, RenameOnCollision)
CopyFile_OnExecute = aqFileSystem.CopyFile(Source, Destination, RenameOnCollision)
If Not CopyFile_OnExecute Then
Log.Error "Failed to copy the """ & Source & """ file.")
Creating Keyword Test Operations
Creating Keyword Test Operations - Basic Concepts
Creating Operation Parameters and Fields
Creating Operation Initialization Routine
Creating the Operation Setup Routine
Customizing KeywordTest Editor Contents
Implementing In-Place Editing Support