cancel
Showing results for 
Search instead for 
Did you mean: 

How to use WaitChild or WaitAliasChild when object name contains "Alias" already?

SOLVED
Occasional Contributor

How to use WaitChild or WaitAliasChild when object name contains "Alias" already?

I am using jscript for TestComplete scripts and am struggling to figure out how to write a custom wait condition that will take an object as input and wait a specific number of seconds.

I have objects set up like this:

 

var button = Aliases.Product.Tab1.button

 

And in my scripts I use it like

 

button.click();

 

I want a new wait for exists function so I can write custom logging. I have tried 

function WaitForConfigObjectExist(objectName, maxWaitTime)
{
  var stopWatch = HISUtils.StopWatch; 
  stopWatch.Start();

  while(!Sys.WaitChild(objectName, 500).Exists)
  { 
    Delay(500);
    var currentTime = stopWatch.Split();
    if(currentTime > maxWaitTime)
    {
      Log.Warning(objectName + " not found after  " + maxWaitTime + " seconds.");
      return false;
    }
}

 

 But I think this fails because System does not have a child called "Aliases.Product.Tab1.button". When I replace the while line with 

while(!Aliases.WaitAliasChild(objectName, 500).Exists)

it complains that Aliases does not have a child with the name: Aliases.Product.Tab1.button

 

Short of changing the button to be "Product.Tab1.button" and using WaitAliasChild on that, is there any other option to check for existence of a generic object? 

 

Thanks for any help!

1 REPLY
Highlighted
Community Hero

Re: How to use WaitChild or WaitAliasChild when object name contains "Alias" already?

Instead of passing in the object itself, you should pass in two parameters... the parent object of the object you want to wait for, and the string name of the child object.

 

So, here's your code:

 

function WaitForConfigObjectExist(parentObject, objectName, maxWaitTime)
{
  var stopWatch = HISUtils.StopWatch; 
  stopWatch.Start();

  while(!parentObject.WaitChild(objectName, 500).Exists)
  { 
    Delay(500);
    var currentTime = stopWatch.Split();
    if(currentTime > maxWaitTime)
    {
      Log.Warning(objectName + " not found after  " + maxWaitTime + " seconds.");
      return false;
    }
}

And you'd call it like this

 

WaitForConfigObjectExists(Aliases.Parent.Tab1, 'button', 10000)

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.


I’ll be talking about “Hidden Treasures – TestComplete Script Extensions” at #SBConnect in October! Who’s joining me? Click here for tickets
Extensions available
Share Your Stories
Read Latest News
Top Kudoed Authors