Forum Discussion

TestCoeUs1337's avatar
TestCoeUs1337
Occasional Contributor
19 days ago

How to speed up checking for non-existence of objects in TestComplete?

I'm running into an issue where asserting that an object does NOT exist is taking an unexpectedly long time (~10 seconds) in my TestComplete tests. I've tried using both:

if(!Aliases.restOftheCode.exists)

and

aqObject.CheckProperty("Exists", False)

But they both take around 10.25 seconds to execute.

I suspect this has to do with some global timeout setting, but I'm not sure exactly which one. Is there a way to override this timeout for just a single test case or step, rather than changing it globally for the entire project?

My goal is to make these "object does not exist" checks run much faster, ideally just taking a fraction of a second. Any tips on the optimal way to achieve this would be greatly appreciated!


8 Replies

  • eykxas's avatar
    eykxas
    Regular Contributor

    Hi! In my case, all wait methods (waitAlias, waitNNN etc...) doesn't have the behavior that I'm looking for.

    So instead, I set the autowait timeout directly in my script code, then revert it to the default value I'm using.

    for example :

    Options.Run.Timeout = 50; //50ms

    if(!myElement.Exists){
    doSomething();
    }

    Options.Run.Timeout = 4000; //4s

    So TestComplete look for the object only for 50ms (nearly instant).

  • PhilippeS's avatar
    PhilippeS
    New Contributor

    I got round this problem by using the "WaitAliasChild" method.

    (There is a optional waitTime as parameter)
    Check the documentation : https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/waitaliaschild-method.html

      if(Aliases.yourAliasesName.WaitAliasChild("yourElement").Exists){
        doSomething();       
      }

    Regards

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

      PhilippeS wrote:

      if(Aliases.yourAliasesName.WaitAliasChild("yourElement").Exists){
          doSomething();       
        }

      [Just as a side note]

      Yes, this might work, but the same condition as mentioned in my previous answer applies: Aliases.yourAliasesName object (and all objects within physical objects' hierarchy that precede "yourElement" aliased object) must exist. Otherwise TestComplete will start to search for them before been able to execute the .WaitAliasChild() call.

       

    • TestCoeUs1337's avatar
      TestCoeUs1337
      Occasional Contributor

      I don't need to wait for the property to exist after deletion; my goal is to assert that it doesn't exist anymore. How can I achieve this without adjusting the auto-wait timeout, but instead using a method tailored for this particular situation?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

        > if(!Aliases.restOftheCode.exists)

        > I don't need to wait for the property to exist after deletion

        Can you provide more details about your exact actions, how these actions change tested objects hierarchy and what is inside "restOftheCode" portion? And what is logged to the test log? Does it contain any error related to this portion of code?

        It is my wild guess that "restOftheCode" contains something like "obj1.obj2.obj3". It is also my guess that either obj3 or even obj2 and obj3 are removed from the application's object tree after deletion.

        If both my guesses are right, then your "Aliases.obj1.obj2.obj3.Exists" line of code effectively tells this to TestComplete: "Look for aliased obj1 object, then look for aliased obj2 child, then continue and look for aliased obj3 child object and for found obj3 object check the value of its .Exists property".

        Note, that the above assumes that obj1, obj2 and obj3 exist (possible caching might also matter: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html). If any of them does not exist, this will cause TestComplete to wait for the absent object to appear (with default 10sec timeout).

        What I would try to speed-up the check is to store the initial reference to the object to some variable and working with this variable than. E.g. (assuming obj3 is going to be deleted):

        var objToBeDeleted = Aliases.obj1.obj2.obj3;

        if (objToBeDeleted.Exists) {

          // perform deletion

          // optionally, wait enough for the object to be deleted or use WaitProperty() method to wait for .Exists property to become false

          if (!objToBeDeleted.Exists)

            // report successful deletion

          else

            // report that object was not deleted within given timeout

        }

        else

          // report object absence

         

        Hope this will help.