Creating Script Extensions - Basic Concepts

Applies to TestComplete 14.72, last modified on April 22, 2021

General Procedure

Creating a script extension includes the following steps:

  1. Plan the functionality provided by the extension

    First, you need to decide what kind of actions you would like to perform during the test recording or at design time, what kind of checkpoints you would like to create, which additional scripting objects and keyword test operations you need, and so on. Determine the steps involved in performing the desired task and think of how they can be scripted.

  2. Write the script code

    The major step is writing the script code that implements the desired action, keyword test operation or runtime object:

    • The code of a record-time or design-time action is a routine that TestComplete will run when you select an appropriate item on the Recording or Tools toolbar.

    • The code of a runtime object are routines that are run when the object’s methods are called from a script or when the object’s properties are being read or assigned.

    • The code of a keyword test operation is the routine executed by the operation during the test run, plus additional routines that enable editing of operation’s data, make the operation recordable, and perform other helper actions.

    The scripts can be written in JScript or VBScript (JavaScript, Python and DelphiScript are currently not supported). At that, VBScript files must have the .vbs extension, JScript files -- the .js extension; otherwise TestComplete will be unable to determine the source language. Also, script files must have the ANSI or UTF-8 character encoding.

    Note: The language you opt for -- JScript or VBScript -- does not affect the range of projects where the extension can be used. Script extensions are language-independent and work equally well in JavaScript, JScript, Python, VBScript, DelphiScript, C#Script and C++Script projects no matter which language was used to create an extension.

    A script extension package can include scripts written in both VBScript and JScript: for example, you could write one action or object in VBScript, another one in JScript. Note also, that references between script files are not allowed, so related routines must be located in the same script.

    You can learn how to write the code of script extensions from the following topics:

    You can also find examples of script extension code in the <TestComplete>\Bin\Extensions\ScriptExtensions\AQAScriptExtensions.tcx file that is shipped with TestComplete. This file is a ZIP archive, so you can extract files from it using any archiver that supports ZIP files. For more information about files included in this package, see Pre-Installed Script Extensions.

  3. Write the description.xml file and create other helper files

    To let TestComplete know which actions and objects the script extension provides, you need to create a description file. This is an XML file that declares actions, objects and keyword test operations, specifies their attributes and provides general information about the extension (such as the vendor name, the version number and so on). In addition to the description file, you may also need to create helper files, such as icons for actions and the help file. For more information, see Structure of the Description File and Script Extension Files - Overview.

    You can find a sample description file, icons and the help file in the <TestComplete>\Bin\Extensions\ScriptExtensions\AQAScriptExtensions.tcx file that is installed along with TestComplete.

  4. Deploy the script extension

    Finally, you need to create a package (archive) that will include all of the extension files -- scripts, description file, icons, help files etc (see Deploying Script Extensions). Then you will be able to install this package into TestComplete or share it with other TestComplete users.

Best Practices

You can develop script extensions directly in TestComplete environment. For example, you can create a special project where you will create and debug script units, design forms, and so on. This will let you use all the TestComplete features in the development process. The following sections discuss recommendations and best practices for script extension development.

Writing Scripts

You can write the source code of script extensions directly in the TestComplete Code Editor. It has many features that make script writing and editing more convenient:

  • Use syntax highlighting and syntax checking to eliminate and fix syntax errors.

  • Use Code Completion to get information about routines provided by scripting languages, methods and properties of objects that can be used in script extensions. Use the Autocompletion mode to write code faster.

  • Use the Code parameters hint to get quick information on the number, names and descriptions of routine parameters while you are typing the code.

  • Use code templates will to insert predefined snippets in your code.

  • Use Code Explorer, bookmarks and other code navigation features to quickly jump to a particular place within the script.

  • And so on.

After writing the desired code, you can export TestComplete script units as ordinary script files. Two notes:

  • VBScript files must have the .vbs extension, JScript files -- the .js extension.

  • Script files must have the ANSI or UTF-8 encoding.

Debugging Scripts

While writing a script extension’s source code in TestComplete, you can debug it with the TestComplete debugger. This means that you can use breakpoints, stepping, watches, expression evaluation and others TestComplete debugging features to observe the code behavior while executing it. See Debugging Tests for more information.

However, keep in mind the following:

  • You can only debug script source code when executing it directly from the Code Editor. Debugging packaged extensions (loaded from .tcx files or extensions residing in Script Extension Folders) is not possible.

  • Scripts are treated as ordinary script units consisting of routines. The concept of actions and custom runtime objects does not apply to source scripts in this case. For example, to debug the get and set methods of a custom object’s property, you need to write a special test routine that directly calls these methods.

  • Extension-specific objects, such as Syntax, Recorder, Help, are unavailable in usual TestComplete scripts. When executing a script extension’s code from TestComplete, an error will occur upon a reference to one of these objects.

    One way to work around this problem is to comment out any use of Syntax, Recorder and other specific objects as well as dependent code while debugging the script in TestComplete.

    Alternatively, you can conditionally execute the problematic code. For example, you can define a global script constant or variable that holds a value indicating whether the code is executed from TestComplete or from a script extension. Depending on the variable value, you can skip execution of code that uses Syntax, Recorder or other non-standard objects. For example:

    JScript

    var RunFromTC = true;

    ...

    if (! RunFromTC)
    {
      // The code is executed outside of TestComplete.
      // You are free to use specific objects such as Syntax, Recorder etc.
      ...
    }

    VBScript

    Const RunFromTC = True

    ...

    If Not RunFromTC Then
      ' The code is executed outside of TestComplete.
      ' You are free to use specific objects such as Syntax, Recorder etc.
      ...
    End If

    In the release version of the script, you can set the debug flag to False in order to enable execution of specific code:

    JScript

    var RunFromTC = false;

    VBScript

    Const RunFromTC = False

For more information about debugging actions and objects provided by script extensions, see Debugging Script Extensions.

See Also

Script Extensions
Creating Script Extensions

Highlight search results