Skip to main content

Easily integrate your protractor tests with django

Project description

Django Protractor

Easily integrate your protractor tests in your django project, and get a fresh test database with every run.
Additionally, there is an included test case mixin to allow any custom setup code to run.

You must have npm and protractor installed. `See Protractor Documentation for more details`_

Quick Start Testing

1. Add "protractor" to your INSTALLED_APPS setting like this::


2. Run the following command to run your protractor tests::

python protractor

More Advanced Test Case Customization
If you're like me, you'll find that one-time fixture loading for all of your protractor tests just isn't enough.
I use the wonderful `factory_boy`_ for my test setup and wanted to find a way to incorporate it with my protractor acceptance tests.
What spawned is an incredibly hack-y mixin that allows me to do just that.

Create a Subclass of `StaticLiveServerTestCase`_ incorporating the :code:`ProtractorTestCaseMixin` like so, setting the class attribute
:code:`specs` to a list of protractor specs. This list will be piped to the :code:`--specs` arg that protractor recieves. Then do any necessary
setup by overriding the :code:`setUp()` method.

.. code:: python

from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from protractor.test import ProtractorTestCaseMixin

class MyAcceptanceTestCase(ProtractorTestCaseMixin, StaticLiveServerTestCase):
specs = ['tests/acceptance/test-spec.js',]

def setUp(self):
"""Do factory setup stuff."""
super(MyAcceptanceTestCase, self).setUp()


def get_protractor_params(self):

def test_run(self):

There are two other hooks that exist as well that can be overridden:

:code:`get_protractor_params()` should return a dict that will be piped to protractor with the :code:`--params` argument.
By default this passes in the value of :code:`self.live_server_url`.

:code:`test_run()` is the actual method that gets discovered by test runners, and calls out to protractor using subprocess.
You may need to override this if you want to do any python assertions about database state after your protractor tests
have run.


There are a variety of options available:

- :code:`--protractor-conf` to specify a protractor config file. Default is :code:`protractor.conf.js`
- :code:`--runserver-command` to specify a different runserver command. Default is :code:`runserver`
- :code:`--specs` to specify which protractor specs to run.
- :code:`--suite` to specify which protractor suite to run.
- :code:`--addrport` to specify which ipaddr:port to run the server on. Default is :code:`localhost:8081`
- :code:`--fixture` to specify which a fixture to load. This can be used multiple times and will load all specified fixtures.

.. _See Protractor Documentation for more details:
.. _factory_boy:
.. _StaticLiveServerTestCase:

Project details

Download files

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

Source Distribution

django-protractor-new-0.9.1.tar.gz (6.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page