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!
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.
First ensure that the latest version of the
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).
Then declare all the Python versions you want to test against with the
Manage Jenkins > Configure System page (one shot configuration):
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.
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
First of all, create a
New Job, enter its name (here
djangotutorial) and select
Build multi-configuration project before validating.
As usual, setup:
- The description.
- The source repository, here the
- The build trigger policy: checking for modifications every five minutes in this example.
Start a display
A display is required to run Selenium tests.
To start one, enable
Run Xvnc during build in the
Build Environment section.
To be able to install all the required packages, a
Virtualenv Builder is recommended.
Add build step in the
Build section and select
Enter all required steps in the
- Install dependencies with pip,
- Execute the
jenkinsgoal with the right browser.
Here is the full
pip install -r requirements.txt $PYTHON_EXE manage.py jenkins --selenium-driver=$BROWSER
Django-jenkins generates a lot of useful data for Jenkins in a
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 patternfield to
Report Violations: loads PyLint report. Set its
XML filename patternfield for
Publish JUnit test result report: generates a test result report. Set its
Test report XMLsfield to
E-mail Notification: sends e-mails on build status changes.
Finally save the configuration with the
Start a new build by clicking on
Build Now, and wait for the results: