Forum Discussion

tristaanogre's avatar
tristaanogre
Esteemed Contributor
8 years ago

Pro-Tip: Cached Aliases

.As myself and other experts here have shared, one of the more powerful features of TestComplete is the NameMapping feature and it's ability to detect and organize objects in your application under test.  Rather than having to write a lot of code to find components, activate them, store them in variables, etc., NameMapping takes care of that for you.

 

However, we ran into something recently that, while not a bug, may cause some difficulties for some users with their application testing.

 

Situation:

I have a test case I'm working on where different users with different levels of privilege and functionality login and logout during the course of the test.  Each user has a different general configuration that is presented to them and, for that matter, some if it is customizable for the user.  In one such case, there is a side bar with a set of tabs to take the user to different pages for different activities.  That list of tabs is one such customizable list.  What happens is that, when a user logs in, the actual activities are assigned to the tab at log in for them to click on and work with.  So, say Tab 1 for user 1 is Activity 1 but the same tab for user 2 is Activity 2.  The actual handle for the object does not change from login to login, just the activity is assigned dynamically.  The end result is that, occasionally, when a user logs in and I tell the test case to have that user click on the activity that, for them, is mapped to Tab 1, they will occasionally end up clicking the wrong tab.  The reason being is that TestComplete caches information for Aliases in memory so the activity for the first user may have been on tab 3... so user 2 ends up clicking on tab 3 which takes them to the wrong activity which ends up failing the test.  My NameMapping is correct, the code is correct, everything is correct, even the application is correct... but the test fails.

 

Reason why:

According to TestComplete help:

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.

 

So, the caching of the Alias ends up mixing up which tabs to click on which messes up my testing.  I would love to be able to have TestComplete turn off that caching, but the downside to that is a loss of performance.

 

Solution:

 

The same help topic that gives that above quote is the topic with the solution.  Specifically, there is a method on every mapped object called RefreshMappingInfo.  See https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html.

 

What I ended up doing is that, after every login, I would have the test case call that method on the object that contains those tabs.  This refreshed the name mapping information for the object as well as any child objects that it had.  The result is that, for each user, their list of tabs and their ordering is corrected.  I didn't have to change any mapping, just clearing the cache for these specific instances to make sure that the objects in the application were properly recognized.

3 Replies

  • Yup. Been caught by that before. Use RefreshMappingInfo quite frequently now!

     

    The way name maps works still feels a little klunky in places (mainly around sharing and lack of ability to do things dynamically with name maps during a run) compared to the object repository in QTPro/UFT. But I do like the Alias feature allowing you to create a much more human readable "version" of the application compared to the full object map at system level.

     

    IF .... it's used properly.

     

    The number of people I see using an Alias which is a straight copy of the Object Map object still astounds me.

     

    Simply bolting the word "Alias" onto an otherwise still long and horrible to read collection of objects doesn't achieve anything really ....

    • Manfred_F's avatar
      Manfred_F
      Regular Contributor

      .refreshMappingInfo, Ok.

       

      one more Approach:

      use Alias to identify the (stable) root of a hierarchy and let Your Framework do the dynamical part of addressing..

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        True, that should work as well.  The container for the menu tabs would be the static root and then use a FindChild or something to find the particular tab.  One reason why we opted for NameMapping the specific tabs is that we're trying to optimize our code by reducing the amount of additional scripting code and using more internally compiled functions.  It's a trade off.