CI | jenkins python selenium tutorial Wed 25 January 2012 Olivier Mansion

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:

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

Then run:

1 $ aptitude update

Add the keys to trust the new repositories:

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

Finally re-update and install the packages:

1 $ aptitude update
2 $ 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:

1 $ aptitude install vnc4server imagemagick

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

1 $ vnc4passwdPassword:
2 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.