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).
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. PYTHONHOME
).
Sample project
This tutorial is based on the sample project described in 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 a free-style software project
before validating.
Basic setup
As usual, setup:
- The description.
- The source repository, here the
django14
branch ofhttps://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.
To start one, enable Run Xvnc during build
in the Build Environment
section.
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
.
Select the desired Python version and enter all required steps in the Command
field:
- Install dependencies with pip,
- Execute the
jenkins
goal.
Here is the full Command
content:
pip install -r requirements.txt
$PYTHON_EXE manage.py jenkins
Post-build actions
Django-jenkins generates a lot of useful data for Jenkins in a reports
folder.
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 itsCobertura xml report pattern
field toreports/coverage.xml
,Report Violations
: loads PyLint report. Set itsXML filename pattern
field forpylint
toreports/pylint.report
,Publish JUnit test result report
: generates a test result report. Set itsTest report XMLs
field toreports/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: