I have been doing some coded UI testing and running tests using Chrome (via the Selenium components). However, I noticed that when my test completed successfully, the Selenium (ChromeDriver) window stayed open and never terminated. Here’s a code snippet of my original code:

public void TestTimesheetIsDeployedChrome()
    BrowserWindow.CurrentBrowser = "chrome";

    var testUrl = ConfigurationManager.AppSettings["TimesheetUrl"];
    Assert.IsFalse(string.IsNullOrEmpty(testUrl), "Could not find testUrl in App Settings");
    var window = BrowserWindow.Launch(testUrl);

    // ...


Pretty straight forward. Except that the call to “window.Close();” closed the browser, but not the ChromeDriver command window – so the test never terminated.


So even though the test passes, I have to manually close the command window before the test run itself terminates.

After playing around a bit, I came up with this code to kill the command window (this works for Chrome – haven’t tested it for Firefox). Just replace “window.Close()” with this code:

// kill the process so we don't lock up - for some reason window.Close() locks

var procs = Process.GetProcesses().Where(p => p.ProcessName.ToLower().Contains("chromedriver"));
foreach (var p in procs)

That did it nicely for me (and made my Build-Deploy-Test workflows in my lab terminate correctly).

Happy (cross-browser) testing!