Refresh Name Mapping Cache

Applies to TestComplete 15.70, last modified on December 17, 2024

TestComplete caches mapped objects to speed up testing. When a test uses a mapped object for the first time, TestComplete remembers the matched object. When the mapped object is used next time, TestComplete will use the cached object instead of searching for the object again.

Sometimes, caching may cause issues when identifying objects in dynamic applications. For example, a mapped object may point to an old object even though another object now matches the mapping criteria. If you face this issue, call the TestObj.RefreshMappingInfo method before the problematic test operation. The RefreshMappingInfo method clears the cached object reference and searches for the object again.

We recommend that you use the RefreshMappingInfo method in the following cases:

  • If you use variables to parameterize the object’s mapping criteria and the variable value is updated during the test run.

  • If your application changes during the test run (for example, part of a web page can be updated as a result of an Ajax request),

  • Before checking if an object exists.

Here is an example:

JavaScript, JScript

function Test()
{
  Browsers.Item(btIExplorer).Run("http://www.example.com");

  var pnlSpecialOffers = Aliases.browser.pageExample.pnlSpecialOffers;
  Log.Picture(pnlSpecialOffers);

  // Do something that updates the web page and the pnlSpecialOffers object
  // ...

  // Force a search for the pnlSpecialOffers object
  pnlSpecialOffers.RefreshMappingInfo();
  // You can also force a search for all child mapped objects of pageExample
  // Aliases.browser.pageExample.RefreshMappingInfo();

  if (pnlSpecialOffers.Exists)
    Log.Picture(pnlSpecialOffers);
}

Python

def Test():
   Browsers.Item(btIExplorer).Run("http://www.example.com")

   pnlSpecialOffers = Aliases.browser.pageExample.pnlSpecialOffers
   Log.Picture(pnlSpecialOffers)

   # Do something that updates the web page and the pnlSpecialOffers object
   # ...

   # Force a search for the pnlSpecialOffers object
   pnlSpecialOffers.RefreshMappingInfo()
   # You can also force a search for all child mapped objects of pageExample
   # Aliases.browser.pageExample.RefreshMappingInfo();

   if (pnlSpecialOffers.Exists):
     Log.Picture(pnlSpecialOffers)

VBScript

Sub Test
  Dim pnlSpecialOffers

  Browsers.Item(btIExplorer).Run("http://www.example.com")

  Set pnlSpecialOffers = Aliases.browser.pageExample.pnlSpecialOffers
  Log.Picture pnlSpecialOffers

  ' Do something that updates the web page and the pnlSpecialOffers object
  ' ...

  ' Force a search for the pnlSpecialOffers object
  pnlSpecialOffers.RefreshMappingInfo
  ' You can also force a search for all child mapped objects of pageExample
  ' Aliases.browser.pageExample.RefreshMappingInfo

  If pnlSpecialOffers.Exists Then
    Log.Picture pnlSpecialOffers
  End If
End Sub

DelphiScript

procedure Test;
var
  pnlSpecialOffers;
begin
  Browsers.Item(btIExplorer).Run('http://www.example.com');

  pnlSpecialOffers := Aliases.browser.pageExample.pnlSpecialOffers;
  Log.Picture(pnlSpecialOffers);

  // Do something that updates the web page and the pnlSpecialOffers object
  // ...

  // Force a search for the pnlSpecialOffers object
  pnlSpecialOffers.RefreshMappingInfo;
  // You can also force a search for all child mapped objects of pageExample
  // Aliases.browser.pageExample.RefreshMappingInfo();

  if pnlSpecialOffers.Exists then
    Log.Picture(pnlSpecialOffers);
end;

C++Script, C#Script

function Test()
{
  Browsers["Item"](btIExplorer)["Run"]("http://www.example.com");

  var pnlSpecialOffers = Aliases["browser"]["pageExample"]["pnlSpecialOffers"];
  Log["Picture"](pnlSpecialOffers);

  // Do something that updates the web page and the pnlSpecialOffers object
  // ...

  // Force a search for the pnlSpecialOffers object
  pnlSpecialOffers["RefreshMappingInfo"]();
  // You can also force a search for all child mapped objects of pageExample
  // Aliases["browser"]["pageExample"]["RefreshMappingInfo"]();

  if (pnlSpecialOffers["Exists"])
    Log["Picture"](pnlSpecialOffers);
}

See Also

How To
Name Mapping

Highlight search results