Monday, August 1, 2016

Running Selenium in Headless Mode on Linux Host

If you want to run selenium on a remote linux machine, which does not have any display, you have the following options available:

(From Wikipedia) Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in memory without showing any screen output. Xvfb can be installed via the following command (tested on CentOS 7):
yum install xorg-x11-server-Xvfb
Once the installation is complete, you can start Xvfb by issuing following command:
Xvfb :99 &
Once the server is launched, export the DISPLAY environment variable so that other programs can find it:
export DISPLAY= :99
You should now be able to run your selenium tests.

Xvfb is not maintained anymore. A more recent supported option is to use XDummy. It is a script developed by Karl Runge to allow a standard X11 server to be used by non-root users with the dummy video driver. If you want to use XDummy, follow the following steps: 1. Make sure you have gcc installed. 2. Download the XDummy script and execute it
chmod +x Xdummy
Xdummy :99 &
XDummy is a drop in replacement for Xvfb (at least from selenium perspective). I have used both Xvfb and XDummy, and found XDummy to be more stable. I have seen Xvfb crashing if I leave the tests running for a while.