Forum Discussion
Thanks Ryan,
As you can see from my code, my objects have a very long list of parents, and it would not be realistic to write code to traverse the entire tree, waiting for each parent to exist before looking at its children.
Surely there must be some builtin function to do this for me?
Thanks again for the quick response,
Cheers,
- James
"my objects have a very long list of parents"
Indeed. That is why I gave you the link to: Waiting For Web Pages
At the very least you may want to check that the page exists, and that the toolbar on which the button resides exists.
If you want a very simple solution then add a delay.
If you want a more dynamic approach I would suggest searching for the object within a loop with either .Find or .FindChild methods.
- jmcwhinney10 years agoContributor
Thanks Ryan,
I did read the page you suggested.
I tried using the below to ensure that my object parents exist.
if(GBFunc.WFO(Aliases.browser.BrowserWindow,"FrameTab.tabpage.ShellDocObjectView.browser.JavaPluginControlWindow.frame0.panel0.RootPane.null_layeredPane.StartupDialog.RootPane.null_layeredPane.null_contentPane.Panel.Panel.TextField",10000)){ Log.Checkpoint("Java Loaded"); } function WFO(Root,ObjectPathString,TimeOut){ //Set Timeout to default of 5000 if not provided if(TimeOut == 0){ TimeOut = 10000; } //Start Stop Watch to Calculate the time remaining var MyStopWatch = HISUtils.StopWatch; MyStopWatch.Start(); var TimeRemaining = TimeOut; //Iterate through object heirarchy and ensure each object exists before moving on... var TargetObject = Root; var AliasNameArray = ObjectPathString.split('.'); var ObjectFound = true; for (x = 0; x < AliasNameArray.length; x++) { TimeRemaining = TimeOut - MyStopWatch.Split(); if(TimeRemaining > 0){ TargetObject = TargetObject.WaitAliasChild(AliasNameArray[x],TimeRemaining); if(TargetObject.Exists == false){ ObjectFound = false; Log.Error("Unable to find UI object: '" + AliasNameArray[x] + "'"); x = AliasNameArray.length; } } else { ObjectFound = false; Log.Error("Timed out while looking for UI object: '" + AliasNameArray[x] + "'"); x = AliasNameArray.length; } } //Add Checkpoint if(ObjectFound){ Log.Checkpoint("UI Object found: '" + AliasNameArray[AliasNameArray.length-1] + "'"); } return ObjectFound; }
The above function works fine for a number of objects on my TestExecute PC, but then later on in the script it fails with the error "the execution timeout has expired" on the below line:
TargetObject = TargetObject.WaitAliasChild(AliasNameArray[x],TimeRemaining);
I feel that I have ruled out the possibility of a parent object not existing.
I am allowing a total of 10 seconds to traverse the object heriarchy, ensuring each parent exists before moving downwards, but somehow within 1 second of starting its heirarchical search, it fails on the above line.
I am completely confounded by this.
Any ideas?
Thanks again!
- James
- Ryan_Moran10 years agoValued Contributor
GBFunc = new Func(); function Func() { this.WFO = function(TargetObject,ObjectPathString,TimeOut){ var MyStopWatch = HISUtils.StopWatch; var AliasNameArray = ObjectPathString.split('.'); /* default TimeOut of 10000 */ TimeOut = TimeOut ? TimeOut : 10000 /* start MyStopWatch to calculate the time remaining */ MyStopWatch.Start(); /* Iterate through object heirarchy and ensure each object exists before moving on... */ for (var x = 0; x < AliasNameArray.length && TimeOut > 0; x++) { /* we want this to wait a fixed time for each child object */ TargetObject = TargetObject.WaitAliasChild(AliasNameArray[x],5000); if(!TargetObject.Exists){ Log.Error("Unable to find UI object: '" + AliasNameArray[x] + "'"); return false; } TimeOut-= MyStopWatch.Split(); } /* verify that TargetObject exists */ if(TargetObject.Exists){ Log.Checkpoint("UI Object found: '" + AliasNameArray[AliasNameArray.length-1] + "'"); return true; } } } function main() { var myMappedString = "pageCommunitySmartbearComT5Testc.panel"; if(GBFunc.WFO(Aliases.browser,myMappedString,10000)){ Log.Checkpoint("Java Loaded"); } }
Give this a try. Had to modify your code a bit for my own testing, sorry if I butchered it :).
Seems to work for me...See notes in code.
This could probably be accomplished with .FindAllChildren as well, but I wanted to use your existing code.
- jmcwhinney10 years agoContributor
Hi Ryan,
Thanks again for the reply.
But again,. I feel that I have ruled out the possibility of a parent object not existing.
The above function works great 9 times out of 10, until suddenly I get a (seemingly random) timeout.
If I have proven the parent object exists, how can i get a timeout only 1 second into a 10 second .WaitAliasChild ?
I think something else must be causing the timeout.
Is there some other timeout setting in TestComplete that could be causing this?
I have tried setting the "Timeout, min" for each test item to 99, but this hasnt helped either..
Thanks again,
- James
Related Content
- 4 years ago
Recent Discussions
- 10 hours ago
- 7 days ago
- 10 days ago