Git Product home page Git Product logo

django-protractor's Introduction

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

django-protractor's People

Contributors

dbaxa avatar dmikhaylov avatar jdmichaud avatar jpulec avatar juliomenendez avatar penguin359 avatar ryangallen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.