【问题标题】:Running 'casperjs test' in phantom在幻象中运行“casperjs 测试”
【发布时间】:2013-11-08 10:47:46
【问题描述】:

所以我有一个在节点中运行的文件,它运行 PhantomJS 的本地副本,如下所示:

phantom.casperPath = 'node_modules/casperjs';
phantom.injectJs('node_modules/casperjs/bin/bootstrap.js');
var casper = require('casper').create({
    viewportSize: config.viewportSize
});

casper.test.begin('Runing tests here', 5, function suite(test) {
    // Tests here
});

没有casper.test.begin() 我的测试功能正常。我有正确的版本 1.1.0 可以使用这个测试套件,但我在控制台中收到以下错误:

CasperError: casper.test property is only available using the `casperjs test` command

CasperJS 文档也提到了这一点:http://docs.casperjs.org/en/latest/testing.html。我的问题是如何在上面代码中的这个命令下运行这个 Casper 以便我可以使用这些测试?

谢谢!

【问题讨论】:

    标签: node.js phantomjs casperjs


    【解决方案1】:

    CasperError: casper.test 属性仅在使用casperjs test 命令时可用

    问题解决了。

    您必须在 xyz.js 中的脚本顶部包含这一行,以便 .test 属性变为 true;

    phantom.casperTest = true;
    

    那么从终端启动应该没问题:

    casperjs xyz.js
    

    【讨论】:

    • 在我阅读bootstrap.js的过程中,看到了casperTest的设置,但是做了很多事情。在我从 phantomjs REPL 运行 capserjs 的用例中,这个答案还不够。
    【解决方案2】:

    您也可以拨打casperjs test xyz.js

    欲了解更多信息,请在此处查看文档:http://docs.casperjs.org/en/latest/testing.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多