Selenium, Python and Jenkins on Debian - 1/3

This series is dedicated to the use of Selenium with Python. Selenium is a convenient way to automate your web application for testing purposes.

In this first post, we'll see how to configure your continuous integration environment to run Selenium tests. In a second one, how to add Selenium tests to your web project, and finally how to integrate all this within Jenkins.

This post assumes a Debian GNU/Linux environment, but you should not have much trouble adapting it to another Linux distribution.

Browsers installation

Selenium requires at least one browser in order to run tests. The following three are a good start:

To install them append the following Debian repositories to /etc/apt/sources.list:

# Opera: see http://wiki.debian.org/Opera (replace squeeze accordingly)
deb http://deb.opera.com/opera squeeze non-free
# Chrome
deb http://dl.google.com/linux/chrome/deb/ stable main

Then run:

$ aptitude update

Add the keys to trust the new repositories:

$ wget -q -O - http://deb.opera.com/archive.key | apt-key add -
$ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -

Finally re-update and install the packages:

$ aptitude update
$ aptitude install iceweasel opera google-chrome

Selenium also requires ChromeDriver to be able to interact with Chrome. Download chromedriver_linux64_X.zip or chromedriver_linux32_X.zip here (depending on your system). This zip contains an executable named chromedriver which should be in the PATH. Copy it in /usr/local/bin for example.

Display

If you are using slaves, it is likely that your Jenkins will run headlessly. If this is the case, you will need to provide a display when executing tests: this role is filled by vnc4server. To install it, just type:

$ aptitude install vnc4server imagemagick

Then, on the account running Jenkins, execute the following command to avoid prompts (password must be at least 6 characters):

$ vnc4passwdPassword:
Verify:

Your environment is now ready. In our next blog post, we'll see how to write Selenium tests for a Python web project based on Django.