Multi-browser Selenium tests with Django 1.4+ on Jenkins

In our previous blog post, we saw how to enable Selenium tests on a Django 1.4+ project. Now it's time to see how to integrate it with Jenkins!

Platform

This post assumes a Debian GNU/Linux environment, but you should not have much trouble adapting it to another Linux distribution. All requirements are listed in our initial blog post: Selenium, Python and Jenkins on Debian - 1/3.

Global Configuration

First ensure that the latest version of the ShiningPanda Plugin, Xvnc Plugin, Violations Plugin and Cobertura Plugin are installed (check on Manage Jenkins > Manage Plugins > Installed page). If not, look for them in the Available tab and perform the installation (don't forget to restart Jenkins).

image

Then declare all the Python versions you want to test against with the Manage Jenkins > Configure System page (one shot configuration):

image

To add a Python version, search the Python section and click on Add Python. Then give the installation a name and enter its home folder (ie. PYTHONHOME).

Sample project

This tutorial is based on the sample project described in Multi-browser Selenium tests with Django 1.4+. Our goal is to integrate this project within Jenkins.

Create a new job

image

First of all, create a New Job, enter its name (here djangotutorial) and select Build multi-configuration project before validating.

Basic setup

image

As usual, setup:

  • The description.
  • The source repository, here the django14-selenose branch of https://github.com/shiningpanda/djangotutorial-selenose.git.
  • The build trigger policy: checking for modifications every five minutes in this example.

Start a display

A display is required to run Selenium tests.

image

To start one, enable Run Xvnc during build in the Build Environment section.

Axis

Python axis

image

Browser axis

image

Builder

To be able to install all the required packages, a Virtualenv Builder is recommended.

Click on Add build step in the Build section and select Virtualenv Builder.

image

Enter all required steps in the Command field:

  • Install dependencies with pip,
  • Execute the jenkins goal with the right browser.

Here is the full Command content:

pip install -r requirements.txt
$PYTHON_EXE manage.py jenkins --selenium-driver=$BROWSER

Post-build actions

Django-jenkins generates a lot of useful data for Jenkins in a reports folder.

image

To load them all, click on Add post-build action in the Post-build Actions section and select the following ones:

  • Publish Cobertura Coverage Report: generates a code coverage report. Set its Cobertura xml report pattern field to reports/coverage.xml,
  • Report Violations: loads PyLint report. Set its XML filename pattern field for pylint to reports/pylint.report,
  • Publish JUnit test result report: generates a test result report. Set its Test report XMLs field to reports/junit.xml,
  • E-mail Notification: sends e-mails on build status changes.

Finally save the configuration with the Save button.

Results

Start a new build by clicking on Build Now, and wait for the results:

image