Additional ways of closing ChromeDriver using Selenium?

Executing automated test cases using Selenium invokes the ChromeDriver during execution. The test cases execute and compelte successfully. However, using DriverClose() and DriverQuit() does not close down the Chrome browsers or ChromeDriver.exe. Also finding the same when using the IEDriverServer.exe. Does anyone have any experience with alternatives to closing the ChromeDriver.exe?

Answers

  • In Java at least we do it this way: Setup: private void initializeChromeDriver() throws IOException { // Start Chrome in maximized window final ChromeOptions options = new ChromeOptions(); options.addArguments("--start-maximized", "--allow-running-insecure-content"); final DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options); org.openqa.selenium.remote.service.DriverService driverService = new ChromeDriverService.Builder().usingDriverExecutable(new File("./resources/driver/chromeDriver.exe")).usingAnyFreePort().build(); driverService.start(); webDriver = new ChromeDriver((ChromeDriverService)driverService, options); } Teardown: if(webDriver != null) { webDriver.quit(); } if(driverService != null) { driverService.stop(); }
  • We call Quit() method on the driver and it works fine. Make sure to put this in the method that has [TestCleanup] attribute in a class your tests extend from. Also make sure to put in a finally clause in case any exception occurs in the cleanup process (such as failing to sign off, failing to checkin password back into the pool, etc.).
  • Oh, right IE too. Here is the set up part for IE: driverService = new InternetExplorerDriverService.Builder().usingDriverExecutable(new File("./resources/driver/IEDriverServer.exe")).usingAnyFreePort().build(); driverService.start(); webDriver = new RemoteWebDriver(driverService.getUrl(), DesiredCapabilities.internetExplorer());