Forum Discussion

alinder's avatar
alinder
Contributor
15 years ago

Using MappedName inconvenient with multiple Aliases for the same object

There are times when it has been sensible in my application under test to create more than one alias to represent an object in my Name Mapping, such as a button that has been implemented as a single control can sensibly be abstracted as different test objects, for example Aliases.Foo.btnNext and Aliases.Foo.btnFinish . The Aliases feature supports this and has the conceptual strength to be used this way.



However, if I need to independently reference the object, such as identifying it with the Find method on MappedName or to note it for logging, I can't rely upon this abstraction as MappedName only makes the shortest alias accessible. If I understand it right, Aliases.Foo.btnFinish.MappedName returns "Aliases.Foo.btnNext".



In certain circumstances, using WaitAliasChild can suffice, but overall, I find the limitations of the MappedName property constrain how I can use the strength of the Name Mapping feature.




6 Replies




  • This was not intended to be posted to this sub-forum, and was intended for General TestComplete Discussions.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm not sure if using "MappedName" is actually the best property to search on using the Find function.  Can you explain more why you use "MappedName" to find objects?  That seems to kind of go backwards since you are mapping an object using certain properties than trying to find that object based upon some custom name.
  • The relevant cases are logging from TestComplete to an external system or driving TestComplete from an external system.  If we just clicked Aliases.Foo.btnFinish, we want to be able to write code that logs, 'Clicked "btnFinish"', not any other name it might happen to have.



    The difficulty is minimizing the amount of re-implementation, the amount of manual annotation, and the amount of data passed in and out of TestComplete. Solutions where we must pass in our out the full Alias name or note another field on all objects beyond the name are not viable for the current work criteria.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You might not need to pass in and out the full alias name.  As you noted, you can use "WaitAliasChild" to specify that you're waiting for a particular object.  OR, for that matter, simply use the find so that



    Aliases.Foo.FindChild("btnFinish")




    For that matter, it may be something that, instead of having to solve it within the automation code or the name mapping, it might need to be something that you map out in your data you're reading in.  



    Say, for example, you want to click the btnFinish object on the Foo form.  You would document your data so that it would know the name of the parent object and the name of the button.  That way, you can then use something like



    var MyObject = eval("Aliases." + FormName + "." + ObjectName)




    That then makes your tests even more data driven in that the data itself determine what will be clicked on what form in the application.  Your testing code then becomes less dependant upon contextual commands and more dependent upon the data.  So long as everything is mapped out, you can call any combination of form and component and use a single bit of code to click on it.  something like



    function MyClickButton(FormName, ButtonName)

    {

    var MyButton = eval("Aliases." + FormName + "." + ButtonName)

    MyButton.ClickButton()

    }




    This is rather rough and dirty but Boris Eligulashvili describes something similar in his article about improving GUI test automation 
  • Boris's article describes a system similar to what we are working with. I'm sorry to say I've tested out the solutions you've suggested and they aren't viable or working. FindChild doesn't work with only one arg, and using it on the Name property doesn't match the alias (multiple aliases possible per object, per the topic). Using eval doesn't work unless we pass in enough information to construct the entire Alias string.



    Our alias tree can be 4 to 6 nodes deep, but our conventions are such that for a given displayed state of the application, any object can be uniquely identified with its alias name and the name of one of its parents. Rearranging the Alias tree to be a consistent shallow depth is not an option as object names have been intentionally re-used, such as when a similar block of controls appears on different dialogs at different times.



    The main conclusion I have come to is don't use multiple Aliases for the same object anymore; use something common to both cases like btnNextFinish instead. We can make it work after a fashion, there are no expectations for a magic fix; the purpose of my posting was to communicate that we were trying to take the tool further than it can go via stable means.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Fair enough. :-)



    I think I would have to concur that using multiple aliases to map to the same object is a relatively unstable method of doing things.  I've found similar problems but not necessarily in the fashion you're trying to implement.  What I did, though, was use a single alias but use Conditional Mode in the NameMapping node itself to say that, for example, your button could be mapped to the node if the WndCaption is either "Next" or "Finish".  That way the button is always consistently found no matter the specifics of it.



    It think that is keeping in with the stability of the TestComplete application.  While it allows you to map the same thing to two different aliases, in my mind, an alias is a unique identifier for an object.  So, a Many Alias to One Object relationship doesn't work well.  However, a One Alias to many Objects using Conditional modes, wildcarded property values, and other similar techniques, works well and is stable.