在Stack中很多人都在苦苦挣扎,我试图将我的CasperJS测试分成多个文件。我花了三天的时间阅读文档并在这里查看答案,似乎找不到任何有用的信息。在CasperJS中分割测试文件 - 与它的逻辑挣扎
我有三个使用--pre,--post和--include命令包含的脚本(安装程序,函数,清理)。当我单独运行我的每一个测试文件,它的伟大工程:
casperjs test tests/tables.js --includes=tests/phantomcss-functions.js --post=tests/phantomcss-cleanup.js --pre=tests/phantomcss-setup.js
... ...产生
Test file: tests/phantomcss-setup.js
Test file: tests/tables.js
Test file: tests/phantomcss-cleanup.js
PASS 1 test executed in 2.416s, 1 passed, 0 failed, 0 dubious, 0 skipped.
当我尝试对整个目录中运行CapserJS,不过,这不是“T相当失败 - 它只是不工作,从 - 事先步到--post跳步不经过任何在目录中的文件走:
Test file: tests/phantomcss-setup.js
Test file: tests/phantomcss-cleanup.js
没有及格,没有失败。只是。我完全丧失了。调试输出中没有任何内容。我已经包含了下面的脚本输出。如果有人想知道下一步该做什么,我很乐意听到它!
phantomcss-functions.js:
var phantomcss = require('../node_modules/phantomcss/phantomcss.js');
function fileNameGetter(root,filename){ ... }
phantomcss.init({
fileNameGetter: fileNameGetter
});
phantomcss-setup.js:
casper.start();
casper.viewport(1024, 768);
casper.test.done();
phantomcss-cleanup.js
casper.then(function now_check_the_screenshots(){
phantomcss.compareAll();
});
casper.then(function end_it(){
casper.test.done();
});
casper.run(function(){
phantom.exit(phantomcss.getExitStatus());
});
tables.js(测试文件样本)
casper.thenOpen('http://127.0.0.1:5000/prototypes/page-product-basic.html');
casper.then(function(){
phantomcss.screenshot('table.attribute-table:first-of-type', 'Table - Attribute');
});
casper.test.done();