1

I am currently working on a project that requires using multiple windows each requiring different sessions and cookies.

After each window is created and does its work it needs to be closed. Then the process is repeated.

The windows are created in an array as shown.

var fOptions = new firefox.Options();
var profile = new firefox.Profile('./fProfile');
fOptions.setProfile(profile);    
driver[0] = new Builder().withCapabilities({'browserName': 'firefox'}).setFirefoxOptions(fOptions).build();
driver[1] .....

What would be the best way to close the windows: using driver[index].close() or driver[index].quit()

I sometimes run into this error This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used. when using driver[index].quit()

And also get a lot of tmp-[abcd] folders in my TEMP directory am guessing from undeleted sessions.

I am open to any solutions that achieve new sessions on multi-window tests

I am using nodeJS implementation of Selenium with gecko driver.

Bob Kimani
  • 1,114
  • 1
  • 20
  • 38
  • 1
    Multiple windows means multiple browser tabs or multiple browser instances (having single tab) ? . Moreover I would use driver.close() method only when In case I have multiple tabs opened in same browser instance and want to close the one which is active right now . While driver.quit() will be used to terminate whole browser instance. One more thing , there used to be 'driver.dispose()' method as well , which does kinda same as driver.quit() , apart from ending session SAFELY. – sjethvani Feb 13 '18 at 11:34

1 Answers1

1

As you are creating the windows in an array so the the best way to close the windows will be using :

driver[index].close()

Analysis

When you invoke quit() the webdriver::server sends DELETE to the geckodriver::marionette for the entire session as follows :

webdriver::server   DEBUG   -> DELETE /session/f84dbafc-4166-4a08-afd3-79b98bad1470 

geckodriver inturn sends "quit" signal along with "eForceQuit" flag to marionette as follows :

geckodriver::marionette TRACE   -> 37:[0,3,"quit",{"flags":["eForceQuit"]}]

marionette finally generates the log that Marionette won't be accepting any further connections the cause being "shutdown" as follows :

1518532363988   Marionette  DEBUG   New connections will no longer be accepted
1518532364053   Marionette  TRACE   0 <- [1,3,null,{"cause":"shutdown"}]
1518532364088   geckodriver::marionette TRACE   <- [1,3,null,{"cause":"shutdown"}]
1518532364089   webdriver::server   DEBUG   Deleting session
1518532364089   geckodriver::marionette DEBUG   Stopping browser process
1518532364519   webdriver::server   DEBUG   <- 200 OK {"value": {}}

Though your driver instances are indexed but as Marionette stops accepting connections hence you observe the following error :

This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

Instead if you invoke close(), the webdriver::server sends DELETE to the geckodriver::marionette for the particular session windown only as follows :

1518532935982   webdriver::server   DEBUG   -> DELETE /session/3694b8b7-89b1-4249-a710-0915ad2e867e/window 
1518532935983   geckodriver::marionette TRACE   -> 16:[0,4,"close",{}]
1518532935985   Marionette  TRACE   0 -> [0,4,"close",{}]   

Hence the other Windows / TABs will remain unaffected.


Update

If you observe the GeckoDriver logs closely it is evident that Marionette scoops out a new moz:profile while creating a new session as follows :

1518532230009   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\user_name\\AppData\\Local\\Temp\\rust_mozprofile.TxhOyDz3ozxL"

This activity is managed and handled by the WebDriver instance i.e. the GeckoDriver . This workflow is in practice since we migrated from the Legacy Firefox to Marionette based Firefox and these stacks up in the temporary directory. As of now I don't see GeckoDriver cleaning up the chores at the end of the Test Execution. So a solution to clean up the rust_moz folders will be to run CCleaner tool regularly at-least before and after the execution of your Test Suite.

You can find a detailed discussion on _“rust_mozprofile”_ directory in _Is it Firefox or Geckodriver, which creates “rust_mozprofile” directory_

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • regarding the resulting temp folders is there a way to avoid them? I find that using either `close()` and `quit()` auto deletes the respective **rust_moz** folders while a **tmp-[] folders** remain undeleted: especially when using a custom Firefox Profile see my updated code. – Bob Kimani Feb 13 '18 at 23:34
  • As per your comment added an update to my answer. Let me know if you have further counter questions. – undetected Selenium Feb 14 '18 at 06:49
  • Thanks how can I turn on the trace logs for the gecko driver, haven't found a tutorial for Selenium JS + where can I find the logs – Bob Kimani Feb 14 '18 at 07:44
  • Can you raise a new question for your new requirement please :) – undetected Selenium Feb 14 '18 at 07:50
  • :) [here](https://stackoverflow.com/questions/48782242/turn-on-logging-for-gecko-driver-in-selenium-node-js) – Bob Kimani Feb 14 '18 at 07:59