Ask a Question

Accessing NameMapping objects in scripts

SOLVED
anumolu9999
Contributor

Accessing NameMapping objects in scripts

Hi, I had given the NameMapping alias name to a variable like aliasName="Aliases.page.button" Here actually I am passing text to the variable in above step. can i access the NameMapping object using above variable to do actions on the object. Thanks, Anumolu
8 REPLIES 8
AlexKaras
Community Hero

Hi Anumolu,

 

If I got the question right:

Use eval() or evaluate() function (depending on the language of your test project, e.g.: http://www.w3schools.com/asp/func_eval.asp) :

I.e.:

VBScript - Set aliasName = Eval("Aliases.page.button")

Other languages - aliasName = evaluate("Aliases.page.button")

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

Hi Alex, Thanks for the reply.... Actually, I want to find whether the screen control exists or not in a windows application screen. So I kept all the aliases names of objects in excel and want to read the aliase name, and want to find whether the object exists or not in the screen. This is the hierarchy of the control in the namemapping: Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.LogDurationValue I passed this as text to a variable as below aliasName="Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.LogDurationValue" Can i make the aliasName as an object variable from string variable to perform actions on the object(Exists, click, settext) as Below: if(aliasName.Exists==true) Is there any way to do like this Thanks, Anumolu.

You can simply do:

 

element = eval("Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.LogDurationValue")

if element.Exists:
    do_something()

 

I am doing like this way. element=getaliasNameFromExcel(); if element.exists then element.click ---------------------------------------------- getaliasNameFromExcel(index) { return aliasName; } Please find the excel attached

I am not able to attach anything from my network. In excel the data is like this. (0,0) - 1000 (0,1) - Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.LogDurationValue (1,0) - 1001 (1,1) - Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.MaintainerOnSiteTimer These are the two rows and two columns in the excel. I wanna send index to a function(getaliasNameFromExcel) and get aliasname as a string in return. Now, is it possible to convert the string to object and perform actions on it?


@venkateswararao wrote:
Now, is it possible to convert the string to object and perform actions on it?

Definitely yes. Check @AlexKaras and mine replies above.

As it has already been said, eval/evaluate functions must be used to get the object from the string that corresponds to project's full name.

This has some specific:

when TestComplete executes line like this:

obj = Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.MaintainerOnSiteTimer

it is implicitly required that all referenced objects do exist. If any object along the 'Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.MaintainerOnSiteTimer' objects' path does not exist (say, workspace or MaintainerOnSiteTimer), an error will be posted to the log.

This is correct and expected behaviour as it implicitely verifies that all explicitly mentioned objects exist.

If it is expected that some object may or may not exist, than WaitChild/WaitAliasChild function must be used. These functions do not fail and do not post an error to the test log if the sought for object does not exist but instead return an empty object with the .Exists property set to False.

So, in order to check that all objects along your Aliases path exist, you must evaluate them one by one.

Something like that (pseudocode):

// Check if 'Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.MaintainerOnSiteTimer' exists:

obj = Aliases.WaitAliasChild(evaluate('MCFConfigTool'))

if (not obj.Exists)

  // Object does not exist

 

obj = obj.WaitAliasChild(evaluate('MCTWindow'))

if (not obj.Exists)

  // Object does not exist

 

obj = obj.WaitAliasChild(evaluate('MainWindow'))

if (not obj.Exists)

  // Object does not exist

 

obj = obj.WaitAliasChild(evaluate('workspace'))

if (not obj.Exists)

  // Object does not exist

 

obj = obj.WaitAliasChild(evaluate('MaintainerOnSiteTimer'))

if (not obj.Exists)

  // Object does not exist

 

// use MaintainerOnSiteTimer object that is referenced by the obj variable

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

Thank you Alex and Baxatob........Its working
cancel
Showing results for 
Search instead for 
Did you mean: