Import Functions Dialog

Applies to TestComplete 15.47, last modified on January 20, 2023

Use the Import Functions dialog to import functions to JavaScript projects. This should be done if you want to call routines that are declared in another unit.

The dialog is called by clicking Import Functions in the context menu of the Project Explorer panel. This menu item is available when

  • your project uses the JavaScript scripting language

  • a scripting unit is chosen in the Project Explorer

  • the project has more than one scripting unit.

Note: If you use another scripting language, see Add Unit References Dialog
Import Functions dialog

This dialog helps you import functions to the desired unit.

The left part of the dialog displays a list of available units. The right part lists the functions of the selected unit. The Function Name column contains the name of the function, the Export Name column contains the name you will use to call the function in the current unit. To call a function from an imported unit, you must use its Export Name.

Note: Currently, the dialog does not allow you to import variables and constants. You have to do this manually.

To import a function, you need to select the function and the unit that contains it.

After you click OK, TestComplete will add the needed statements to the appropriate units:

  • Adds export statements to the units in which the desired functions are declared:

    JavaScript

    // [Unit1]
    function foo()
    {
      ...
    }

    module.exports.foo = foo;

  • Declares a global variable with a reference to the exports object of the needed unit. This object contains all the exported items of the specified unit:

    JavaScript

    // [Unit2]
    var Unit1 = require("Unit1");

After you import the desired function, you can call it by using its export name prefixed with the source unit name:

JavaScript

// [Unit2]
var Unit1 = require("Unit1");

function bar()
{
  Unit1.foo();
}

See Also

Calling Routines and Variables Declared in Another Unit from GUI
Add Unit References Dialog

Highlight search results