Delete Mapped Objects From Tests

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

In tests, you can delete an object from the Name Mapping repository using the RemoveNamedChild method of its parent mapped object. This method deletes the specified object from both Mapped Objects and Aliases, and also deletes all of its child objects. In keyword tests, you can call the method using the Call Object Method or Run Code Snippet operation.

JavaScript, JScript

NameMapping.Sys.some.parent.object.RemoveNamedChild(index);

Python

NameMapping.Sys.some.parent.object.RemoveNamedChild(index)

VBScript

Call NameMapping.Sys.some.parent.object.RemoveNamedChild(index)

DelphiScript

NameMapping.Sys.some.parent.object.RemoveNamedChild(index);

C++Script, C#Script

NameMapping["Sys"]["some"]["parent"]["object"]["RemoveNamedChild"](index);

Notes:

  • To specify the parent object, use its name in the Mapped Objects tree (NameMapping.Sys.object.name or NameMapping.Mobile.object.name) rather than the alias (Aliases.object.name).

  • The object to delete is specified by its zero-based index among sibling objects.

  • You cannot delete the Sys and Mobile objects from the Mapped Objects tree.

Examples
Delete a specific object (with child objects) from the Name Mapping repository

This example deletes Notepad’s window from the name map. Before you run this example, add Notepad and Notepad’s window to the name map (see Mapping Objects Manually).

JavaScript, JScript

function Test()
{
  NameMapping.Sys.notepad.RemoveNamedChild(0);
}

Python

def Test():
  NameMapping.Sys.Notepad.RemoveNamedChild(0)

VBScript

Sub Test
  NameMapping.Sys.notepad.RemoveNamedChild 0
End Sub

DelphiScript

procedure Test;
begin
  NameMapping.Sys.notepad.RemoveNamedChild(0);
end;

C++Script, C#Script

function Test()
{
  NameMapping["Sys"]["notepad"]["RemoveNamedChild"](0);
}

Delete all objects from the Name Mapping repository

This example deletes all objects from the name map except for Sys and Mobile. To call this script from a keyword test, you can use the Run Script Routine operation.

JavaScript, JScript

function Main()
{
  if (aqObject.IsSupported(NameMapping, "Sys"))
    UnmapChildObjects(NameMapping.Sys);

  if (aqObject.IsSupported(NameMapping, "Mobile"))
    UnmapChildObjects(NameMapping.Mobile);
}

function UnmapChildObjects(Object)
{
  while (Object.NamedChildCount > 0)
    Object.RemoveNamedChild(0);
}

Python

def Main():
  if (aqObject.IsSupported(NameMapping, "Sys")):
    UnmapChildObjects(NameMapping.Sys)
  
  if (aqObject.IsSupported(NameMapping, "Mobile")):
    UnmapChildObjects(NameMapping.Mobile)

def UnmapChildObjects(Object):
  while (int(Object.NamedChildCount) > 0):
    Object.RemoveNamedChild(0)

VBScript

Sub Main
  If aqObject.IsSupported(NameMapping, "Sys") Then
    UnmapChildObjects NameMapping.Sys
  End If

  If aqObject.IsSupported(NameMapping, "Mobile") Then
    UnmapChildObjects NameMapping.Mobile
  End If
End Sub

Sub UnmapChildObjects(Object)
  While Object.NamedChildCount > 0
    Object.RemoveNamedChild 0
  Wend
End Sub

DelphiScript

procedure UnmapChildObjects(Obj);
begin;
  while Obj.NamedChildCount > 0 do
    Obj.RemoveNamedChild(0);
end;

procedure Main;
begin
  if aqObject.IsSupported(NameMapping, 'Sys') then
    UnmapChildObjects(NameMapping.Sys);

  if aqObject.IsSupported(NameMapping, 'Mobile') then
    UnmapChildObjects(NameMapping.Mobile);
end;

C++Script, C#Script

function Main()
{
  if (aqObject["IsSupported"](NameMapping, "Sys"))
    UnmapChildObjects(NameMapping["Sys"]);

  if (aqObject["IsSupported"](NameMapping, "Mobile"))
    UnmapChildObjects(NameMapping["Mobile"]);
}

function UnmapChildObjects(Object)
{
  while (Object["NamedChildCount"] > 0)
    Object["RemoveNamedChild"](0);
}

See Also

Delete Objects From the Name Mapping Repository
How To
Delete Mapped Objects Manually
Mapping Objects From Tests

Highlight search results