HuddleEng / PhantomCSS

Visual/CSS regression testing with PhantomJS
MIT License
4.72k stars 259 forks source link

Duplicate screenshots #110

Open chris-dura opened 9 years ago

chris-dura commented 9 years ago

I'm trying to organize screenshots into separate sub-directories to make managing them easier. So, I have three simple test files that just open a URL and take a screenshot. The only code differences in the tests is the url being opened and the screenshotRoot and failedComparisonsRoot because I'm trying to organize the screenshots into sub-directories.

tests/
├── test1.js
├── test2.js
└── test3.js
// test1.js

var fs = require('fs'),
    phantomcss = require(fs.absolute(fs.workingDirectory + '/node_modules/phantomcss/phantomcss.js'));

casper.test.begin("Test Suite Numero Uno", 1, function suite(test) {

    phantomcss.init({
        casper:                     casper,
        libraryRoot:                fs.absolute(fs.workingDirectory + '/node_modules/phantomcss'),
        screenshotRoot:             fs.absolute(fs.workingDirectory + '/screenshots/test1'),
        failedComparisonsRoot:      fs.absolute(fs.workingDirectory + '/failures/test1'),
        addLabelToFailedImage:      false,
        mismatchTolerance:          0.01,
        rebase:                     casper.cli.get('rebase')
    });

    casper.start('http://www.google.com');

    casper.viewport(1280, 800, function () {
        phantomcss.screenshot('body', 2000);
    });    

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

    casper.run(function () {
        console.log('\nTHE END.');
        // phantomcss.getExitStatus(); // pass or fail?
        test.done();
    });

});
// test2.js
...
        screenshotRoot:             fs.absolute(fs.workingDirectory + '/screenshots/test2'),
        failedComparisonsRoot:      fs.absolute(fs.workingDirectory + '/failures/test2'),
...
    casper.start('http://www.huddle.com');
// test3.js
...
        screenshotRoot:             fs.absolute(fs.workingDirectory + '/screenshots/test3'),
        failedComparisonsRoot:      fs.absolute(fs.workingDirectory + '/failures/test3'),
...
    casper.start('http://www.casperjs.org');

I would expect running casperjs test tests to end up with this screenshots organization...

screenshots/
├── test1/
|   ├── screenshot_0.png
├── test2/
|   └── screenshot_1.png
└── test3/
    └── screenshot_2.png

However, I end up with the screenshots taken in the second and third suites duplicated into the test1 directory.

screenshots/
├── test1/
|   ├── screenshot_0.png
|   ├── screenshot_1.png
|   └── screenshot_2.png
├── test2/
|   └── screenshot_1.png
└── test3/
    └── screenshot_2.png
jamescryer commented 9 years ago

This could be a bug.

Could you try setting comparisonResultRoot as well.

  screenshotRoot: fs.absolute(fs.workingDirectory + '/screenshots/test3'),
  comparisonResultRoot: fs.absolute(fs.workingDirectory + '/screenshots/test3'),
  failedComparisonsRoot: fs.absolute(fs.workingDirectory + '/failures/test3'),
chris-dura commented 9 years ago

Could you try setting comparisonResultRoot as well.

That did it.