2

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();
}
4
  • Are you sure TakeScreenshot doesn't throw an error on the VM? :)
    – FDM
    Commented Dec 10, 2020 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. Commented Dec 10, 2020 at 13:11
  • There's your answer. If it fails at TakeScreenshot it won't execute the next line (dispose).
    – FDM
    Commented Dec 10, 2020 at 13:46
  • Commented out that piece of code but no luck, not sure why it is happening only on the VM. Commented Dec 15, 2020 at 13:18

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

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