How to Hide the Browser in Selenium Rc

Is it possible to hide the browser in Selenium RC?

There are a few options:

  • You could use Selenium Grid so that the browser is opened on a completely different machine (or virtual machine) that you can then connect to via VNC or Remote Desktop Connection if you wanted to see the browser. Also, another option: if you run a Jenkins foreground process on that remote server, it can execute your test project on the desktop.

  • You can run Selenium 'headless' on Linux in XVFB. I've never tried doing this and doubt it's really worth the effort. http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

  • You can wrap Selenium RC in a Windows service. http://support.microsoft.com/kb/137890 . Except that permissions constraints on later versions of windows will probably prevent Selenium from accessing the desktop like Windows 2000 used to allow us to do.

  • Another option would be to use something like WebDriver HTMLUnitDriver, which doesn't launch a 'real' browser. http://code.google.com/p/webdriver/ . Also there is a PhantomJS option as well as a 'headless Chrome' that you could use.

  • Of course there's also the option of using a service like SauceLabs, where you can get your tests to be run in the cloud. After your tests have completed you can watch a video of them running.

How to close a browser on a selenium RC server which lost it's client

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



Related Topics



Leave a reply



Submit