Functional Website Testing with Selenium

We will use Jenkins CI": in order to run "SeleniumHQ tests headlessly on a Debian server.

Install SeleniumHQ

The Selenium Server is needed in order to run either Selenium RC style scripts or Remote Selenium Webdriver ones. Download the Selenium Standalone Server from into an appropriate location and create a softlink:

mkdir /usr/lib/selenium
cd /usr/lib/selenium
ln -s selenium-server-standalone-2.53.0.jar selenium-server.jar

Test run the selenium server

edit-develop:/usr/lib/selenium# java -jar selenium-server.jar 
15-Mar-2011 12:29:48 java.util.prefs.FileSystemPreferences$2 run
INFO: Created user preferences directory.
12:29:48.291 INFO - Java: Sun Microsystems Inc. 17.1-b03
12:29:48.295 INFO - OS: Linux 2.6.26-1-xen-amd64 amd64
12:29:48.299 INFO - v2.0 [b2], with Core v2.0 [b2]
12:29:48.475 INFO - RemoteWebDriver instances should connect to:
12:29:48.479 INFO - Version Jetty/5.1.x
12:29:48.479 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
12:29:48.479 INFO - Started HttpContext[/selenium-server,/selenium-server]
12:29:48.479 INFO - Started HttpContext[/,/]
12:29:48.507 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@68e6ff0d
12:29:48.507 INFO - Started HttpContext[/wd,/wd]
12:29:48.511 INFO - Started SocketListener on
12:29:48.511 INFO - Started org.openqa.jetty.jetty.Server@30f7f540

See also Installing Selenium server 2 as a service

Install xvfb

The following installation instructions have been copied from the great guidance on this topic, though we found that we need to install additional packages we decided repeat and extend this guidance here.

To install xvfb:

sudo apt-get install xvfb libgl1-mesa-dri xfonts-cyrillic xfonts-100dpi xfonts-75dpi

And then to check everything’s OK:

Xvfb :99

Where :99 is the display number. We set it to 99 to avoid any conflict with other displays, should they be attached. The command line should just hang without any comments until you press CTRL-C to close.

Install iceweasel (firefox)

Iceweasel is a fork Firefox with the following purpose.

Iceweasel can be installed from the Debian repository with

@ apt-get install icewease@.

Nevertheless a newer backport from the Debian Mozilla team is usually preferable:

Add the sources (in this example for debian squeeze), add the apt key and install the latest iceweasel release

echo "deb squeeze-backports main" > /etc/apt/sources.list/iceweasel.list
echo "deb squeeze-backports iceweasel-release" >> /etc/apt/sources.list/iceweasel.list
apt-get install pkg-mozilla-archive-keyring
apt-get update
apt-get install -t squeeze-backports iceweasel


Test & troubleshooting iceweasle & tests

Remotely via X11 forwarding

Open a ssh session with X11 forwarding (with compression) and start icewaesel from within the session

ssh -c arcfour,blowfish-cbc -XC root@
iceweasel &

After a little while (depending on the connection speed) iceweasel will appear on your local computer screen.

Headless with screen shot

And then, once you’re installed, to test that it works OK.

  1. Start Xvfb in one window as above,

  2. then in a second terminal window:

export DISPLAY=:99

you should see nothing except maybe a message that the extension [RANDR" missing on display ](99.0") – firefox should just sit there until you CTRL+C.

The “export DISPLAY=:99″ line is telling firefox to use display # 99, which we started above.

we want to take take a screenshot in order to check that everything is ok. We will use ImagMagick to take screen shots in addition we also install the x11-utils in order get the xwininfo tool.

See also:

apt-get install imagemagick x11-utils

Now take a screenshot of the root window:

export DISPLAY=:99
import -window root example.png

The screenshot would look like this:


If you want to get a list of all windows currently managed by Xvfb :

xwininfo -root -tree

Jenkins CI

Install the Seleniumhq Plugin and configure it according to

However in order to actually run the test suites we need to configure a Execute shell build step which will start selenium using the which is found below.

The Execute shell build step:

 bash -ex /usr/lib/selenium/ $WORKSPACE $WORKSPACE/test/selenium/TestSuite-search.html

The script:

#     bash -ex /usr/lib/selenium/ $BASEURL $WORKSPACE $TEST_SUITE

SELENIUM="java -jar /usr/lib/selenium/selenium-server.jar"
# This option creates screen screennum and sets its width, height, and depth to W, H, and  D  respectively.
# By default, only screen 0 exists and has the dimensions 1280x1024x8.
SCREEN="0 1280x1024x16"

#Use virtual X server

if [ -z "$(pidof Xvfb)" ]; then
        $VIRTUAL_X &
export DISPLAY

$SELENIUM -htmlSuite "*firefox $FIREFOX_BIN" ${BASEURL} ${TEST_SUITE} ${WORKSPACE}/selenium-results.html

The following screenshot givens an example of a Jenkins job configuration:


Updated by Katja Luther 7 months ago · 37 revisions