Forum Discussion

kcsahu777's avatar
kcsahu777
Contributor
13 years ago

Choosing between findchild and namemapping

Not sure when it is appropriate to use findchild and when namemapping?





What to use( findchild or namemapping) when we see the desired object is at very deep level i.e the hierarchy is very long ?

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    We have a phrase in US culture:



    "Six one way, half a dozen the other" meaning that there is very little difference between the two choices.



    To be honest, I don't think there really is much advantage one over the other.  Using FindChild requires you to write in code the specifics of the object you're searching for and have that object resolved at run time.  Using NameMapping allows you to predefine it ahead of time and, using Aliases, "telescope" the object down to something easily referenced.  Overhead different between the two, as far as I know, is negligible.



    Personally, I use FindChild when the parameters of the object may not be known ahead of time and are dependant upon other items in the application so the object is VERY dynamic.  NameMapping I use for objects that are much more static and won't change from test case to test case.  But there are ways of overcoming this in both methods so I can't necessarily say my way is THE right way to do things.



    Not much help, I know, but that's the best I can do.
  • Hi Krushna,


    If your goal is to shorten expressions for addressing objects, use the NameMapping feature. This approach lets you define the object in advance and allows you to change the object hierarchy by excluding intermediate objects from the syntax. I recommend that you read http://smartbear.com/support/viewarticle/12465/ in the online documentation.


    The FindChild method is typically used for the dynamical search for the object. Note that the FindChild speed depends on the Depth parameter. So, I recommend that you call FindChild belonging to the nearest known parent of the target object. For more information on using this method, please refer to http://smartbear.com/support/viewarticle/12729/.