2. Preparing the Project

Applies to TestComplete 15.63, last modified on April 10, 2024

A script extension includes one or more JScript or VBScript units containing script code that implements the extension’s functionality. To create script units, you can use any tool or editor. However, it is convenient to use TestComplete to create them, because it offers a full-featured Code Editor with the Code Completion window that lets you quickly find the objects, methods, and properties to be used in scripts. So, in this tutorial we will create script units with TestComplete.

The code of script extensions can be written in JScript or VBScript, or both. In this tutorial, we will use JScript. Note that the selected language does not affect the range of TestComplete projects where the script extension can be used: extensions work equally well in any project, no matter which scripting language is used in TestComplete.

Create a Source Folder

Start with creating a folder where we will store the script extension files. Placing the script extension files into one folder will help you debug script code and pack the files into one .tcx module.

  1. Open Windows Explorer or any other file manager and create a new folder where you are going to keep the extension files. In this tutorial, we will use the C:\My Extension Files\LogAttrExtension folder.

  2. In the folder, create a new empty file and name it laCode.js. This file will contain the code of our custom keyword test operation. An extension may include several script units, but in our example one unit is enough.

    It is important that the script file has the .js extension, since TestComplete uses the extension to determine the script language of the unit. JScript units must have the .js extension, VBScript units – .vbs.
Create a Blank Project

Create a TestComplete project where we will keep and edit the source files of the script extension.

First, create a project suite:

  1. Select File | New | New Project Suite from the TestComplete main menu. The Create Project Suite dialog will open.

  2. In the dialog, specify the project suite name and location and click OK.

TestComplete will create an empty project suite in the specified location.

Now add a project to this suite:

  1. Select File | New | New Item from the TestComplete main menu. The Create Project dialog wil open.

  2. Specify the desired project name and path in the Project name and Location text boxes.

  3. Select JScript in the Language box.

  4. Clear the Generate the default content text box.

  5. Click OK.

TestComplete will create an empty project.

A blank project in the Project Explorer
Add a Script

Earlier, we have created the laCode.js file that will contain the source code of our custom keyword test operation. Import this file to the project so that we can write the code in the TestComplete Code Editor. But first, add the Scripts collection to our project:

  1. Right-click the project in the Project Explorer and select Add | New Item from the context menu. The Create Project Item dialog will open.

  2. In the dialog, select the Script item.

  3. Clear the Generate the default content check box.

  4. Click OK.

TestComplete will add an empty Scripts collection to the project. Now we can import the laCode.js file to this collection:

  1. Right-click the Script project item and choose Add | Existing Item from the context menu. The Open File dialog will appear.

  2. In the dialog, navigate to the C:\My Extension Files\LogAttrExtension folder.

  3. Select All Files (*.*) in the Files of type box.

  4. Select the laCode.js file and click Open.

TestComplete will add the laCode.js script unit to the project.

Make sure the laCode unit is clean. Do not use //USEUNIT statements in it, because units of script extensions cannot refer to each other.

Script files in script extensions must use the ANSI or UTF-8 character encoding. So, we need to specify the desired encoding for script units included in the project:

  1. Right-click the project node in the Project Explorer and select Edit | Properties from the context menu.

    TestComplete will display the project editor in the Workspace panel and will activate the Properties page of the editor.

  2. Select the General category in the tree on the left, and then specify the desired format -- ANSI or UTF-8 -- in the Units encoding box.

  3. Close the project editor.

Add a Form

Finally, create a form that will display the properties of our keyword test operation. To add a form to the project:

  1. Right-click the project in the Project Explorer and select Add | New Item from the context menu. The Create Project Item dialog will open.

  2. In the dialog, select User Forms and click OK. TestComplete will add the UserForms collection to the project.

  3. Right-click the UserForms collection in the Project Explorer and select Add | New Item from the context menu.

  4. In the dialog, specify laEditForm in the Name box and click OK.

TestComplete will add a new form to the project.

Test Project in the Project Explorer

Prev     Next

See Also

Creating Projects and Project Suites
Adding and Removing Project Items and Their Child Elements
User Forms

Highlight search results