Skip to main content

A nose plugin to run selenium tests with django

Project description

Adds selenium testing support to your nose test suite.

To use, run nosetests with the --with-selenium flag.

Why use Selenium?

Selenium is a portable testing framework for web applications. It allows you to write tests that run in the browser to test your user interface and javascript code that is not available through the usual testing channels. See the examples below to get a clearer impression of what selenium tests can provide.

django-nose-selenium allows you to write and run selenium tests the same way as usual django unit tests.


The plugin expects that you have configured the django-nose app. In a nutshell, this is done by running pip install django-nose, adding django_nose to INSTALLED_APPS and setting TEST_RUNNER to django_nose.NoseTestSuiteRunner in the


From PyPI:

pip install django-nose-selenium

In-development version via Pip:

pip install django-nose-selenium==dev

Directly from Git:

pip install -e

Django Settings

The plugin supports the following settings:

  • SELENIUM_HOST, default:
  • SELENIUM_PORT, default: 4444
  • SELENIUM_BROWSER_COMMAND, default: chrome
  • SELENIUM_URL_ROOT, default:
  • FORCE_SELENIUM_TESTS, default: False. By default, SocketErrors cause the tests to be skipped. This options causes the tests to fail when the Selenium server is unavailable.


Define the class variable selenium_test = True in your nose test class. You can use self.selenium to access a selenium instance with the given options:

class TestSelenium(TestCase):

    selenium_test = True

    def test_start(self):
        """Tests the start page.""""/")

To run this test, you have to pass the option --with-selenium to the Django management command test:

python test --with-selenium

Alternatively, django-nose-selenium provides a mixin that has the benefit of raising a SkipTest exception if the plugin was not loaded and the selenium attribute is accessed:

from noseselenium.cases import SeleniumTestCaseMixin

class TestSelenium(TestCase, SeleniumTestCaseMixin):

    def test_start(self):
        """Tests the start page.""""/")


The default fixtures of django are run in transactions and not available to a live testing server, therefore noseselenium provides an option to load and commit fixtures to the database automatically. Please note that there’s no automatic rollback, so the data will stay in your test database for the rest of the run if you don’t provide a custom teardown strategy.

from noseselenium.cases import SeleniumTestCaseMixin

class TestUserLogin(TestCase, SeleniumTestCaseMixin):

    selenium_fixtures = ['user_data.json']

    def tearDown(self):
        # Remove data from user_data.json

    def test_login(self):
        """Tests the login page."""

        sel = self.selenium"/login/")
        sel.type("id_username", "pascal")
        sel.type("id_password", "iwantapony")"//form[@id='myform']/p/button")
        self.failUnless(self.is_text_present("Hello, Pascal!"))

To enable selenium fixtures, nosetests must be called with the additional --with-selenium-fixtures flag.


noseselenium provides expiremental support for running a live server that Selenium can connect to. Currently, there’s a threaded server that reuses django’s development webserver and a cherrypy implementation. It’s recommended you use the cherrypy one as the django devserver is certainly not designed to run in a multi-threaded environment.

The liveserver plugin introduces two new configuration options:

  • LIVE_SERVER_ADDRESS, defaults to
  • LIVE_SERVER_PORT, defaults to 8080
  • LIVE_SERVER_STATIC, boolean that defaults to True. If enabled, the live server enables serving of static files via the django.contrib.staticfiles app.

These should match your Selenium Settings.

To start the liveserver, nosetest is called with either the --with-djangoliveserver or preferably the --with-cherrypyliveserver flag.

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-nose-selenium-0.7.3.tar.gz (26.8 kB) Copy SHA256 hash SHA256 Source None Aug 15, 2011

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page