Accessing NameMapping objects in scripts
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Accessing NameMapping objects in scripts
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")
/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
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can simply do:
element = eval("Aliases.MCFConfigTool.MCTWindow.MainWindow.workspace.LogDurationValue") if element.Exists: do_something()
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.workspa
it is implicitly required that all referenced objects do exist. If any object along the 'Aliases.MCFConfigTool.MCTWindow.MainWindow.workspa
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.workspa
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('workspa
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
/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
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
