3

尝试将我的视觉回归测试添加到 grunt。我按照此处提供的教程进行操作。但看起来有什么不对劲。

这是我的 gruntfile:

    phantomcss: {
        desktop: {
            options: {
                screenshots: 'tests/visual-regression/screenshots/baseline',
                results: 'tests/visual-regression/screenshots/results',
                viewportSize: [1280, 1024]
            },
            src: ['test/visual-regression/**/*_spec.js']
        },

        mobile: {
            options: {
                screenshots: 'tests/visual-regression/screenshots/baseline',
                results: 'tests/visual-regression/screenshots/results',
                viewportSize: [320, 480]
            },
            src: ['test/visual-regression/**/*_spec.js']
        }
    }
});

grunt.loadNpmTasks('grunt-phantomcss');

grunt.registerTask('test', ['phantomcss']);

这是我的规范文件的一部分。进行 casperjs 测试 tests/meu_spec.js 非常好。

casper.start( targetUrl );

//casper.viewport(1280, 1024);

casper.then( login ) ;

casper.wait( 20000,function() {} );

casper.then( function user_info (){
    phantomcss.screenshot('#slide-out > div.user.col.s12', 'user');
})


[...]



casper.then( function now_check_the_screenshots (){
    phantomcss.compareAll();
});

casper.then( function end_it (){
    casper.test.done();
});

casper.run( function () {
    console.log('\nTHE END.');
    phantom.exit(phantomcss.getExitStatus());
});

然后,运行grunt test我得到了这个:

andre@testware:~/workspace/meu-psafe$ grunt test
Running "phantomcss:desktop" (phantomcss) task
CasperError: Casper is not started, can't execute `then()`                      
  /home/andre/workspace/meu-psafe/node_modules/grunt-    phantomcss/bower_components/phantomcss/CasperJs/modules/casper.js:396 in     checkStarted
  /home/andre/workspace/meu-psafe/node_modules/grunt-    phantomcss/bower_components/phantomcss/CasperJs/modules/casper.js:1685 in then
  /home/andre/workspace/meu-psafe/node_modules/grunt-    phantomcss/phantomjs/runner.js:58
Warning:  Use --force to continue.

Aborted due to warnings.
4

0 回答 0