4

Stack の他の多くの人が苦労しているように、私は CasperJS テストを複数のファイルに分割しようとしています。ドキュメントを読んで、ここで回答をクロールするのに 3 日間費やしましたが、役立つものは何も見つからないようです。

--pre、--post、および --include コマンドを使用して含める 3 つのスクリプト (セットアップ、関数、クリーンアップ) があります。各テスト ファイルを個別に実行すると、うまく機能します。

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

ファントムcss-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();
4

1 に答える 1