zinserjan / wdio-visual-regression-service

Visual regression service for WebdriverIO.
MIT License
102 stars 39 forks source link

More consistent API #15

Closed monolithed closed 8 years ago

monolithed commented 8 years ago

Actual

/test.js

browser.saveDocumentScreenshot('file.png', options);
browser.checkDocument(options)

/config.js

{
    visualRegression: {
        compare: new VisualRegressionCompare.LocalCompare({
            referenceName : screenshot('/expected/file.png'),
            screenshotName: screenshot('/actual/file.png'),
            diffName      : screenshot('/diff/file.png')
        })
    }
}

Expected

1

let file = 'file.png';

let options = { 
     output: {
         actual: '/actual',
         expected: '/expected',
         diff: '/diff'
     } 
};

browser.saveDocumentScreenshot(file, options);
browser.checkDocument(file, options)
2
let file = 'file.png';

let options = { 
     output: {
          actual ({ test }) {
               return path.join('/actual', test, 'file.png');
          },

          expected ({ test }) {
               return path.join('/expected', test, 'file.png');
          }

           diff ({ test }) {
               return path.join('/diff', test, 'file.png');
          }
     } 
};

browser.saveDocumentScreenshot(options);
browser.checkDocument(options);

The second variant is more universal

zinserjan commented 8 years ago

What do you mean with consistent API?

wdio-screenshot has nothing to do with this library. It's just an internally used lib. What confuses me, that you use both libraries in your test.js. For regression testing it's just enough to use this library. There is no need to save screenshots before checking them. So your test.js should just look like

browser.checkDocument(options)

Expected

1

let file = 'file.png';

let options = { 
     output: {
         actual: '/actual',
         expected: '/expected',
         diff: '/diff'
     } 
};

browser.checkDocument(file, options)

Prodiving a file parameter does not make any sense for this library. I build this with the idea that it is easily extendable with a plugin system for comparison methods. You can build your own screenshot method and pass a filename into the options to build the file path. Have a look into LocalCompare.js as a base to build something that satisfies your expectations.

monolithed commented 8 years ago

There is no need to save screenshots before checking them.

Oh, I got it, thanks!