cancel
Showing results for 
Search instead for 
Did you mean: 

store all name mapping objects in a page and then use in scripts.

Regular Contributor

store all name mapping objects in a page and then use in scripts.

I want to store all webelement objects in a page and then want to use.

like

 

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

 

6 REPLIES 6
Highlighted
Community Leader

Re: store all name mapping objects in a page and then use in scripts.

Hi,


Save the reference to NameMapping obj in another file -> use it in your unit -> use codeCompletion.


This is the simplest solution to this.

Highlighted
Contributor

Re: store all name mapping objects in a page and then use in scripts.

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:

unit1:-

unit1.png

unit2:-

unit2.png

Regards,
Sathish Kumar K
Highlighted
Regular Contributor

Re: store all name mapping objects in a page and then use in scripts.

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

Highlighted
Community Hero

Re: store all name mapping objects in a page and then use in scripts.

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.  


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: store all name mapping objects in a page and then use in scripts.

Note, BTW, that you can use Aliases to shorten your object names however you want to.

 

The following object:

 

NameMapping.Sys.browser.myPage.panel0.panel0.panel1.panel0.table0.cell1

 

will, by default, create an Alias like

 

Aliases.browser.myPage.panel0.panel0.panel1.panel0.table0.cell1

 

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

 

Aliases.browser.myPage.table0.cell1

 

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: store all name mapping objects in a page and then use in scripts.

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.

 

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================