I use driver.Dispose(); and using chromedriver. But the browser is closed only if the test passed. On the VM if a test failed, the browser is still open. If I run tests from Visual Studio on local machine, browser is closed if test passed or failed.
[AfterScenario]
public void DisposeWebDriver()
{
foreach (CommonTests ct in _tests) {
try {
Exception ex = this.ScenarioContext.TestError != null ? this.ScenarioContext.TestError : null;
ct.TakeScreenshot(this.ScenarioContext, ex);
ct.Dispose();
} catch (Exception exception) { Console.WriteLine(exception.Message); }
}
}
public void Dispose()
{
if (null != WebDriver) WebDriver.Dispose();
}