gpt4 book ai didi

javascript - 在 CasperJS 中拆分测试文件——与它的逻辑作斗争

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:32:03 31 4
gpt4 key购买 nike

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

最佳答案

我需要研究原因,但“测试”文件似乎不能与前/后/包含文件位于同一目录中。一旦我将测试文件隔离到它们自己的“测试”目录中,它就开始正常工作了。

我猜,有时您只需要提出问题就可以想出另一件事来尝试。

关于javascript - 在 CasperJS 中拆分测试文件——与它的逻辑作斗争,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569698/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com