Class Object

Applies to TestComplete 15.45, last modified on December 01, 2022

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

The Class objects provide a scripting interface to classes created via the ODT project item. Once you obtain a reference to a class, you can add or remove properties and methods, modify property values and perform other operations from scripts.

Members

Example

The code below posts the names and values of all the properties that belong to the MyClass class to the test log.

JavaScript, JScript

function PropertiesExample()
{
  // Specifies the class name
  var MyClass = ODT.Classes.MyClass;
  // Obtains the total number of the class's properties
  var PropNum = MyClass.PropertyCount;
  
  // Iterates through the properties
  for (var i = 0; i < PropNum; i++)
  {
    var PropName = MyClass.Properties(i).Name;
    var PropValue = MyClass.Properties(i).Value;
    // Posts a property's name and value to the test log
    Log.Message("The " + PropName + " property has the " + PropValue + " value.");
  }
}

VBScript

Sub PropertiesExample()

  ' Specifies the class name
  Set MyClass = ODT.Classes.MyClass
  ' Obtains the total number of the class's properties
  PropNum = MyClass.PropertyCount
  
  ' Iterates through the properties
  For i = 0 to (PropNum - 1)
    PropName = MyClass.Properties(i).Name
    PropValue = MyClass.Properties(i).Value
    ' Posts a property's name and value to the test log
    Log.Message("The " & PropName & " property has the " & PropValue & " value.")
  Next

End Sub

DelphiScript

function PropertiesExample;
var MyClass, PropNum, i, PropName, PropValue;
begin

  // Specifies the class name
  MyClass := ODT.Classes.MyClass;
  // Obtains the total number of the class's properties
  PropNum := MyClass.PropertyCount;
  
  // Iterates through the properties
  for i := 0 to (PropNum - 1) do
  begin
    PropName := MyClass.Properties[i].Name;
    PropValue := MyClass.Properties[i].Value;
    // Posts a property's name and value to the test log
    Log.Message('The ' + PropName + ' property has the ' + PropValue + ' value.');
  end;

end;

C++Script, C#Script

function PropertiesExample()
{
  // Specifies the class name
  var MyClass = ODT["Classes"]["MyClass"];
  // Obtains the total number of the class's properties
  var PropNum = MyClass["PropertyCount"];
  
  // Iterates through the properties
  for (var i = 0; i < PropNum; i++)
  {
    var PropName = MyClass["Properties"](i)["Name"];
    var PropValue = MyClass["Properties"](i)["Value"];
    // Posts a property's name and value to the test log
    Log["Message"]( "The " + PropName + " property has the " + PropValue + " value." );
  }
}

See Also

ODT Object
Classes Object
Object Object

Highlight search results