Mark Letterman
Mark Letterman

Reputation: 31

Selenium webdriver closing without session

I have test that executes for 6 hours. After 2 hours, my driver slows down due to nature of Chrome browser. Solution is to close browser and restart it. I found out that doing driver.quit() helps in performance due to some internal memory that is being used which causes test to become slow. I am wondering is there option to use driver.quit() without closing drivers because i need cookies that were generated in that session as well as not killing Python script that is being ran at that moment.

Upvotes: 0

Views: 2250

Answers (1)

timbre timbre
timbre timbre

Reputation: 13960

The purpose of driver.quit() is to close all browser windows and terminate WebDriver session. So no, you cannot use driver.quit() without closing drivers - that's what it does.

In my opinion, you should look at why at all you have this issue:

  • Is there really a reason to run 6 hours of testing within the same session? Of course there could be special circumstances, but good practice is to cut entire test collection into independent sets, where each set can run on its own, on "clean" environment (i.e. new browser session). Not only this will prevent the problem you are facing, but also improves reliability of the tests (i.e. domino effect when one tests messes all future test executions), ability to debug (imagine you have a problem with a test that runs on hour #3, and the problem is not reproducible when you run it alone, or you can't run it alone), and flexibility of the executions.

  • Why does the browser need to be restarted after 2 hours? No, it's not a "nature of Chrome". It's a bug somewhere - memory leak, or something else. It might be worth investigating what it is about. Because you can stop tests after 2 hours, but are you going to tell your users to not use your application for more than 2 hours? Even if it's a bug in Selenium driver, it might be worth reporting it to selenium developers for your, and everyone else's benefit.

Upvotes: 1

Related Questions