Forum Discussion

denhenp's avatar
denhenp
New Contributor
9 years ago
Solved

Waiting for a window to close functionality. Jscript or keyword test.

Hi,

 

I'm fairly new to testcomplete and in need of some help creating a jscript/keyword test, either will work.

 

Test scenario is:

I click a createprofile  btn that opens up a new window.

I add some values to a textfield in the newly opened window and click a create profile btn.

The system then processes the data, and closes the createprofile window when done - This can take up to 45 seconds.

When done processing the data and the profile is created, it returns to the original window.

 

The functionality i need in testcomplete is following:

when the create profile btn is pressed in the new window, i need to wait untill the window is closed, for a maximum of 45 seconds.

If the create profile window does not exist(closed) i want to proceed with the test.

 

I've been trying to use:

while("create profile window".Exists)

{

Delay(500);

}

 

The problem is then, when the window closes, the while loop then throws "Object not fund exception" after waiting the default timeoutvalue.

 

 

Anyone has an idea on how to do this?

 

Best regards

Henrik

 

 

 

 

 

 

 

 

 

  • Hello denhenp,

     

    Congratulations on your solution :)

    I'd like to suggest the following improvent on your script:

     

    if(milisec >= 45000)
    {
      Log.Error("Waited 45 sec for the window to close.. Stopping test");
    /*Stops the current Test Item*/
    Runner.Stop(true); }

    and then... Setup TC not to stop on error, see http://support.smartbear.com/viewarticle/63574/

     

    Regards,

     

    Leandro de Araújo Souza

3 Replies

  • Henrik, this is for a similar situation in a Java SWT app:

     

     

             lMille = 0;
             do {
                w = Sys.Process("javaw").FindChild(["WndClass","Visible"],["SWT_Window0","True"],4);
                aqUtils.Delay(500);
                lMille += 500;
             } while (w.Exists && lMille < 45000);

    • denhenp's avatar
      denhenp
      New Contributor

      Hi,

       

      Thanks for the feedback.

       

      The suggestion works fine, when the application has a lot of data to process and it takes some time to close the window.

      The problem ocurs when there’s little data to process for the application and it closes the window immediately.

      Then a ”Object not found exception” is thrown.

       

      I had to implement it like this:

      function WaitWindowClose()
      {
      milisec = 0;
      //For some reason this only works for me, when I use a NameMappingItem in an if statement, combined with Exists.
      //Otherwise I get the object not found exception.
      if("NameMappingItem".Exists)
      {
      do
      {
      //You can't use the FindChild with 'NameMappingItem' - you have to use the 'Aliases'
      w.Sys.Process("ProcessName").FindChild("MappedName","<Insert mapped name using 'Aliases'>",1);
      milisec += 500;
      Delay(500);
      }while(w.Exists && milisec < 45000);
      if(milisec >= 45000)
      {
      Log.Error("Waited 45 sec for the window to close.. Stopping test");
      }
      }
      else
      {
      }
      
      Log.Message("The window has successfully closed.");
      }

       

      Thanks for pointing me towards a solution :)

      • leandroaraujoso's avatar
        leandroaraujoso
        Contributor

        Hello denhenp,

         

        Congratulations on your solution :)

        I'd like to suggest the following improvent on your script:

         

        if(milisec >= 45000)
        {
          Log.Error("Waited 45 sec for the window to close.. Stopping test");
        /*Stops the current Test Item*/
        Runner.Stop(true); }

        and then... Setup TC not to stop on error, see http://support.smartbear.com/viewarticle/63574/

         

        Regards,

         

        Leandro de Araújo Souza