Skip to main content
1 of 2

Browser is closed only if test passed on VM

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();
    }