我正在使用 PhantomCSS 编写测试脚本,但遇到了错误。我已经运行了一次我的脚本并创建了基线屏幕截图。现在,当我尝试再次运行它时,它会创建 .diff.png 图像,但随后会引发错误:
TypeError: 'undefined' is not an object (evaluating 'test.success')
/path/to/phantomcss.js:426
FAIL TypeError: 'undefined' is not an object (evaluating 'test.success')
# type: error
# file: visual.js
# subject: false
# error: "TypeError: 'undefined' is not an object (evaluating 'test.success')"
# stack: in anonymous() in /path/to/phantomcss.js:426
FAIL 1 test executed in 4.035s, 0 passed, 1 failed, 0 dubious, 0 skipped.
我注释掉了我的大部分 phantomcss.init() 代码,但这是我留下的:
var phantomcss = require('/path/to/phantomcss.js');
phantomcss.init({
failedComparisonRoot: './diffs'
});
casper.start(url);
casper.viewport(1024, 768);
casper.then(function() {
casper.wait(2500, function() {
phantomcss.screenshot('#app-bar', 'App_bar_initial');
phantomcss.screenshot('.selected', 'Selected_Menu_Initial');
});
});
casper.then(function() {
phantomcss.compareAll();
})
casper.then(function() {
casper.test.done();
})
casper.run(function() {
phantom.exit(phantomcss.getExitStatus());
});
编辑:phantomcss.js的第 426 行是:
function waitForTests(tests){
casper.then(function(){
casper.waitFor(function(){
return tests.length === tests.reduce(function(count, test){
if (test.success || test.fail || test.error) {
return count + 1;
} else {
return count;
}
}, 0);
.....