Internet Explorer 11在Selenium测试后无法关闭

5
我们在Google Cloud上设置了多个Windows Server 2012机器,用于运行Selenium测试。它们在NodeJS中使用Mocha运行。Chrome和Firefox可以正常启动、运行和关闭,但是IE 11无法关闭。因此,Selenium服务器停止响应,并且所有在IE中的测试都会失败。
以下是我的before和after each钩子的代码。
// 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();
}

我所设置的功能如下:
{
  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"
  }
}

我已经搜索了几天,尝试了不同的 driver.close()、driver.quit()、IE 设置和能力设置的组合,但它们都没有起作用,我真的不知道还要尝试什么。因为 IE 没有关闭,所以几乎不可能在该浏览器中进行测试。经过大约三次测试后,服务器会变慢,我们不得不手动登录并关闭所有窗口。

2个回答

4

如@Sonny在评论中提到的,您可能需要终止“iexplorer.exe”任务。

我在预构建事件中都有:

    taskkill /f /fi "pid gt 0" /im IEDriverServer.exe
    taskkill /f /fi "pid gt 0" /im iexplore.exe

2

如果我们无法通过webdriver命令关闭IE浏览器,而它成为了一个绊脚石,那么为什么不能借助Java等语言来关闭它呢?

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

已知可以通过驱动程序命令关闭浏览器,但在其正常工作之前,我希望我们可以尝试上述方法。请参见此链接

谢谢, Murali


谢谢!这个有效了,只不过我们需要杀掉“iexplore.exe”,而不是IEDriverServer.exe。 - Sonny
浏览器正在关闭,但问题是,当我创建IE实例时,它会获取URL并立即关闭浏览器,即使我已经提供了隐式等待,因此我无法执行我的代码。你能帮我解决吗? - Hardik Vora
你在上面的回答中使用了iexplorer.exe吗?按照Sonny的说明使用它,这样它就会关闭浏览器而不是iedriverserver。 - murali selenium

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接