Interface TestScreenshotComparisonOptions
- All Superinterfaces:
TestScreenshotCommonOptions<TestScreenshotComparisonOptions>
By default, screenshots are compared with a fuzzy comparison which allows screenshots to be 0.5% different from
the template image. See TestScreenshotComparisonAlgorithm.defaultAlgorithm()
for details on how this is
implemented. To change the threshold for how different the screenshot can be, set the algorithm to
TestScreenshotComparisonAlgorithm.meanSquaredDifference(float)
. To force the screenshot to be exactly the
same as your template, use TestScreenshotComparisonAlgorithm.exact()
. It is recommended to stick with fuzzy
matching unless you specifically require an exact match, because the exact screenshot can vary slightly on different
frames and in rare cases other factors such as the GPU/driver version.
Template images must be fully opaque, this API will throw if the template image has any transparent pixels.
Template images loaded from a path are expected to be in the templates
directory inside the resources
directory of the mod which registered the gametest. If the template image is not found then the screenshot will be
saved to the templates
directory so that it can be used next time the gametest is run. Your test mod's
resources directory is in the fabric.client.gametest.testModResourcesPath
system property which is set by
Loom by default. You may set this system property to override the location of the test mod resources directory. If
this system property is unset and the template image is not found, then the test will fail.
-
Method Summary
Modifier and TypeMethodDescriptionLoad the template image from a path.of
(NativeImage templateImage) Use the given image as the template image.saveWithFileName
(String fileName) Additionally save the screenshot which was compared against.withAlgorithm
(TestScreenshotComparisonAlgorithm algorithm) Changes the algorithm used to compare the template image with the screenshot.Compares images in grayscale rather than in color.withRegion
(int x, int y, int width, int height) Only considers a certain region of the screenshot for comparison.Methods inherited from interface net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotCommonOptions
disableCounterPrefix, withDestinationDir, withSize, withTickDelta
-
Method Details
-
of
Load the template image from a path. The template image is expected to be in thetemplates
directory inside the resources directory of the mod which registered the gametest.- Parameters:
templateImage
- The template image path- Returns:
- The new screenshot comparison options instance
-
of
Use the given image as the template image.- Parameters:
templateImage
- The template image- Returns:
- The new screenshot comparison options instance
-
saveWithFileName
Additionally save the screenshot which was compared against. This method works as if by callingClientGameTestContext.takeScreenshot(TestScreenshotOptions)
with these screenshot options, except that the screenshot saved is from the same render of the game as the one that is compared against in this screenshot comparison.- Parameters:
fileName
- The name of the screenshot to save- Returns:
- This screenshot comparison options instance
-
withAlgorithm
Changes the algorithm used to compare the template image with the screenshot. See class documentation for details.- Parameters:
algorithm
- The new algorithm- Returns:
- This screenshot comparison options instance
-
withGrayscale
TestScreenshotComparisonOptions withGrayscale()Compares images in grayscale rather than in color. Comparing in grayscale is typically faster but has the obvious disadvantage of two colors with different hues but the same brightness being treated as the same.- Returns:
- This screenshot comparison options instance
-
withRegion
Only considers a certain region of the screenshot for comparison. When used withassertScreenshotEquals
, asserts that the template image is equal to the given region of the screenshot. When used withassertScreenshotContains
, asserts that the template image is contained within the given region of the screenshot.- Parameters:
x
- The minimum X position in the regiony
- The minimum Y position in the regionwidth
- The width of the regionheight
- The height of the region- Returns:
- This screenshot comparison options instance
-