Writing Operation Code

Applies to TestComplete 15.40, last modified on March 25, 2022

The code of a custom keyword test operation consists of a number of script routines. These are:

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 OnExecute event.

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 aqFileSystem.CopyFile method:


    <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">
                        <Parameter Name="Source"/>
                        <Parameter Name="Destination"/>
                        <Parameter Name="RenameOnCollision"/>
                        <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)
  return true;

function CopyFile_OnExecute (Data, Source, Destination, RenameOnCollision)
  var result = aqFileSystem.CopyFile(Source, Destination, RenameOnCollision);
  if (! result)
    Log.Error("Failed to copy the \"" + Source + "\" file.");
  return result;


Sub CopyFile_OnCreate (Data, Parameters)
  Parameters.Source = ""
  Parameters.Destination = ""
  Parameters.RenameOnCollision = True
End Sub

Function CopyFile_OnSetup(Data, Parameters)
  CopyFile_OnSetup = True
End Function

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.")
  End If
End Function

See Also

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

Highlight search results