Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #949 from gemini-testing/diff-bounds
Browse files Browse the repository at this point in the history
feat: pass diff bounds to error from looks-same
  • Loading branch information
rostik404 committed Dec 26, 2018
2 parents 86624ce + bdb3aab commit 5c89c0f
Show file tree
Hide file tree
Showing 8 changed files with 2,446 additions and 2,686 deletions.
8 changes: 7 additions & 1 deletion doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ desiredCapabilities:
commonThing: value
calibrate: false
tolerance: 3.5
antialiasingTolerance: 0
antialiasingTolerance: 0,
compareOpts:
stopOnFirstFail: true
httpTimeout: 5000
sessionRequestTimeout: 60000
sessionQuitTimeout: 5000
Expand Down Expand Up @@ -213,6 +215,10 @@ Settings list:

* `antialiasingTolerance` — read about this option in [looks-same](https://github.com/gemini-testing/looks-same#comparing-images-with-ignoring-antialiasing).

* `compareOpts` — extra options for images comparing. It's an Object with following fields:
* `[stopOnFirstFail] {Boolean}` Only first pixel will be found if this option is true
See [looks-same](https://github.com/gemini-testing/looks-same#comparing-images) documentation for the list of options.

* `windowSize` — specify browser window dimensions (i.e. `1600x1200`). If not
specified, the size of the window depends on WebDriver. :warning: You can't set specific resolutions for browser Opera or mobile platforms. They use only full-screen resolution.

Expand Down
12 changes: 12 additions & 0 deletions lib/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const getTopLevel = () => {
screenshotsDir: 'gemini/screens',
tolerance: 2.3,
antialiasingTolerance: 0,
compareOpts: {stopOnFirstFail: false},
sessionsPerBrowser: 1,
suitesPerSession: Infinity,
windowSize: null,
Expand Down Expand Up @@ -228,6 +229,17 @@ function buildBrowserOptions(defaultFactory, extra) {

compositeImage: booleanOption(defaultFactory('compositeImage')),

compareOpts: option({
defaultValue: defaultFactory('compareOpts'),
parseEnv: JSON.parse,
parseCli: JSON.parse,
validate: (value) => {
if (!isOptionalObject(value)) {
throw new GeminiError('CompareOpts should be object');
}
}
}),

orientation: option({
defaultValue: defaultFactory('orientation'),
validate: (value) => {
Expand Down
13 changes: 7 additions & 6 deletions lib/state-processor/capture-processor/capture-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ module.exports = class CaptureProcessor {
_compareImages(capture, opts) {
const {refImg} = opts;
const currImg = {path: temp.path({suffix: '.png'}), size: capture.image.getSize()};
const compareOpts = {
const imageCompareOpts = {
canHaveCaret: capture.canHaveCaret,
pixelRatio: opts.pixelRatio,
tolerance: opts.tolerance,
antialiasingTolerance: opts.antialiasingTolerance
antialiasingTolerance: opts.antialiasingTolerance,
compareOpts: opts.compareOpts
};

return capture.image.save(currImg.path)
.then(() => Image.compare(currImg.path, refImg.path, compareOpts))
.then((isEqual) => {
return isEqual
.then(() => Image.compare(currImg.path, refImg.path, imageCompareOpts))
.then(({equal, diffBounds}) => {
return equal
? this._onEqualHandler(refImg, currImg)
: this._onDiffHandler(refImg, currImg);
: this._onDiffHandler(refImg, currImg, diffBounds);
});
}
};
2 changes: 1 addition & 1 deletion lib/state-processor/capture-processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.create = (type) => {
.onReference()
.onNoReference(throwNoRefError)
.onEqual((refImg, currImg) => ({refImg, currImg, equal: true}))
.onDiff((refImg, currImg) => ({refImg, currImg, equal: false}));
.onDiff((refImg, currImg, diffBounds) => ({refImg, currImg, diffBounds, equal: false}));
}

if (type === 'new-updater') {
Expand Down
3 changes: 2 additions & 1 deletion lib/state-processor/state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module.exports = class StateProcessor {
refImg: {path: browserConfig.getScreenshotPath(state.suite, state.name), size: null},
pixelRatio: page.pixelRatio,
antialiasingTolerance: browserConfig.antialiasingTolerance,
tolerance
tolerance,
compareOpts: browserConfig.compareOpts
},
temp: temp.serialize()
};
Expand Down

0 comments on commit 5c89c0f

Please sign in to comment.