Hide your Selenium browser window with a VNC server

Updated . Posted . Visible to the public.

This is now part of geordi. Please don't follow the instructions below, if you use geordi.

Inspired by the recent headless Selenium note, I found yet another solution for the problem to hide your selenium tests away.

This has the advantages
^

  • not to require a gem (so you do not force this on others)
  • to allow you to take a look at the running webdriver if necessary

Simply make a script that runs your cucumber tests and runs this before:

vncserver :6 -localhost -nolisten tcp -SecurityTypes None &>/dev/null 
DISPLAY=":6"

Your webdriver will now start within a VNC server (which will only listen to your machine). To take a look, open a VNC viewer using

vncviewer :6

You can close the viewer, and the tests will keep running.

Custom resolution

The X session provided by the VNC server can have a custom resolution. Just pass your preferred resolution like this: -geometry 1280x1024

Ubuntu issues

You need a VNC server and viewer:

sudo apt-get install tightvncserver
sudo apt-get install xtightvncviewer

sudo apt-get install vnc4server # alternative vncserver if tightvncserver doesn't work

Also on Ubuntu you are asked for a password the first time you start the VNC server. It will not be used by the above call after that (due to SecurityTypes None).

So for a first-time setup run it without the "&>/dev/null" part, choose a password, and terminate your vnc server.

Terminating the VNC server

vncserver -kill :6
Tobias Kraze
Last edit
Deleted user #6
Keywords
headless
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2011-07-25 21:49)