0

I few of my test cases, driver object is not closed but test cases has been complete. In the following test cases how to identify that the driver object is no more refernced. In other words when will an unused webdriver object loses it refernce.

  • This would depend on how you have coded it. You should create webdriver object at test level and it will work without issues – Tarun Lalwani Feb 12 '18 at 05:48

1 Answers1

0

As per best practices there should be no WebDriver object remaining in the System Memory which is not-closed or destroyed (i.e. dangling) once the execution of the Test Suite has been completed.

To keep your Test System free from unused WebDriver and Web Client objects you should invoke the quit() method within the tearDown() method {}. Invoking quit() DELETEs the current browsing session through sending "quit" command with {"flags":["eForceQuit"]} and finally sends the GET request on /shutdown EndPoint. Here is an example below :

1503397488598   webdriver::server   DEBUG   -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74 
1503397488607   geckodriver::marionette TRACE   -> 37:[0,4,"quit",{"flags":["eForceQuit"]}]
1503397488821   webdriver::server   DEBUG   -> GET /shutdown

So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any other additional steps which would have been an overhead.

You can find about the various methods available to clear off the WebDriver instances staying in the memory in the discussion PhantomJS web driver stays in memory

You can also find about some alternative methods available to clear off the WebDriver process in the discussion Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352