微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 在CasperJS中拆分测试文件 – 挣扎于它的逻辑

正如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();

解决方法

我需要研究原因,但似乎“测试”文件不能与pre / post / include文件存在于同一目录中.一旦我将测试文件隔离到他们自己的“测试”目录中,它就开始正常工作了.

我想,有时你只需要提出问题就可以提出另一件事.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐