title: WebDriver Proper Shutdown
body: <p>I'm wondering for a while now what the best way was to do a proper clean-up after an expection has been thrown or the testcase has finished.</p>
  
  <p>As a reminder:
  An .exe process driver process according to the implementation, conhost.exe, the browser and Java application are launched.</p>
  
  <p>Using <code>driver.quit()</code>, we can kill the driver process, conhost and browser after finishing the testcase.</p>
  
  <pre><code>WebDriver driver = new SomethingDriver();
  
  // do stuff
  
  driver.quit(); // Proper cleaning
  </code></pre>
  
  <p>However, if an exception may be thrown, we need to do this:</p>
  
  <pre><code>    try{
          WebDriver driver = new SomethingDriver();
  
          // do stuff
      }
  catch(Exception e){
  e.printStackTrace();
  }        
      finally{
          driver.quit(); // Proper cleaning
      }
  </code></pre>
  
  <p>What about shutting down the driver process and conhost, but leaving the browser alive? Executing a shell script is bad since it kills <em>all</em> the processes with these names (therefore prevents concurrent usage) and it is Windows only (I think):</p>
  
  <pre><code>TASKKILL /F /IM chromedriver.exe
  TASKKILL /F /IM conhost.exe
  </code></pre>
  
  <p>Let's say we kill the Java process randomly (in Eclipse or task manager). How can we make sure that above mentioned cleaning takes place?</p>
  
  <p>Is there a code solution which covers all these issues nicely?</p>