Search code examples
seleniumselenium-webdrivermocha.jswindows-server-2012

Internet Explorer 11 does not close after Selenium Test


we have multiple Windows Server 2012 machines setup on Google Cloud where we are running Selenium tests. They are running with Mocha in NodeJS. Chrome and Firefox are starting, running, and closing as expected but IE 11 will not close. As a result, the selenium server stops responding and all the tests in IE begin to fail.

Here is the code for my before and after each hooks

// Launches browser, opens homepage, and closes the popup.
exports.beforeEach = function(capability) {
   driver = utils.driver.launch(capability);
   utils.driver.open(driver);
   utils.driver.closePopup(driver);
}

exports.afterEach = function() {
  driver.quit();
}

The capabilities I have set are the following

{
  browserName: browser,
  version: version,
  screenResolution: resolution,

  requireWindowFocus: true,
  unexpectedAlertBehaviour: "dismiss",
  ignoreProtectedModeSettings: false,
  ignoreZoomSetting: false,
  nativeEvents: true,
  handlesAlerts: true,
  javascriptEnabled: true,
  enableElementCacheCleanup: true,
  cssSelectorsEnabled: true,
  usePerProcessProxy: false,
  elementScrollBehavior: 0,
  enablePersistentHover: false,
  pageLoadStrategy: "normal",

  ie: {
    ensureCleanSession: true,
    forceCreateProcessApi: true,
    browserCommandLineSwitches: "-private"
  }
}

I've searched around for a few days and have tried different combinations of driver.close(), driver.quit(), IE settings, and capability settings, but they haven't worked and I really don't know what else to try. Since IE is not closing it's making it practically impossible to test in that browser. After about three tests the server slows down and we have to login and close all the windows manually.


Solution

  • If we are not able to close the IE by webdriver commands and at this moment it becomes stopping stone, so why cant we take help from language may be Java from my side to close it.

      try {
    Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe");
    } catch (IOException e) {
    e.printStackTrace();
    }
    

    Known that good to close browser by driver command but till it get works i hope we can try above. see this

    Thank You, Murali