Skip to main content

django-nose-selenium

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.

Requirements

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 settings.py.

Installation

From PyPI:

pip install django-nose-selenium

In-development version via Pip:

pip install django-nose-selenium==dev

Directly from Git:

pip install -e
git://github.com/weluse/django-nose-selenium.git#egg=django-nose-selenium

Django Settings

The plugin supports the following settings:

  • SELENIUM_HOST, default: 127.0.0.1

  • SELENIUM_PORT, default: 4444

  • SELENIUM_BROWSER_COMMAND, default: chrome

  • SELENIUM_URL_ROOT, default: http://127.0.0.1:8000

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

Usage

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

        self.selenium.open("/")

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

python manage.py 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."""

        self.selenium.open("/")

Fixtures

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
        sel.open("/login/")
        sel.type("id_username", "pascal")
        sel.type("id_password", "iwantapony")
        sel.click("//form[@id='myform']/p/button")
        sel.wait_for_page_to_load(5000)
        self.failUnless(self.is_text_present("Hello, Pascal!"))

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

Liveserver

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 0.0.0.0

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

Metadata

Release files for django-nose-selenium 0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-nose-selenium 0.7.3
File Size Uploaded Provenance Actions
django-nose-selenium-0.7.3.tar.gz 26.8 kB Without provenance Details for django-nose-selenium-0.7.3.tar.gz

Release files / django-nose-selenium-0.7.3.tar.gz

Download URL django-nose-selenium-0.7.3.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6e438f18001f9d8a8073836cd6bb5f2925ccabed74a3946025dc932f4e918673
BLAKE2b-256 checksum
How to use checksums
413d68ff8319715383f9801f59285b3216a30dc9c3eede4cffa9bf0ed4c2f2ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-nose-selenium 0.7.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page