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.