Forum Discussion

bgran05's avatar
bgran05
Occasional Contributor
7 years ago

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!

  • 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)
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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)