Forum Discussion

manish_bansal_1's avatar
manish_bansal_1
Occasional Contributor
9 years ago
Solved

Waiting for window till a given time

As we all know TC does not support a very important feature of timeout with exists function,  Smartbear telling us to use some WaitNNN  method, :catfrustrated: but again without exists i am not sure how to really use it ?

 

My situation is : after clicking on submit button, I have to wait maximum of 5 sec for error message, if no error message comes, in 5 sec it means, records are saved successfully.

 

Now i am doing waitNNN  (waitwindow) for 5 sec, after 5 sec, i will get an window proxy object, i have check if this window object is exists or not for writing results.

 

 

Please note : this .exists takes 30 sec (which is provided in the project properties), then what is the use of WaitNNN... am super confused, begging TC to add timeout to .exits function. or comeup with .ExistsEx(timeout).

 

I dont understand why they (SB) are pushing this stupid WaitNNN and not listing users to imporve TC by providing a simple solution to complexity, this is very annoying.

 

 

  • AlexKaras's avatar
    AlexKaras
    9 years ago

    Hi,

     

    The difference between, for example, .Window() and .WaitWindow() is that .Window() searches for the window for the AutoWait timeout and posts a message to the log if the window was not found. You should consider this function as a kind of implicit checkpoint - i.e. if the window must be present and you reference it via the call to .Window(), you will be notified if the window did not exist without any additional actions from your side.

    .WaitWindow() searches for the window for the specified timeout (for example, you may specify zero wait time in order not to wait for the window but just to check whether it exists or not) and does not post anything to the log. Then it is your responsibility to decide what to do if the window was found or not as it is only you who knows whether or not window is expected to exist or not. So no reason to post something into the log if the window was not found because it well might be that I want to check that some window does not exist. And in this case my code will be like this:

    If (obj.WaitWindow().Exists) Then

      Log.Error("Window that must be absent exists")

    End If

    ...

7 Replies

  • william_roe's avatar
    william_roe
    Super Contributor

    Have you tried the 'WaitProperty' operation. There is a timeout parameter and then the 'LastResult' can be used to know whether the property was found. I usually use the 'visibleOnScreen' property.. 

    • manish_bansal_1's avatar
      manish_bansal_1
      Occasional Contributor

      WaitProperty can be applied only on existing objects, otherwise testcomplete will throw exception. therefore waitproperty is useless.

      • Ryan_Moran's avatar
        Ryan_Moran
        Valued Contributor

        You need to use WaitNNN and Exists together.

         

        JScript example of waiting for notepad:

         

        function main() {
            wshell = new ActiveXObject('WScript.Shell');
            
            while (Sys.WaitProcess("Notepad", 0).Exists) {
              Sys.Process("notepad").terminate();
            }
            /*
              run notepad
            */
            wshell.run("notepad");
            
            /*
              wait 5 seconds for notepad to load 
            */
            if (Sys.WaitProcess("Notepad", 5000).Exists){
              Log.Message("Found notepad.");
              
              /*
                close notepad
              */
              Sys.Process("Notepad").terminate();
            }
            
            /*
              wait 5 seconds for notepad
              notepad should not be running
              no error should be logged
            */
            if (!Sys.WaitProcess("Notepad", 5000).Exists){
              Log.Message("Did not find notepad.");
            }
        }