Forum Discussion

tcuser8's avatar
tcuser8
New Contributor
2 months ago

Checking until a window doesn't exist

Is there any way to check until a window doesn't exist. An inverse .WaitWindow()? Alternatively, is there a version of .Exists() that just returns bool? I've looked around forums and tried implementing this myself, but haven't found anything that works.

I'm using TC with Python. I set exceptions to not panic/exit early in TC, but .Exists() still does for some reason, even when caught.

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    You could use a while loop, This one is writen in JavaScript but should be about the same:

    I added a check that after a few checks it returns

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      WaitProperty method will pause execution until the specified object property achieves the specified value or until the specified timeout elapses. For example, waiting until the property value Visible becomes False.

      object.WaitProperty("Visible", "false", 30000);

       

      • MW_Didata's avatar
        MW_Didata
        Regular Contributor

        if the Object stops existing there is no visible property, does it still work?

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Frequent Contributor

    Yes you can use the property exists described in https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/exists-property.html?sbsearch=exists 

    Also as it would wait for the system default value when it no longer exist you need to change the value to lower setting, the following example is in JavaScript.

    function Test()
    {
      //Capture default timeout value
      var TimeoutValue;
      TimeoutValue = Options.Run.Timeout;
      
      //Set new default timeout value
      Options.Run.Timeout = 500;
      while(Aliases.browser.page.form.panel.Exists == true)
      {
        Delay(500);
      }
      Log.Message("Object no longer exists", "");

      //Restore default timeout value
      Options.Run.Timeout = TimeoutValue;
    }

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    I would avoid using the Exists method on the window object itself in this case.  The issue is you'll take a performance hit of several seconds when the window no longer exists.  That's because "Exists" waits for the full amount of time specified in your Auto-wait timeout set in the project properties. You could reset the Auto-wait time per Hassan_Ballan's suggestion.

    However, I would suggest using WaitWindow with a loop something like below.  As you can see, I included a counter/timer so that it doesn't get stuck in the loop if the window never closes.

    Set myWindow = xxx.WaitWindow(wndClass, wndCaption, 1, 500)
      x = 0
      While myWindow.Exists and x < 10
        Delay 500
        Set myWindow = xxx.WaitWindow(wndClass, wndCaption, 1, 500)
        x = x +1
      Wend
      
      If Not myWindow.Exists Then
        Log.CheckPoint "Yippie!  The window closed"
        Else
        Log.Message "Sad face.  After waiting five seconds the window is still open"
      End If