Derek Kwok's Blog

Blog about Software Development, Techniques and Discoveries.

Django and Selenium on Jenkins/Hudson (Headless)

| 1 Comment

Prerequisite: You already have a basic django build running on Jenkins/Hudson. If not, I highly recommend first reading Continuous Integration with Django and Hudson CI (Day 1).

Ubuntu:
Remember to replace link to selenium with version you need. Here we are using version 2.17.0 of Selenium.

wget http://selenium.googlecode.com/files/selenium-server-standalone-2.17.0.jar
sudo apt-get install xvfb
sudo apt-get install --no-install-recommends firefox
xvfb-run java -jar /root/selenium-server-standalone-2.17.0.jar

In your Jenkins/Hudson build step, you will want to:

  • export DISPLAY=:99
  • run your webserver (background)
  • run your tests
Below is a very simplified version of what I have.

Inside my __init__.py is the following code:

class BaseWebTestCase(TestCase):

    def setUp(self):
        self.base_url = 'http://localhost:8000'

        self.selenium = selenium(
            "localhost",
            4444,
            "*chrome",
            self.base_url
        )
        self.selenium.start()
        self.selenium.open('/')

    def tearDown(self):
        self.selenium.stop()

from webtests.account_tests import *

if __name__ == '__main__':
    import unittest, xmlrunner
    unittest.main(testRunner=xmlrunner.XMLTestRunner(
        output='xmlrunner',
        descriptions=True,
        verbose=True,
    ))

This is all that is needed to run Selenium tests in Jenkins/Hudson. With my settings above, the XML test results will be output into the folder “xmlrunner” which Jenkins/Hudson can read.

Tips and Tricks

You can autostart selenium when your machine boots by adding the following to /etc/rc.local:

xvfb-run java -jar /root/selenium-server-standalone-2.17.0.jar

One Comment

  1. Pingback: A Smattering of Selenium #76 « Official Selenium Blog

Leave a Reply

Required fields are marked *.

*