0

In selenium, I have a whole bunch of checks to see if the browser contains something. If the browser does not contain what I want, I close the program.

Console.WriteLine("Error loading channel.", Color.Red);
driver.close(); // Is this needed?
driver.quite(); // Is this needed?
System.Environment.Exit(0);

Do I need to close the driver before I call exit? What is better coding practice?

Juansdk
  • 93
  • 5
  • @gunr2171 It does not. All im asking is if it is neccessary to close the drivers before calling Enironment.exit. – Juansdk Feb 22 '21 at 20:14
  • 1
    In the accepted answer is the sentence "In summary ensure that Quit() or Dispose() is called before exiting the program, and don't use the Close() method unless you're sure of what you're doing." Does that answer your question? – gunr2171 Feb 22 '21 at 20:15
  • @gunr2171 It did not answer my question, but this is great informtion! Thank you very much. I will just call quite. – Juansdk Feb 22 '21 at 20:18
  • 1
    I'm confused how that doesn't satisfy you. `System.Environment.Exit(0);` exits the program, and the advice says "call Quit or Dispose before you exit". You can imply from there that Close is _not_ needed, but Quit is. What is missing from this information? – gunr2171 Feb 22 '21 at 20:24
  • 1
    Yes, just noticed this. Thank you! Sorry for the confusion. – Juansdk Feb 22 '21 at 20:27

1 Answers1

1

Yes! Just like any resource allocations for your program that gets released once you're done with running it, Selenium driver (the process that coordinates the browser) needs to exit too.

Specially in testing environment, you must ensure you are not sharing processes/resources across multiple runs to avoid interference. Isolation is the key to have a reliable test run. (:

(Remember that the driver keeps the browser open - and keeps running to follow instructions from your tests, so if you don't quit it, not only the driver is running - there will also be an instance of a browser on the agent that's running the tests open/running)

Rikki
  • 3,338
  • 1
  • 22
  • 34