Skip to content

Comparison Results

Philipp Stracker edited this page Aug 13, 2021 · 5 revisions

Both methods checkVisualDifferences() and getVisualDifferences() return a Promise that resolves to the following "comparison results" object:

match

(boolean) - Whether the differences are within the allowed tolerance level.

diffImage

(string) - Filename of the diff-file.

diffPixels

(int) - Absolute count of different pixels.

totalPixels

(int) - Absolute count of all pixels inside the image.

relevantPixels

(int) - Absolute count of pixels, that are not ignored and inside the bounds-area.

difference

(float) - Relative difference between both images. The percentage is calculated from the diffPixels and relevantPixels values.

variation

(string) - Stores the variation-suffix of the match. Only used, when multiple base images are present for the comparison.

variations

(Array of Comparison Results) - Contains details about all variations. Only used, when multiple base images are present for the comparison.

Sample

const res = await I.getVisualDifferences("dashboard");

console.log('Match: ', res.match);
console.log('Diff-Image: ', res.diffImage);
console.log('Diff Pixels: ', res.diffPixels);
console.log('Total Pixels: ', res.totalPixels);
console.log('Relevant Pixels: ', res.relevantPixels);
console.log('Difference: ', res.difference);

Notes

When running a test using multiple base images, then the comparison result object contains details about the best match. That is the match with the least amount of different pixels.

You can still analyze all comparison results by inspecting the variations property of the result object.

Sample

const res = await I.getVisualDifferences("dashboard");

console.log(`Variations tested: ${res.variations.length}`);
for (let i = 0; i < res.variations.length; i++) {
    const v = res.variations[i];
    console.log(`Variation ${i} has suffix "${v.variation} and difference of ${v.diffPixels} Pixels`);
}

← Comparison Options | Samples →