Objects Object

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

The Objects object stores collections of properties and fields of applications' objects and allows you to:

  • Save application object properties to the Stores | Objects collection.
  • Compare object properties (especially those of the current object against those of a stored one).
  • Restore to an object the values of saved properties, all at once or selectively.

The Objects object contains properties that correspond to the objects added to the Stores | Objects collection. The property names coincide with the names of these objects. Each property returns a StoredObject object that corresponds to the appropriate object. For instance, the following code provides access to the CheckBox1 element:

JavaScript, JScript

var StoredObj1 = Objects.CheckBox1;

Python

StoredObj1 = Objects.CheckBox1

VBScript

Set StoredObj1 = Objects.CheckBox1

DelphiScript

var
  StoredObj1 : OleVariant;
begin
  StoredObj1 := Objects.CheckBox1;
end;

C++Script, C#Script

var StoredObj1 = Objects["CheckBox1"];

Objects lets you trace changes during a test. It also lets you compare an object state in the current test to the object state stored in a previous test and update values of stored properties with actual ones. This makes Objects a very useful tool for regression testing.

Note: The Objects object can only work with objects’ properties whose values are OLE-compatible. If you need to save, compare or restore an object’s non OLE-compatible property, you need to write the corresponding code manually.

Requirements

The Objects object is available only if your project contains the Stores | Objects collection.

Members

Example

The following code demonstrates how you can save properties of the desired object to an item of the Objects collection and compare the values of the stored properties with the actual values of the properties.

JavaScript, JScript

function Test()
{
  var w, PropertyNames, CollectionName;
  w = Sys.Desktop.ActiveWindow();

  // Prepares the property list
  PropertyNames = "Top Left Height Width";
  // Sets the name of the property collection
  CollectionName = "ActiveWindowProps";
  // Saves the values of the properties specified in PropertyNames.
  // Note that the Save method also has the fourth parameter
  // that lets you not to save certain properties.
  Objects.Save(w, CollectionName, PropertyNames);
  ...
  // Compares property values
  if (! Objects.Compare(w, CollectionName))
    Log.Message("Properties have been changed.");
}

Python

def Test():
   w = Sys.Desktop.ActiveWindow()
   # Prepares the property list
   PropertyNames = "Top Left Height Width"
   # Sets the name of the property collection
   CollectionName = "ActiveWindowProps"
   # Saves the values of the properties specified in PropertyNames.
   #Note that the Save method also has the fourth parameter
   # that lets you not to save certain properties.
   Objects.Save(w, CollectionName, PropertyNames)
   # ...
   # Compares property values
   if not Objects.Compare(w, CollectionName):
     Log.Message("Properties have been changed.")

VBScript

Sub Test
  Set w = Sys.Desktop.ActiveWindow

  ' Prepares the property list
  PropertyNames = "Top Left Height Width"
  ' Sets the name of a property collection
  CollectionName = "ActiveWindowProps"
  ' Saves the values of the properties specified in PropertyNames.
  ' Note that the Save method also has the fourth parameter
  ' that lets you not to save certain properties.
  Objects.Save w, CollectionName, PropertyNames
  ...
  ' Compares property values
  If Not Objects.Compare(w, CollectionName) Then
    Log.Message "Properties have been changed."
  End If
End Sub

DelphiScript

var
  w, PropertyNames, CollectionName : OleVariant;
begin
  w := Sys.Desktop.ActiveWindow();
  // Prepares the property list
  PropertyNames := 'Top Left Height Width';
  // Sets the name of the property collection
CollectionName := 'ActiveWindowProps';
  
  // Saves the values of the properties specified in PropertyNames.
  // Note that the Save method also has the fourth parameter
  // that lets you not to save certain properties.
Objects.Save(w, CollectionName, PropertyNames);
  ...
  // Compares property values
  if not Objects.Compare(w, CollectionName) then
    Log.Message('Properties have been changed.');
end;

C++Script, C#Script

function Test()
{
  var w, PropertyNames, CollectionName;
  
  w = Sys["Desktop"]["ActiveWindow"]();

  // Prepares the property list
  PropertyNames = "Top Left Height Width";
  // Sets the name of the property collection
  CollectionName = "ActiveWindowProps";
  // Saves the values of the properties specified in PropertyNames.
  // Note that the Save method also has the fourth parameter
  // that lets you not to save certain properties.
  Objects["Save"](w, CollectionName, PropertyNames);
  ...
  // Compares property values
  if (! Objects["Compare"](w, CollectionName) )
    Log["Message"]("Properties have been changed.");
}

See Also

Regions Object
Files Object
Stores
About Objects Collection

Highlight search results