2014-08-29 28 views
4

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

回答

1

我需要找出原因,但現在看來,「測試」文件不能住在同一目錄前/發佈/包含文件。一旦我將測試文件分離到他們自己的「測試」目錄中,它就開始正常工作。

我猜,有時候你只需要提出這個問題就可以想出另一個嘗試。