Calling Routines and Variables Declared in Another Unit from GUI

Applies to TestComplete 15.0, last modified on November 17, 2021

To add references to other units to the current script unit, you can use the TestComplete GUI or insert the USEUNIT directive to your script.

Adding Script References via the GUI and Calling Items

  • In JavaScript:

    • Right-click a script unit in the Project Explorer and select Import Functions from the context menu. The Import Functions dialog appears.

      Note: Currently, the dialog does not allow you to import variables and constants. You have to do this manually.
    • Select the units from which you want to import functions.

    • Select the functions of the unit you want to import:

      Import Functions dialog
  • In Python, VBScript, DelphiScript, JScript, C#Script and C++Script:

    • Right-click a script unit in the Project Explorer and select Import Functions from the context menu. The Add Unit References dialog appears.

    • Select Add the following unit references to the unit_name unit

    • Select the check box next to the units you want to add a reference to and click OK.

      Add Unit References dialog

After you perform the steps above, you can call routines and variables from the referenced unit as if they were declared in the current unit:

JavaScript

var MyExtUnit = require("MyExtUnit");
function main()
{
  MyExtUnit.myRoutine(Param1, Param2);
  MyExtUnit.myVariable;
  MyExtUnit.myConstant;
}

JScript

MyExtUnit.MyRoutine(Param1, Param2)
MyRoutine(Param1, Param2)

MyExtUnit.MyVariable
MyVariable

MyExtUnit.MyConstant
MyConstant

Python

MyExtUnit.MyRoutine(Param1, Param2)
MyExtUnit.MyVariable
MyExtUnit.MyConstant

# To call items from the external script implicitly, add reference from code

VBScript

Call MyExtUnit.MyRoutine(Param1, Param2)
Call MyRoutine(Param1, Param2)

MyExtUnit.MyVariable
MyVariable

MyExtUnit.MyConstant
MyConstant

DelphiScript

MyExtUnit.MyRoutine(Param1, Param2)
MyRoutine(Param1, Param2)

MyExtUnit.MyVariable
MyVariable

MyExtUnit.MyConstant
MyConstant

C++Script, C#Script

MyExtUnit.MyRoutine(Param1, Param2)
MyRoutine(Param1, Param2)

MyExtUnit.MyVariable
MyVariable

MyExtUnit.MyConstant
MyConstant

In some cases, you must specify the name of the referenced unit. For more information, see one of the topics below.

Calling Items From Another Unit

To learn how to call items from another unit and add script references from code written in different programming languages, see one of following topics:

See Also

Calling Routines Declared in Another Project
Supported Scripting Languages - Specifics of Usage

Highlight search results