RefreshMappingInfo Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

TestComplete caches mapped objects to speed up test runs. The first time a test uses an alias, TestComplete remembers the found object and uses the cached object for all subsequent uses of the alias.

The RefreshMappingInfo method clears the cached object reference and searches for the object again. You may need to use this method:

  • if the object’s identification properties were changed,

  • if the object was recreated in the application,

  • if another object matches the mapping criteria,

  • before checking if the object exists.

Declaration

TestObj.RefreshMappingInfo()

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Result None

Applies To

All mapped processes, windows and controls.

View Mode

This method is not displayed in the Object Browser panel.

Result Value

None.

Remarks

The RefreshMappingInfo method does nothing when called from the Evaluate dialog during test debugging.

Example

Suppose you have the following Name Mapping structure for Notepad. In this example, Notepad’s window titled “Untitled - Notepad” has the wndUntitledNotepad alias.

Notepad objects in Name Mapping

The script below demonstrates how the RefreshMappingInfo method affects the check for object existence after the Notepad window’s caption changes. Before running the script, create the file C:\MyFile.txt, or change the path in the script.

JavaScript, JScript

function RefreshMappingInfo()
{
  // Run Notepad and open a text file
  WshShell.Run("notepad");
  Aliases.notepad.wndUntitledNotepad.MainMenu.Click("File|Open...");
  // After the first use, wndUntitledNotepad points to the Notepad window

  Aliases.notepad.dlgOpen.OpenFile("C:\\MyFile.txt");

  /*
  Now the Notepad caption has been changed from "Untitled - Notepad" to "MyFile.txt - Notepad".
  As a result, the Notepad window no longer matches the mapping criteria
  of the wndUntitledNotepad object (WndCaption = "Untitled - Notepad").
  But wndUntitledNotepad still points to the Notepad window because of caching.
  */
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists); // True

  // If we force a search for the wndUntitledNotepad object,
  // no window titled "Untitled - Notepad" will be found.
  Aliases.notepad.wndUntitledNotepad.RefreshMappingInfo();
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists); // False
}

Python

def RefreshMappingInfo():
  # Run Notepad and open a text file
  WshShell.Run("notepad")
  Aliases.notepad.wndUntitledNotepad.MainMenu.Click("File|Open...")
  # After the first use, wndUntitledNotepad points to the Notepad window

  Aliases.notepad.dlgOpen.OpenFile("C:\\MyFiles\\MyFile.txt")

  # Now the Notepad caption has been changed from "Untitled - Notepad" to "MyFile.txt - Notepad".
  # As a result, the Notepad window no longer matches the mapping criteria
  # of the wndUntitledNotepad object (WndCaption = "Untitled - Notepad").
  # But wndUntitledNotepad still points to the Notepad window because of caching.
  
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists) # True

  # If we force a search for the wndUntitledNotepad object,
  # no window titled "Untitled - Notepad" will be found.
  Aliases.notepad.wndUntitledNotepad.RefreshMappingInfo()
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists) # False

VBScript

Sub RefreshMappingInfo
  ' Run Notepad and open a text file
  WshShell.Run "notepad"
  Aliases.notepad.wndUntitledNotepad.MainMenu.Click "File|Open..."
  ' After the first use, wndUntitledNotepad points to the Notepad window

  Aliases.notepad.dlgOpen.OpenFile "C:\MyFile.txt"

  ' Now the Notepad caption has been changed from "Untitled - Notepad" to "MyFile.txt - Notepad".
  ' As a result, the Notepad window no longer matches the mapping criteria
  ' of the wndUntitledNotepad object (WndCaption = "Untitled - Notepad").
  ' But wndUntitledNotepad still points to the Notepad window because of caching.
  Log.Message Aliases.notepad.wndUntitledNotepad.Exists ' True

  ' If we force a search for the wndUntitledNotepad object,
  ' no window titled "Untitled - Notepad" will be found.
  Aliases.notepad.wndUntitledNotepad.RefreshMappingInfo
  Log.Message Aliases.notepad.wndUntitledNotepad.Exists ' False
End Sub

DelphiScript

procedure RefreshMappingInfo;
begin
  // Run Notepad and open a text file
  WshShell.Run('notepad');
  Aliases.notepad.wndUntitledNotepad.MainMenu.Click('File|Open...');
  // After the first use, wndUntitledNotepad points to the Notepad window

  Aliases.notepad.dlgOpen.OpenFile('C:\MyFile.txt');

  {
  Now the Notepad caption has been changed from 'Untitled - Notepad' to 'MyFile.txt - Notepad'.
  As a result, the Notepad window no longer matches the mapping criteria
  of the wndUntitledNotepad object (WndCaption = 'Untitled - Notepad').
  But wndUntitledNotepad still points to the Notepad window because of caching.
  }
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists); // True

  // If we force a search for the wndUntitledNotepad object,
  // no window titled 'Untitled - Notepad' will be found.
  Aliases.notepad.wndUntitledNotepad.RefreshMappingInfo;
  Log.Message(Aliases.notepad.wndUntitledNotepad.Exists); // False
end;

C++Script, C#Script

function RefreshMappingInfo()
{
  // Run Notepad and open a text file
  WshShell["Run"]("notepad");
  Aliases["notepad"]["wndUntitledNotepad"]["MainMenu"]["Click"]("File|Open...");
  // After the first use, wndUntitledNotepad points to the Notepad window

  Aliases["notepad"]["dlgOpen"]["OpenFile"]("C:\\MyFile.txt");

  /*
  Now the Notepad caption has been changed from "Untitled - Notepad" to "MyFile.txt - Notepad".
  As a result, the Notepad window no longer matches the mapping criteria
  of the wndUntitledNotepad object (WndCaption = "Untitled - Notepad").
  But wndUntitledNotepad still points to the Notepad window because of caching.
  */
  Log["Message"](Aliases["notepad"]["wndUntitledNotepad"]["Exists"]); // True

  // If we force a search for the wndUntitledNotepad object,
  // no window titled "Untitled - Notepad" will be found.
  Aliases["notepad"]["wndUntitledNotepad"]["RefreshMappingInfo"]();
  Log["Message"](Aliases["notepad"]["wndUntitledNotepad"]["Exists"]); // False
}

See Also

Exists Property
WaitAliasChild Method
WaitNamedChild Method
Name Mapping

Highlight search results