Forum Discussion

OV's avatar
OV
Frequent Contributor
7 years ago

namemapping

Hi,

 

I'm having difficulties to understand how the NameMapping works.

When adding an object to the name mapping i can the see that it asks for the properties i want to add to this specific object, what's the reason for asking to add these properties if anyway during the scripting i can query any of these properties whether they've been added to the object namemapping or not?

Another thing, when adding a new object and drag it to the Aliases area below i can see that i can edit the name so it'll be easier for me to recognize the object name and what object it is related to, what's the point of doing dragging it to the aliases if it already exists and can be added in the namemapping? and i saw i can't drag it to for example higher place in the object hierarchy because it won't be recognized afterwards.

 

Another thing is sometimes when asking tc highlight the object it won't recognize it although it clearly on appears in the screen.

 

And the most critical problem i have is, the desktop app i'm testing has different screen, when creating the first project, it shows 3 test fields - Host, Instance and DB when creating the 2nd project and on the screen changes a bit and shows the existing projects on the left along with the same screen to create new project on the right hand side, both project creation has the same fields. when asking tc to add the fields to the namemapping it says object already exists but when running the script it can not recognize it. when highlight it it will find it but when running the script it wont :-/

 

I would really like the understand how the NameMapping/Aliases works because all the object recognition and the script run is based on tc's ability to recognize the object and their properties for me to later on in the future maintain and edit the script accordingly among all the thousands of code lines could be a big mess.

 

Thank you,

 

OV

 

 

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    NameMapping consists of two parts... first, the mapping which is the object recognition settings to determine, based upon properties and object hierarchy, the identification of objects.  So, for example, using the website http://secure.smartbearsoftware.com/samples/TestComplete10/WebOrders/, the username text field could be mapped as 

     

    NameMapping.Sys.browser.pageWebOrdersLogin.formAspnetform.panelLogin.textboxusername

    The properties for each level in that string tell test complete how to identify the specific object.  So, for the username text box, I have it mapped using the properties of ObjectType and ObjectIdentifier with values of Textbox and username respectively.  This allows TestComplete, without having to write lines of code to "find" components, to use the above string to identify the object.

     

    However, that string can get to be cumbersome for more complex websites.  There may be additional DIV panels and tables with cells with more div panels, etc.  So, mapping a single text box could generate a VERY long string.  This is where Aliases, the second part, comes in.  While I could have an Alias that looks like this:

     

    Aliases.browser.pageWebOrdersLogin.formAspnetform.panelLogin.textboxusername

    That's a pain in the butt to utilize.  There are two objects in the mapped hierarchy that, for practical purposes in the test, are unnecessary.  So, I "drag" the textboxusername in the Aliases to be a direct child of pageWebOrdersLogin and remove the unnecessary Aliases.  So, now my Alias is

     

    Aliases.browser.pageWebOrdersLogin.textboxusername

    This is much less cumbersome to work with.  When the automation code reads this alias, the NameMapping engine of TestComplete interprets it back to the NameMapping string and identification factors.  

     

    So, in short, NameMapping identifies the objects, Aliases translates them into more compact and human-readable strings for use in tests.

     

     

    So... that answers the first part of your post.  This is also all documented in https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html

     

    Now, as for your question about not highlighting the object... depending upon what object you are trying to highlight, there could be any number of reasons why it won't show on screen.  Primary would be that the NameMappping criteria used is insufficient to identify the object and, therefore, won't highlight it.  This could happen if there are dynamic factors involved in the identifying properties (cyciling ID numbers, etc).  Resolution: Edit the mapping criteria of the object to use more "static" identification factors or wildcard those portions that are seemingly random. 

     

    Other reasons for not highlighting would be if you're attempting to highlight an object that is not necessarily a visible or rendered object on screen but is simply a "container" for other objects.  Some applications do this.  

     

    As for your critical problem, this sounds, again, like a problem with object identification.  The factors you are using in your NameMapping for your objects are either not unique enough to distinguish properly between the two different project sets or there are randomizing factors in your identification criteria that are preventing identification.

     

    Another possible factor, not related to NameMapping, is a timing factor.  Automated test in TestComplete run faster, many times, than the application can keep up.  So, if it takes too long for the objects to render in your application, the test scripts may fail.

     

    As to your concern about editing scripts... that's why NameMapping is so powerful.  If you keep your Aliases as they are, you can modify the mapping as much as you want to, including changing hierarchy, adding additional panels in between, altering identification factors, etc.  In my above example, so long as my Alias remains the same, I don't ever need to change that value in my tests.  I can edit my NameMapping as much as I want for that Alias and the script code will still find the object.

     

    If you go to https://support.smartbear.com/testcomplete/videos/?utm_source=TestComplete&utm_medium=StarterPage, there are a number of short tutorial videos on NameMapping and object identification.  Specifically, I'd suggest "How to use extended find", "Editing properties for an object", "Editing Aliases", and "Using the Wildcard in the Name Map for values that change". Also, while it's for an older version of the application, the webinar at https://support.smartbear.com/screencasts/testcomplete/reliable-tests-for-dynamic-objects/ is also very useful and helpful.