Name Property

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

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Description

Use the Method.Name property to specify the name of an ODT object method. Note that you cannot rename an object’s method if it was defined in a class. At the “object” level, you can rename only those methods that you added to the object using the AddMethod method after the object was created.

Declaration

MethodObj.Name

Read-Write Property String
MethodObj An expression, variable or parameter that specifies a reference to a Method object

Applies To

The property is applied to the following object:

Property Value

A string that holds the method name.

Remarks

When changing this property, keep in mind that the method name must be unique within the class or object, to which the method belongs. If the class or object already contains another method or property with the same name, an error will occur. Also, the method name is used to call the method in scripts. Therefore, the method name must match the naming rules of the project scripting languages (it must be a valid identifier). Otherwise, the scripts will not work.

Example

The following example obtains the Method object and posts the method’s name and the name of the method’s script routine to the test log.

JavaScript, JScript

function MethodSample()
{
  var NewClass, TestGroup, NewObj, MethodObj;
  // Deletes all the existing classes and variables
  ODT.Data.Clear();
  ODT.Classes.Clear();

  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Declares a new class method
  NewClass.AddMethod("NewClassMethod", "Unit1.Test1");

  // Adds a new group
  TestGroup = ODT.Data.AddGroup("TestGroup");
  // Creates a new variable that represents the object of the NewClass type
  NewObj = TestGroup.AddVarOfClassType("MyVar", "NewClass");
  // Obtains the object’s method by its index
  MethodObj = NewObj.Methods(0);

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log.Message("The " + MethodObj.Name + " method executes the " + MethodObj.ScriptProc + " script routine");

}

VBScript

Sub MethodSample

  ' Deletes all the existing classes and variables
  ODT.Data.Clear
  ODT.Classes.Clear

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Declares a new class method
  Call NewClass.AddMethod("NewClassMethod", "Unit1.Test1")

  ' Adds a new group
  Set TestGroup = ODT.Data.AddGroup("TestGroup")
  ' Creates a new variable that represents the object of the NewClass type
  Set NewObj = TestGroup.AddVarOfClassType("MyVar", "NewClass")
  ' Obtains the object’s method by its index
  Set MethodObj = NewObj.Methods(0)

  ' Posts the method’s name
  ' And the name of the script routine the method will execute to the test log
  Log.Message "The " & MethodObj.Name & " method executes the " & MethodObj.ScriptProc & " script routine"

End Sub

DelphiScript

procedure MethodSample();
var NewClass, TestGroup, NewObj, MethodObj;
begin
  // Deletes all the existing classes and variables
  ODT.Data.Clear;
  ODT.Classes.Clear;

  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Declares a new class method
  NewClass.AddMethod('NewClassMethod', 'Unit1.Test1');

  // Adds a new group
  TestGroup := ODT.Data.AddGroup('TestGroup');
  // Creates a new variable that represents the object of the NewClass type
  NewObj := TestGroup.AddVarOfClassType('MyVar', 'NewClass');
  // Obtains the object’s method by its index
  MethodObj := NewObj.Methods[0];

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log.Message('The ' + MethodObj.Name + ' method executes the ' + MethodObj.ScriptProc + ' script routine');

end;

C++Script, C#Script

function MethodSample()
{
  // Deletes all the existing classes and variables
  var NewClass, TestGroup, NewObj, MethodObj;
  ODT["Data"]["Clear"]();
  ODT["Classes"]["Clear"]();

  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Declares a new class method
  NewClass["AddMethod"]("NewClassMethod", "Unit1.Test1");

  // Adds a new group
  TestGroup = ODT["Data"]["AddGroup"]("TestGroup");
  // Creates a new variable that represents the object of the NewClass type
  NewObj = TestGroup["AddVarOfClassType"]("MyVar", "NewClass");
  // Obtains the object’s method by its index
  MethodObj = NewObj["Methods"](0);

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log["Message"]("The " + MethodObj["Name"] + " method executes the " + MethodObj["ScriptProc"] + " script routine");

}

See Also

Name Property
ScriptProc Property
Object Object
AddMethod Method

Highlight search results