Forum Discussion
The beauty about NameMapping is that, if a component changes, you simply edit the identification criteria in your NameMapping repository and all the objects then reference off that. There's no need to update any references to the object.
For example, let's say I have something like Aliases.MyApp.MyForm which has child objects of MyOKButton, MyCancelButton, MyTextEdit, and MyToolBar. Some developer decides to change MyForm to a different class or change the caption or something. My code has 40-11 zillion references to MyForm and various calls to the child objects.
With NameMapping, all I need to do is edit the repository information for MyForm. So long as the child objects are still child objects of MyForm, everything should then just translate. I don't need to make any code changes in any of my tests, I don't need to change any of my references to those child objects, everything just "works".
- ryan_perneel9 years agoContributor
Thanks for the update.
So in code (i have spent all of 30 minutes playing with namemapping) I have references to Alias.MainForm.Grid.Button1. so if Grid, gets changes to something else, say "class1", when I make the change in the namemapping file, then all references in code will autoupdate?
Also, are there perceived performance benefits to changing to namemapping? This is a project that has been around for going on 5 years, and would be alot of work to make the change (though i am tempted to propose a change to using javascript instead of jscript)
Thanks.
- tristaanogre9 years agoEsteemed Contributor
So long as all you do is change the mapping criteria and not the actual name of the alias, then yes, everything should work... it's not a matter of it updating the "code"... just that if your code is referencing Aliases.MainForm.Grid, that will point to whatever you have Grid mapped to, no matter how often you change it. Now, if you change the name from Aliases.MainForm.Grid to Aliases.MainForm.Grid2... then we have a bit of a problem. Keyword tests will automatically update, but script code will not.
I don't know about performance but, honestly, you'll be writing a LOT less code. instead of this:
function test1() { var myButton =Sys.Process('myApp').WinFormsObject('MainForm').WinFormsObject('Grid1').WinFormsObject('Button1'); myButton.Click(); }
All you need is
function test1 () { var myButton = Aliases.MainForm.Grid1.Button1; myButton.Click(); }
Much more readable, really. And you don't have to worry as much about when components change classes, hierarchy, etc... you can "fix" that but just playing with your NameMapping configuration and, if you do it right, you won't need to make any code changes.