Skip to content

checkVisualDifferences

Philipp Stracker edited this page Aug 12, 2021 · 5 revisions
checkVisualDifferences(imageName[, options])

Compares the specified current image with an expected base image. If both images match, the test passes. If there are (too many) differences, the test fails.

For the test, there must be an image with the specified name inside the dirActual folder (usually output/) and dirExpected folder (usually screenshots/base/). Both images can be generated using the takeScreenshot() method.

Tip: The method signature and comparison behavior is identical to getVisualDifferences()

Parameters

imageName

Name of an existing image. The .png extension is optional. An image with that filename must exist inside the dirActual folder, and the dirExpected folder.

options

Optional. Custom comparison options for this check. If no options are defined, the defaults from the helper configuration are used.

Here is a list of all options.

Returns

When the test passes, the method returns a Promise that resolves to the comparison results. The results object contains the following attributes:

  • match (boolean) - Always true.
  • diffImage (string) - Always empty.
  • 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.

Samples

// Simple test.
await I.checkVisualDifferences("dashboard");
I.say(`Dashboard looks good!`);

// Use return values (only present, when the test passes).
await I.checkVisualDifferences("dashboard");
I.say(`Dashboard looks good!`);
Clone this wiki locally