测试图像是否加载了casperjs

时间:2014-11-04 05:52:46

标签: javascript testing casperjs

我正在尝试使用casperjs测试图像是否正确加载到页面上。我正在使用这种方法 - http://vgaltes.com/index.php/2013/03/16/testing-with-casperjs-part-2/,所以在我的脚本中我有类似

的东西
casper.on('resource.received', function(resource) {        //checks if images are loaded
      var status = resource.status;
      if(status >= 400) {
         casper.log('Resource ' + resource.url + ' failed to load (' + status + ')', 'error');
         resourceErrors.push({
             url: resource.url,
             status: resource.status
         });
      }
});

它适用于某些页面,但有时我会收到错误(虽然在浏览器中页面看起来非常好):

FAIL ReferenceError: Can't find variable: resourceErrors
#    type: uncaughtError
#    file: ./test_new.js:120
#    error: Can't find variable: resourceErrors
#           ReferenceError: Can't find variable: resourceErrors
#               at ./test_new.js:120
#               at emit (/home/test/casperjs/modules/events.js:80)
#               at onResourceReceived (/home/test/casperjs/modules/casper.js:2594)
#    stack: not provided

任何想法导致此错误的原因是什么?

由于

0 个答案:

没有答案