Runner.CallMethod Method

Applies to TestComplete 15.47, last modified on January 20, 2023
This method is obsolete. See the Remarks section below.

Description

Use this method to call a script routine specified by its unit name and routine name.

Declaration

Runner.CallMethod(ComplexName, Param1, Param2, ..., ParamN)

ComplexName [in]    Required    String    
Param1 [in]    Optional    Variant    
Param2 [in]    Optional    Variant    
...
ParamN [in]    Optional    Variant    
Result Variant

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

ComplexName

Specifies the name of the script routine to be executed. The name should be specified in the unit_name.routine_name format. Both unit_name and routine_name are required.

Param1, Param2, ... ParamN

Specify parameters passed to the routine.

Result Value

If the specified routine is a function, CallMethod returns its value, otherwise, CallMethod returns a varEmpty Variant variable. You can check it using the aqObject.GetVarType method.

Remarks

  • The Runner.CallMethod method is obsolete and it is supported for backward compatibility only. You can call routines directly by their names without using the Runner.CallMethod method. If the desired routine is declared in another unit, add the USEUNIT statement to the current unit to include a reference to the unit that contains the routine declaration. For more information on this, see Calling Routines and Variables Declared in Another Unit from GUI.

  • If you use DelphiScript, to call a routine that returns a value, you can use the Evaluate function instead of the Runner.CallMethod method.

  • If you call a routine declared in a different unit, there is no need to specify unit_name in the USEUNIT (or uses) clauses of the current unit.

  • To call an object’s method by its name, use the aqObject.CallMethod method.

  • It is impossible to call a routine with the Runner.CallMethod method from an OnStopTest event handler (this event is generated when the test run is stopped, for instance, by calling the Runner.Stop or Runner.Halt method or by clicking the Stop button on the Test Engine toolbar). All routine calls performed by Runner.CallMethod from OnStopTest event handlers are ignored and the called functions are not executed.

For JScript, C++Script and C#Script users:

  • If a function called by Runner.CallMethod returns an array, the array’s elements cannot be iterated in a for…in loop. Due to some specifics of TestComplete subsystems, such a loop is not executed during the script execution and no iteration is performed. For example:

    JScript

    var Arr = Runner.CallMethod("Unit1.GetArray");
    // The loop will not be executed
    for(var i in Arr)
    {
      Log.Message(Arr[i]);
    }

    C++Script, C#Script

    var Arr = Runner["CallMethod"]("Unit1.GetArray");

    // The loop will not be executed
    for(var i in Arr)
    {
      Log["Message"](Arr[i]);
    }

    To avoid this problem, you can use one of the following workarounds:

    • Use the USEUNIT statement to include a reference to the unit containing the called function and directly call the function from the current unit (without using Runner.CallMethod).

    • Create an ActiveX array object (for instance, a Scripting.Dictionary object or some other) in the called function and return this object instead of a native array.

    • Use a for loop instead of for…in to iterate elements of the array returned by the function.

  • If you use the method to call routines declared in another unit, TestComplete may handle exceptions that occur while executing these routines incorrectly. For more information, see the Specifics of Usage Common for All Languages help topic.

See Also

Calling Routines and Variables Declared in Another Unit from GUI
CallObjectMethodAsync Method
CallMethod Method

Highlight search results