这可能是一个愚蠢的问题(CasperJS noob):给出了CasperJS文档中的这个例子:
// cow-test.js
casper.test.begin('Cow can moo', 2, function suite(test) {
var cow = new Cow();
test.assertEquals(cow.moo(), 'moo!');
test.assert(cow.mowed);
test.done();
});
如果文件Cow()
中定义了\path\to\myCowClass.js
,如何在通过CLI使用CasperJS时加载此类?这是files
配置参数还是clientScripts
的工作?
如果有人有简明的教程/示例,我真的很喜欢。
答案 0 :(得分:2)
我们来看看你的Cow.js
文件。我认为它看起来像这样:
function Cow() {
this.mooed = false;
}
Cow.prototype.moo = function () {
this.mooed = true;
return 'moo!';
}
此文件应该是您的测试的依赖项。在这里你可以:
includes
选项phantom.injectJs
使用--includes
casperjs test --includes=/path/to/Cow.js cow-test.js
使用phantom.injectJs
// cow-test.js
phantom.injectJs('/path/to/Cow.js');
casper.test.begin('Cow can moo', 2, function suite(test) {
var cow = new Cow();
test.assertEquals(cow.moo(), 'moo!');
test.assert(cow.mooed);
test.done();
});