Creating Snapshots in Object Browser

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

TestComplete allows you to store snapshots of your tested application, a specific window or window element to a file for later use. A snapshot contains complete information about properties, fields and/or methods of an object that you selected and, optionally, of all of its child objects. You can use the resulting snapshots, for example, to explore your tested application’s object hierarchy and state when the application is not running.

Creating Snapshots

To create a snapshot from the Object Browser
  • Select the desired object in the object hierarchy displayed in the Object Browser.
  • Click the Save Object Snapshot button on the Save/Load Snapshots toolbar. If the toolbar is hidden, right-click somewhere within the TestComplete toolbar or menu area and select Save/Load Snapshots from the pop-up list.
  • This will open the Save Object Snapshot dialog. In the dialog specify the snapshot file name and object information the snapshot will contain.
  • Click OK.
To create a snapshot from tests

The following code saves information on the object that corresponds to the Notepad process to a file.

JavaScript, JScript

function SaveObjectToFile()
{

  // Specifies the object to save the information about
  var Obj = Sys.Process("notepad");
  
  // Specifies additional parameters for saving a snapshot
  
  var FileName = "C:\\MyFiles\\ObjectInfo.tcSnapshot"; // the path to the file the snapshot is saved to
  var SaveRecursive = true; // properties of the object's child objects are saved as well.
  var SaveAllProperties = true;
  
  // Saves the snapshot
  aqObject.SaveObjectSnapshotToFile(Obj, FileName, SaveRecursive, SaveAllProperties);

}

Python

def SaveObjectToFile():

  # Specifies the object to save the information about
  Obj = Sys.Process("notepad");
   
  # Specifies additional parameters for saving a snapshot
   
  FileName = "C:\\MyFiles\\ObjectInfo.tcSnapshot"; # the path to the file the snapshot is saved to
  SaveRecursive = True; # properties of the object's child objects are saved as well.
  SaveAllProperties = True;
   
  # Saves the snapshot
  aqObject.SaveObjectSnapshotToFile(Obj, FileName, SaveRecursive, SaveAllProperties);

VBScript

Sub SaveObjectToFile

  ' Specifies the object to save the information about
  Set Obj = Sys.Process("notepad")
  
  ' Specifies additional parameters for saving a snapshot
  
  FileName = "C:\MyFiles\ObjectInfo.tcSnapshot" ' Specifies the path to the file the snapshot is saved to
  SaveRecursive = true ' properties of the object's child objects are saved as well.
  SaveAllProperties = true
  
  ' Saves the snapshot
  Call aqObject.SaveObjectSnapshotToFile(Obj, FileName, SaveRecursive, SaveAllProperties)

End Sub

DelphiScript

function SaveObjectToFile;
var Obj, FileName, SaveRecursive, SaveAllProperties;
begin

  // Specifies the object to save the information about
  Obj := Sys.Process('notepad');
  
  // Specifies additional parameters for saving a snapshot
  
  FileName := 'C:\MyFiles\ObjectInfo.tcSnapshot'; // the path to the file the snapshot is saved to
  SaveRecursive := true; // properties of the object's child objects are saved as well.
  SaveAllProperties := true;
  
  // Saves the snapshot
  aqObject.SaveObjectSnapshotToFile(Obj, FileName, SaveRecursive, SaveAllProperties);

end;

C++Script, C#Script

function SaveObjectToFile()
{

  // Specifies the object to save the information about
  var Obj = Sys["Process"]("notepad");
  
  // Specifies additional parameters for saving a snapshot
  
  var FileName = "C:\\MyFiles\\ObjectInfo.tcSnapshot"; // the path to the file the snapshot is saved to
  var SaveRecursive = true; // properties of the object's child objects are saved as well.
  var SaveAllProperties = true;
  
  // Saves the snapshot
  aqObject["SaveObjectSnapshotToFile"]( Obj, FileName, SaveRecursive, SaveAllProperties);

}

Snapshots can be created only for objects that are displayed in the object hierarchy in the Object Browser. If the object is not displayed in the hierarchy (for example, a context menu, a submenu, a list item and so on that are not displayed in the Object Browser but returned by other objects’ properties and methods), the SaveObjectSnapshotToFile method fails to create a snapshot for that object and posts an error message to the log.

Loading Snapshots

  • Click the Load Object Snapshot button on the Save/Load Snapshots toolbar.
  • In the ensuing Load Object dialog, browse for the needed snapshot file.
  • The Object Browser will display the object hierarchy stored in the selected snapshot as well as object properties, fields, values and methods. The information you see is the same as if you dealt with “live” objects.

To close the currently opened snapshot and restore the default view, click the Show Default Object Tree button.

See Also

About Object Browser
SaveObjectSnapshotToFile Method

Highlight search results