正如Stack的许多其他人正在努力解决的那样,我正试图将我的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时,它并没有完全失败 – 它只是不起作用,从–pre步骤跳转到–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();