Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

jpulec/django-protractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Protractor

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

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

Configuration

There are a variety of options available:

  • --protractor-conf to specify a protractor config file. Default is protractor.conf.js
  • --runserver-command to specify a different runserver command. Default is runserver
  • --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 is localhost:8081
  • --fixture to specify which a fixture to load. This can be used multiple times and will load all specified fixtures.

About

Easily run your protractor tests with django

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages