Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run casperjs javascript tests from Jenkins?

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.

like image 811
ivy Avatar asked Nov 23 '12 14:11

ivy


2 Answers

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
like image 127
ivy Avatar answered Nov 02 '22 02:11

ivy


You should take a look at django-casper. I started to use it a few days ago and it is just awesome!

like image 45
user2421123 Avatar answered Nov 02 '22 01:11

user2421123