Casperjs "casper.test property is only available using the `casperjs test` command"但不调用 casper test



错误:

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

搜索了我的整个代码库"casper.test","this.test","@test"等,但没有一个存在。查看 casper 代码,需要触发其中一个代码才能引发此错误。

该错误是间歇性的,仅在某些卡斯珀运行中发生。还有其他人得到这个错误吗?我正在运行1.1.0-beta3.

您可以添加

phantom.casperTest = true;

在测试文件的顶部。

你像这样启动你的脚本了吗?

casperjs test yourScript.js

它与启动它无关。不知道为什么,但是在写入文件之前,我的代码也收到了此错误。删除后它消失了...

JSON.stringify(obj);

同样,我不知道是什么导致了这个问题。这可能是其他原因导致你。但是,如果您找到导致它的代码段,我有一个解决方案。

我的解决方案:通过基本变量开关使用错误处理程序,并关闭该部分步骤的错误日志。

casper.on("error", function(err) {
    if(custLog) {console.log(err);} //log the error
});

在步骤中...

casper.then(function() {
    custLog = false;
    fs.write(fileName, JSON.stringify(content), 'w');
    custLog = true;
});

您可能需要也可能不需要在那里订购内部堆栈的重新排序。

最新更新