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.

Dependencies
------------
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::

INSTALLED_APPS = (
...
'protractor',
)

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

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

FooFactory()
BarFactory()

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.


Configuration
-------------

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: https://angular.github.io/protractor/#/
.. _factory_boy: https://github.com/rbarrois/factory_boy
.. _StaticLiveServerTestCase: https://docs.djangoproject.com/en/1.8/ref/contrib/staticfiles/#django.contrib.staticfiles.testing.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-0.8.4.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-protractor-0.8.4.tar.gz.

File metadata

File hashes

Hashes for django-protractor-0.8.4.tar.gz
Algorithm Hash digest
SHA256 470f19715b0636f41795b24d9b2f6219013c7a74bcaa79240212ef12fed27327
MD5 ce96e401acfcb216134dda480adf67d3
BLAKE2b-256 f153521855746de7e7422a0cc12a2d0cb0a8c10f685361cdc0242a304eebab10

See more details on using hashes here.

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