1

I'm writing a test script with PhantomCSS but I'm running into an error. I've already run my script one time and I created the baseline screenshots. Now, when I try to run through it again, it creates the .diff.png images, but then throws the error:

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.

I commented out most of my phantomcss.init() code, but this is what I have left:

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

EDIT: Line 426 from phantomcss.js is:

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);
.....
Jordan Plahn
  • 375
  • 4
  • 12

3 Answers3

2

Found the problem. If you have installed it with NPM you have to specify the libraryRoot

var phantomcss = require('../node_modules/phantomcss/phantomcss.js');

phantomcss.init({
  libraryRoot: 'node_modules/phantomcss',
});
Alex Palcuie
  • 4,434
  • 3
  • 22
  • 27
  • This fixed the issue I was having. The demo they have in their repo would look like: ```libraryRoot: fs.absolute( fs.workingDirectory + '/node_modules/phantomcss' )``` – CraigColes Jan 28 '16 at 14:49
0

Actually, I found that phantomCss would raise this exception if your screenshots directory was missing.

This can be specified as follows:

phantomcss.init({
    screenshotRoot: './spec/phantomcss/screenshots',
    failedComparisonsRoot: './spec/phantomcss/failures',
    comparisonResultRoot: './spec/phantomcss/results'
});
pbanka
  • 716
  • 1
  • 8
  • 20
0

This error was generated because of phantomcss.turnOffAnimations(). I removed it.

Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110