I've written some casperjs tests to test my Django application. If the Django application is started (on port 8000 for example), casperjs can be run as a separate process and access my running Django app.
My other tests are written with Django's (web)testing framework that sets up the test database with fixtures, and are run with ./manage.py test
. With Django webtest, you don't need to start a separate Django webserver (doing requests and url routing is proxied/simulated).
Is there a way to rung casperjs tests from within Django webtest? Without starting a different webserver and having yet another test database?
I've seen ghost.py exists, but haven't tried it yet.
I've managed to find a solution. After upgrading to Django 1.4 I can use LiveServerTestCase and fork casperjs in a subprocess:
from django.test.testcases import LiveServerTestCase
import os, subprocess
from subprocess import Popen, PIPE, STDOUT
class CasperTest(LiveServerTestCase):
fixtures = ['test_initial_data', ]
def test_my_testcase(self):
p = Popen(['casperjs %s/caspertest.js' % os.path.dirname(__file__)], shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
print output
You should take a look at django-casper. I started to use it a few days ago and it is just awesome!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With