I want to store all webelement objects in a page and then want to use.
Set a = Aliases..........element path in object tree..............
Set b = Aliases..........element path in object tree..............
Set c = Aliases..........element path in object tree..............
Set d = Aliases..........element path in object tree..............
how can I do the same. I want to do this because it will help to call just object anywhere in scripts so there is not need to write full mappedpath in the code when a single element occur on different different journies.
Or is there any better way. Kindly share
Save the reference to NameMapping obj in another file -> use it in your unit -> use codeCompletion.
This is the simplest solution to this.
Hi @kaiiii ,
please save the object names in seperate Unit file and use the required objecs werevere required by refering to that unit.
please find the below exampe:
Hi @K_Sathish_Kumar ,
Thanks for reply.
I had done this before . it's not working.
we can call unit in one to another but what i am facing here
we are creating only objects not any function and not able to to call that object in another unit
If you haven't ready it already, I'd start with https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/...
However, please note that what you're trying to do isn't going to work well. At the moment of the Set command where you're assigning the Alias to the variable, that's when TestComplete does the evaluation of the object. Most likely, if the objects are not defined at the time of the variable assignment, you're going to get all sorts of errors later on. Object references for onscreen objects must be done in real-time closer to when you want to use the object and can't be referenced as such, at least, not as NameMapping.
To do what you want, you're going to have to create functions for every object that you want to reference that way. And that kind of defeats the purpose of NameMapping.
Note, BTW, that you can use Aliases to shorten your object names however you want to.
The following object:
will, by default, create an Alias like
However, those other panels aren't needed for the actual object you want. So, you can, in your NameMapping editor, highlight those panels, right click, and select "Exclude Items" and you'll end up with an alias like
And this is still the same object, found properly. Aliases are, as the name implies, "renaming" of what is mapped out in NameMapping. The engine reads the Alias and checks where it is found in the NameMapping tree and then uses that tree to find the object.
You can shorten object names as much as you want. TECHNICALLY speaking, I could shorten that Alias all the way down to Aliases.cell1 and it will still work so long as the NameMapping tree remains unchanged.
So... rather than trying to assign all the objects as you are doing, a better methodology would be to spend time formatting your Aliases to be more code-friendly.
> At the moment of the Set command where you're assigning the Alias to the variable, that's when TestComplete does the evaluation of the object.
I would like to clarify a bit.
Disclaimer: it is posible that for VBScript the behaviour is as Robert described. But description below is correct for JScript.
Aliases object uses late binding. Which means that it is possible to use statements like the below outside of any function in JScript:
var page = Aliases.browser.page;
JScript engine executes code that is outside of any function as a global one and before any function is called. So the above line will be executed on the very start of the test. (Even before the OnStartTest event IIRC.)
However, due to the late binding, the above line will just 'declare' the variable, but will not assign it the actual value, will not initialize the variable.
The reference to the object will be resolved at the moment of its first use. For example, when the code like this is executed:
var userName = page.NameField;
Note, that (as it is documented) at this moment the value of page will be cached and TestComplete will use the cached value. If, for example, the tested page is reloaded due to browser restart, the reference to the cached page object will be invalidated and its .Exists property will return False.
As a result, all subsequent calls like, for example, page.FindChild(...), will fail with the error that .FindChild() is not a property or method.
To solve this, test code must call page.RefreshNameMappingInfo() after page reload.
Considering the above, the technique to declare aliased objects as global variables can not be considered as a recommended one and should be used with a clear understanding of how Aliases functionality works in TestComplete.