Search in sources :

Example 1 with PixelMatcherRgb

use of org.testfx.service.support.impl.PixelMatcherRgb in project JavaFXLibrary by eficode.

the class Verifiers method imagesShouldNotMatch.

@RobotKeyword("Fails if images are too similar\n\n" + "``image1`` is an _Object:Image_ for the first comparable image.\n\n" + "``image2`` is an _Object:Image_ for the second comparable image.\n\n" + "``percentage`` the percentage of pixels that should not match, defaults to 100.\n\n" + "This keyword can be coupled with e.g. `Capture Image` -keyword.")
@ArgumentNames({ "image1", "image2", "percentage=100" })
public void imagesShouldNotMatch(Image image1, Image image2, double percentage) {
    robotLog("INFO", "Checking if " + percentage + "% of " + image1 + " differs with " + image2);
    if (image1.getHeight() != image2.getHeight() || image1.getWidth() != image2.getWidth())
        throw new JavaFXLibraryNonFatalException("Images must be same size to compare: Image1 is " + (int) image1.getWidth() + "x" + (int) image1.getHeight() + " and Image2 is " + (int) image2.getWidth() + "x" + (int) image2.getHeight());
    PixelMatcherResult result = robotContext.getCaptureSupport().matchImages(image1, image2, new PixelMatcherRgb());
    int nonSharedPixels = (int) (result.getNonMatchFactor() * 100);
    robotLog("INFO", "Matching pixels: " + nonSharedPixels + "%");
    if (nonSharedPixels < percentage)
        throw new JavaFXLibraryNonFatalException("Images are too similar - Expected at least " + (int) percentage + "% " + "difference, got " + nonSharedPixels + "%");
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PixelMatcherResult(org.testfx.service.support.PixelMatcherResult) PixelMatcherRgb(org.testfx.service.support.impl.PixelMatcherRgb)

Example 2 with PixelMatcherRgb

use of org.testfx.service.support.impl.PixelMatcherRgb in project JavaFXLibrary by eficode.

the class Verifiers method imagesShouldMatch.

@RobotKeyword("Fails if images are not similar enough\n\n" + "``image1`` is an _Object:Image_ for the first comparable image.\n\n" + "``image2`` is an _Object:Image_ for the second comparable image.\n\n" + "``percentage`` the percentage of pixels that should match, defaults to 100.\n\n" + "This keyword can be coupled with e.g. `Capture Image` -keyword.")
@ArgumentNames({ "image1", "image2", "percentage=100" })
public void imagesShouldMatch(Image image1, Image image2, double percentage) {
    robotLog("INFO", "Checking if " + percentage + "% of " + image1 + " matches with " + image2);
    if (image1.getHeight() != image2.getHeight() || image1.getWidth() != image2.getWidth())
        throw new JavaFXLibraryNonFatalException("Images must be same size to compare: Image1 is " + (int) image1.getWidth() + "x" + (int) image1.getHeight() + " and Image2 is " + (int) image2.getWidth() + "x" + (int) image2.getHeight());
    PixelMatcherResult result = robotContext.getCaptureSupport().matchImages(image1, image2, new PixelMatcherRgb());
    int sharedPixels = (int) (result.getMatchFactor() * 100);
    robotLog("INFO", "Matching pixels: " + sharedPixels + "%");
    if (sharedPixels < percentage)
        throw new JavaFXLibraryNonFatalException("Images do not match - Expected at least " + (int) percentage + "% " + "similarity, got " + sharedPixels + "%");
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PixelMatcherResult(org.testfx.service.support.PixelMatcherResult) PixelMatcherRgb(org.testfx.service.support.impl.PixelMatcherRgb)

Aggregations

JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)2 PixelMatcherResult (org.testfx.service.support.PixelMatcherResult)2 PixelMatcherRgb (org.testfx.service.support.impl.PixelMatcherRgb)2