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).

/media/blog/45/plugin_manager.png

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

/media/blog/45/installations.png

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

/media/blog/45/new_job.png

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

Basic setup

/media/blog/45/name_source_trigger.png

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.

/media/blog/45/xvnc.png

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

Axis

Python axis

/media/blog/45/python_axis.png

Browser axis

/media/blog/45/browser_axis.png

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.

/media/blog/45/virtualenv_builder.png

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.

/media/blog/45/post_build_actions.png

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:

/media/blog/45/results.png

Comments

No comments yet.

Post your comment