1

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();
}
  • Are you sure TakeScreenshot doesn't throw an error on the VM? :) – FDM Dec 10 '20 at 8:43
  • No it just says cannot locate element ID and times out. After the timeout it goes to the next test in that group leaving the Chrome window open. – Sathira Padukka Dec 10 '20 at 13:11
  • There's your answer. If it fails at TakeScreenshot it won't execute the next line (dispose). – FDM Dec 10 '20 at 13:46
  • Commented out that piece of code but no luck, not sure why it is happening only on the VM. – Sathira Padukka Dec 15 '20 at 13:18
0

For me as it turned out it was a chrome driver version issue, after updating the chrome driver the issue was resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.