Forum Discussion

heidi_n's avatar
heidi_n
Regular Contributor
8 years ago

How to fix "The Internet Explorer browser was not closed after the loop iteration was finished"?

I am running TC 12.20 and have prepared web browsers (per: http://support.smartbear.com/testcomplete/docs/app-testing/web/general/preparing-browsers/internet-explorer.html) IE Version is 11.0.9600.18125 I do not have this problem with Chrome or FireFox.

 

My test goes to our website, logs in, clicks around, and closes the browser:

 

When I run my browser loop, it runs fine in Chrome and FireFox but gets "The Internet Explorer browser was not closed after the loop iteration was finished" in IE.

 

  • You should have, in your project, probably in the "Advanced" folder, a Script project object.  If you don't already have a script code unit there, add one by right clicking on the Script object and selecting "Add -> New Item".  Give it a meaningful file name.

     

    Then, take what I wrote and paste it into the unit as a new function.  Please note what I wrote is code written assuming JScript/JavaScript code syntax.  I don't know what code language your project is created in so you will have to adapt it accordingly.  The full function for my syntax would be

     

     function killIEProcess() {
        var ieProcess = Sys.WaitProcess('iexplore*');
        while (ieProcess.Exists) {
            ieProcess.Terminate();
            ieProcess = Sys.WaitProcess('iexplore*', 10000);
        }
    }

    Then, in your keyword test, after that Delay call for 5000 ms, add a the "Run Script Routine" operation.  You will be prompted to specify what code unit and available test to select.  Point to the function that you just created and that should work then for you.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Yeah, IE in modern versions of windows is funky that way.  You close the browser but the process stays memory resident...and not every time.

     

    In your case, you're using Alt-F4 to close the browser window followed by the 5 second delay to wait for the process to close.  However, this isn't always successful in closing the process, I'm guessing.

    What I've done to mitigate this is utilize the following code which executes after my command to close the browser.

     

        var ieProcess = Sys.WaitProcess('iexplore*');
        while (ieProcess.Exists) {
            ieProcess.Terminate();
            ieProcess = Sys.WaitProcess('iexplore*', 10000);
        }

    I'm not sure the easiest way to translate this into Keyword Test operations but what you could do is put this in a script function and just call it as a script routine.

    • heidi_n's avatar
      heidi_n
      Regular Contributor

      Yes, I've tried clicking on the actual X to close the IE browser and also Alt F4, but still no luck. 

       

      How would I do this part?

       

      "

      What I've done to mitigate this is utilize the following code which executes after my command to close the browser.

       

          var ieProcess = Sys.WaitProcess('iexplore*');
          while (ieProcess.Exists) {
              ieProcess.Terminate();
              ieProcess = Sys.WaitProcess('iexplore*', 10000);
          }

      I'm not sure the easiest way to translate this into Keyword Test operations but what you could do is put this in a script function and just call it as a script routine."

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You should have, in your project, probably in the "Advanced" folder, a Script project object.  If you don't already have a script code unit there, add one by right clicking on the Script object and selecting "Add -> New Item".  Give it a meaningful file name.

         

        Then, take what I wrote and paste it into the unit as a new function.  Please note what I wrote is code written assuming JScript/JavaScript code syntax.  I don't know what code language your project is created in so you will have to adapt it accordingly.  The full function for my syntax would be

         

         function killIEProcess() {
            var ieProcess = Sys.WaitProcess('iexplore*');
            while (ieProcess.Exists) {
                ieProcess.Terminate();
                ieProcess = Sys.WaitProcess('iexplore*', 10000);
            }
        }

        Then, in your keyword test, after that Delay call for 5000 ms, add a the "Run Script Routine" operation.  You will be prompted to specify what code unit and available test to select.  Point to the function that you just created and that should work then for you.