Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
2 years ago

WaitProperty throwing error

Hello everyone,

 

I have a below code that returns the 'requiredobject' if it exists and if it does not exist on the desktop. I have some assertion units that need this object for further testing. I have used 'requiredobject.WaitProperty('Exists', true, waitLongTime); ' as sometimes the object cannot be found immediately and takes time to appear. Now the problems is that when the object doesn't exist in the first If check and the 'else if' is executed, the 'requiredobject.WaitProperty' logs that 'object doesn't exist' in the test log (I run my script on 'Continue on Error' so I only get results after complete test execution) before waiting for the 'Exists' property. I don't want this error in the logs. I can also use Delay method, but apparently, WaitProperty is most preferred in the test complete documentation?

 

if (requiredobject.Exists && requiredobject.VisibleOnScreen == true) {
return requiredobject;
} else if (!requiredobject.Exists) {
requiredobject.WaitProperty('Exists', true, waitLongTime);
if (requiredobject.Exists && requiredobject.VisibleOnScreen == true) {
return requiredobject;
} else {
return requiredobject;
}
}
}

 

Thanks,

1 Reply

  • Hi TestQA1.

     

    You are correct, you cannot call the WaitProperty method on the object if it doesn't exists.  So, doing your own delay and "wait" might be needed. Something like this could work, where you check if the object is null first.

     

    var requiredObject = ;// your mapped object or code for finding the object;
    // loop counter
    var sanity = 0;
    while (requiredObject == null || !requiredObject.Exists || !requiredobject.VisibleOnScreen)
    {
      Delay(1000);
      // make sure to have an exit condition so it doesn't get stuck in a infinite loop
      if (sanity > 60)
      {
         Log.Error("requiredObject not found"); // or throw an error if you have this code in a try/catch
         break;
      }
      // if you are searching for the object then you might want to place your search code here too, to search for it again


      sanity++;
    }

    return requiredObject