suppose a client starts a selenium session on an RC server, but at the middle of the session the client "went away". The browser will remain open, and eventually, after enough such dropped sessions, there will be enough "orphan" browsers to slow down the computer.

- 36,924
- 42
- 155
- 176

- 23,991
- 34
- 108
- 149
-
You must accept an answer once you think your question has been answered... – Santi Aug 25 '09 at 20:24
-
On the similar note, could I reuse the existing browser sessions? :) – Nayn Dec 03 '10 at 08:39
-
@Nayn - yes you can! :) There's an argument you can send the selenium RC when it starts: -browserSessionReuse – olamundo Dec 03 '10 at 11:19
3 Answers
Any browser instance has a session_id you can store. Python example:
>>> import selenium
>>> browser = selenium.selenium("localhost",4444, "*firefox", "http://www.santiycr.com.ar")
>>> browser.start()
>>> browser.sessionId
u'b4ad1f1d624e44d9af4200b26d7375cc'
So, if you store these sessionId in a file when your test starts and then remove it when your tests ends, you'll have a log file with sessions for tests that didn't end up properly.
Now using cron, or any regular execution, you can read that file, iterate over the sessionIds stored in it and open the following url (using a browser or even an http library for your programing language):
http://localhost:4444/selenium-server/driver/?sessionId=THE-SESSION-ID&cmd=testComplete
That should do the trick.
Edit: I found this question so interesting that created a post in my blog about the solution. If you're a python guy you'll find it interesting: http://www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-browsers-from-selenium-rc

- 4,428
- 4
- 24
- 28
-
For Firefox browsers, you can find out the sessionid by checking the profile folder name. On a unixlike system, `ps ax | grep firefox-bin` will return something like `12345 ? 1:00 /usr/lib/iceweasel/firefox-bin -profile /tmp/customProfileDir
`. – Tgr Jul 01 '11 at 12:04
You can also just kill the process:
Windows:
taskkill /f /im iexplore.exe
taskkill /f /im firefox.exe
*nix:
for i in `ps -A | grep firefox | awk '{print $1}'`; do kill -9 $i; done

- 21
- 1
-
this will kill all firefoxes, not just the "zombie" one. so if, for instance, you run two rc's on the same machine (not that unlikely), you might end up klling an ff that was used by the other RC. – olamundo Sep 25 '10 at 15:48