【问题标题】:How can I run casperjs javascript tests from Jenkins?如何从 Jenkins 运行 casperjs javascript 测试?
【发布时间】:2012-11-23 14:03:23
【问题描述】:

我编写了一些 casperjs 测试来测试我的 Django 应用程序。如果启动了 Django 应用程序(例如在端口 8000 上),casperjs 可以作为单独的进程运行并访问我正在运行的 Django 应用程序。

我的其他测试是使用 Django 的(网络)测试框架编写的,该框架使用夹具设置测试数据库,并使用 ./manage.py test 运行。使用 Django webtest,您不需要启动单独的 Django 网络服务器(执行请求和 url 路由是代理/模拟的)。

有没有办法在 Django webtest 中运行 casperjs 测试?无需启动不同的网络服务器并拥有另一个测试数据库?

我已经看到 ghost.py 存在,但还没有尝试过。

【问题讨论】:

    标签: django jenkins phantomjs casperjs ghost.py


    【解决方案1】:

    我设法找到了解决方案。升级到 Django 1.4 后,我可以在子进程中使用 LiveServerTestCase 和 fork casperjs:

    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
    

    【讨论】:

      【解决方案2】:

      你应该看看django-casper。几天前我开始使用它,真是太棒了!

      【讨论】:

        猜你喜欢
        • 2012-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-12
        • 1970-01-01
        • 1970-01-01
        • 2014-07-03
        • 1970-01-01
        相关资源
        最近更新 更多