0

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.

  • Can you post your complete code? I'm wondering if you aren't opening multiple browsers in a loop. – Matt Cremeens Nov 29 '18 at 17:14
  • Complete code is 4000 lines long. I tested this on a smaller code by writting big text with 1 second delay in between. It slows down after some moment. I don't open multiple browsers. I am working on 1 session. – Mark Letterman Nov 29 '18 at 17:21
  • This question discusses how to save and load cookies between sessions with pickle: [How to save and load cookies using Python + Selenium WebDriver](https://stackoverflow.com/questions/15058462/how-to-save-and-load-cookies-using-python-selenium-webdriver) – G. Anderson Nov 29 '18 at 17:31
  • Then I would at least post the minimum code that could possibly point to a problem. I agree with @Kiril S. in that there is likely a problem with your code somewhere. – Matt Cremeens Nov 29 '18 at 18:41

1 Answers1

1

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.

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
  • [SOLID](https://www.tomdalling.com/blog/software-design/solid-class-design-the-liskov-substitution-principle/), is a developers best friend. +1. – Brian Nov 29 '18 at 17:36
  • I need to run test for 6 hours due to specific request i am doing. There is no memory leak due to the fact that i am tracing every single byte coming and going out of my script. I do not deal with any memory allocation whatsoever because code only deals with printing output and clicking on elements. It is not only me that has problems with this. Many people have problems with Selenium being slow after some period of time. You can read about it online. Only solution to that problem is to use driver.quit() and to restart the session. I can't do that. – Mark Letterman Nov 29 '18 at 22:43