Forum Discussion

tristaanogre's avatar
tristaanogre
Esteemed Contributor
9 years ago

Pro-Tip: How Aliases Saved My Bacon

This is going to be a short one because this is a topic I've mentioned over and over in many conversations.  If you are using NameMapping properly and Aliases properly, if your AUT changes so that object identifications need to change, these two features can really make your life a lot easier.

 

Case in point: We recently elevated a version of one of our apps to our automated regression environment.  Unfortunately, the first pass through looked REALLY ugly with lots of test cases failing.  Almost all of them were "object not found" errors because, well, the developers changed some of the hierarchy of the app (additional DIV tags) and some of the identifying factors (ObjectLabel properties have different values now).

 

For many of these situations, we needed to do some radical surgery in our NameMapping to insert new "parent" objects, update properties with some conditional mapping, etc.  

 

But here's the thing: Not one line of code needed to change.  We didn't need to redo any of our tests or utility code or anything like that.  Because everything is referenced through Aliases, I could reorganize my NameMapping as much as I wanted to, as radically as I wanted to, and so long as the Aliases didn't change, I was safe.

 

And bonus... because we're using Aliases commonly throughout all our test cases, if a component needed reworked to get one test case to work, all test cases with failures on that component "magically" started working again.

 

As LinoTadros mentioned during the training at Connect, NameMapping can be a scary monster to deal with.  But it is also a feature of the tool that can REALLY be a good friend if it's used well.  Take the time to read up on all the topics concerning NameMapping in the help, watch the various videos available on line, and spend the time within your own projects to make this feature work for you.  

1 Reply

  • AlexKaras's avatar
    AlexKaras
    Community Hero

    And one more bonus from Aliases (which might be of special interest for those who like to have something like Page Object pattern for their tests). This was figured-out occasionally and confirmed by Support later.

     

    -- Aliases use a kind of 'late binding' that is evaluated when the referenced object is resolved in code.

     

    E.g.:

    This pseudo code will *not* work because of 'object not found' error (assuming Notepad is not running):

    var oEdit = Sys.Process("Notepad").FindChild("EditWnd");

     

    function main

    {

      TestedApps.Notepad.Run();

      oEdit.Keys("Test");

    }

     

    While this code will run because of late binding provided by Aliases:

    var oEdit = Aliases.Notepad.EditWnd;

     

    function main

    {

      TestedApps.Notepad.Run();

      oEdit.Keys("Test");

    }