*UNMAINTAINED*
I stopped using this library an no longer wish to maintain it. If someone really wants to take over ownership of it, and the ability to deploy oo PyPI, reach out to me.
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
Add "protractor" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'protractor', )
Run the following command to run your protractor tests:
python manage.py protractor
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 ProtractorTestCaseMixin
like so, setting the class attribute
specs
to a list of protractor specs. This list will be piped to the --specs
arg that protractor recieves. Then do any necessary
setup by overriding the setUp()
method.
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:
get_protractor_params()
should return a dict that will be piped to protractor with the --params
argument.
By default this passes in the value of self.live_server_url
.
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:
--protractor-conf
to specify a protractor config file. Default isprotractor.conf.js
--runserver-command
to specify a different runserver command. Default isrunserver
--specs
to specify which protractor specs to run.--suite
to specify which protractor suite to run.--addrport
to specify which ipaddr:port to run the server on. Default islocalhost:8081
--fixture
to specify which a fixture to load. This can be used multiple times and will load all specified fixtures.