Forum Discussion

DevaV's avatar
DevaV
Contributor
14 years ago

The window was destroyed during method execution.

Hi,



We get the error message 'Window is destroyed during method execution' while executing the scripts. Please find the code below.



This error is usually logged while trying to close the window (if it exists) in the finally block.





function test(){

  var dlgSchedule;

  try {

     dlgSchedule = Sys.Process("mmc").WaitWindow("MMCMainFrame", "Task Scheduler", -1,1000); //Opens the task scheduler window

     dlgSchedule.Close(); //Close the task scheduler window

     Delay(500);

     dlgSchedule.Refresh();

     Delay(500);

  }

  catch(exception){

    Log.Error(exception.message, exception.description);

  }

  finally{

    if(dlgSchedule !== undefined && dlgSchedule.Exists) //Close the task scheduler window if it exists

      dlgSchedule.Close()



 /* Also tried to close the dialog as below

   if(Sys.Process("mmc").WaitWindow("MMCMainFrame", "Task Scheduler", -1,1000).Exists)

     Sys.Process("mmc").WaitWindow("MMCMainFrame", "Task Scheduler", -1,1000).Close();    

 */

        

  }

}





Please let us know to resolve this scenario

3 Replies

  • Hello Deva,


    Is the Close method you call within the try block executed successfully when you get that error message? Does the Close method called within the try block post any messages to the test log?


    Maybe, instead of using the hardcoded delays within the try block, you would better set the timeout period for the Close method.

    For example, please see the code below:



    ...

    try

    {

      dlgSchedule = Sys.Process("mmc").WaitWindow("MMCMainFrame", "Task Scheduler", -1,1000);

      dlgSchedule.Close(60000); // Waits until the window is closed for one minute

    }

    ...



    You need to set the timeout period long enough for the window to be closed.


    Or you can try modifying your code in the following way:



    function Test()

    {

      var dlgSchedule;

      try

      {

        dlgSchedule = Sys.Process("mmc").WaitWindow("MMCMainFrame", "Task Scheduler", -1,1000);

        dlgSchedule.Close(10000);



        var i = 0;

        while (dlgSchedule.Exists)

        {

          Delay(3000);



          // Not to fall into an infinite loop if the tested window is frozen and cannot be closed

          i ++;

          if  (i  > 100)

            break;

        }



        // Checks whether the window still exists

        if (dlgSchedule.Exists)

          Log.Error("The window has not been closed");



      }



      catch(exception)

      {

        Log.Error(exception.message, exception.description);

      }



    }


    Please let us know whether this information helps you or whether you have any additional questions.

    Thank you.


  • Hi Julia,



    Thanks for your suggestion!



    It does not logs any error message during close method. The close method works fine in try block and mostly dialog gets closed inside the try block. In finally block we perform an additional check to close it in case  an exception occurs and close statement in try block is not executed.



    Hope this helps to understand the problem better!
  • Hello Deva,


    Thank you for your reply.


    It looks like the Close method in your test works correctly, and your problem is caused by the fact that it takes much time for the tested window to close.

    So, I guess, all possible workarounds come to setting a timeout long enough for the tested window to close. You can use the approaches I suggested in my previous post or any other approach that you find suitable. Also, if you have any unnecessary CPU-consuming processing running in the background during the test playback, you would better turn them off.

    Good luck.