Images

public class Images

Fields

logger

static Logger logger

Methods

assertCanvasImageIsEqualToExpected

public static void assertCanvasImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)

Verify that the element’s image is pixel-perfect

Parameters:
  • browser
    • browser
  • el
    • canvas to capture and verify
  • expectedImageInput – reference image file
Throws:
  • IOException
    • file could not be read

assertHTMLImgSoureIsEqualToExpected

public static void assertHTMLImgSoureIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)

Verify that an image downloaded from an HTML img src attribute, is pixel-perfect

Parameters:
  • browser
    • browser
  • el
    • HTML img element to capture and verify
  • expectedImageInput – reference image file
Throws:
  • IOException
    • file could not be read

assertImageIsEqualToExpected

public static void assertImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)

Verify that the element’s image is pixel-perfect

Parameters:
  • browser
    • browser
  • el
    • element to capture and verify
  • expectedImageInput – reference image file
Throws:
  • IOException
    • file could not be read

assertImageIsEqualToExpectedWithShiftAndCrop

public static void assertImageIsEqualToExpectedWithShiftAndCrop(InBrowser browser, Path el, InputStream expectedImageInput, int maxShift)

Verify that the element’s image is pixel-perfect, but allowing some crop/shift

Parameters:
  • browser
    • browser
  • el
    • element to capture and verify
  • expectedImageInput – reference image file
  • maxShift – maximum pixels the images are shifted/cropped compared to each other (both on x and y axis)
Throws:
  • IOException
    • file could not be read

assertImageIsSimilarToExpected

public static void assertImageIsSimilarToExpected(InBrowser browser, Path el, InputStream expectedImageInput, int maxBadPixelsRatio)

Verify the picture is “similar” to the reference image. Ignores minor differences between the pixels.

Parameters:
  • browser
    • browser
  • el
    • element to capture and validate
  • expectedImageInput
    • reference image
  • maxBadPixelsRatio
    • a positive number. For example: If it’s 100, then 1% of the pixels can have major differences compared to the reference.
Throws:
  • IOException
    • image file could not be read

captureCanvas

public static BufferedImage captureCanvas(InBrowser browser, Path canvas)

captureCanvasToFile

public static void captureCanvasToFile(InBrowser browser, Path el, File outputFile)

Save an HTML5 canvas to file. Optimized for canvas. Will fail if the element is not a canvas.

Parameters:
  • browser
    • browser
  • el
    • Path element to capture
  • outputFile
    • output file

captureImgSrcToFile

public static void captureImgSrcToFile(InBrowser browser, Path imgEl, File outputFile)

Save the source of an HTML img element to file

Parameters:
  • browser
    • browser
  • imgEl
    • HTML img element to capture
  • outputFile
    • output file

captureToFile

public static void captureToFile(InBrowser browser, Path el, File outputFile)

Save image to file

Parameters:
  • browser
    • browser
  • el
    • Path element to capture
  • outputFile
    • output file

getErrorsImage

public static Optional<BufferedImage> getErrorsImage(InBrowser browser, Path el, InputStream expectedImageInput)

create and return an image that highlights the different pixels between the captured image and the reference image

Parameters:
  • browser
    • browser
  • el
    • element to capture and verify
  • expectedImageInput – reference image file
Throws:
  • IOException
    • file could not be read
  • AssertionError
    • images are not the same size
Returns:

an image that highlights the different pixels. If the images are equal, returns an empty optional.

show

public static void show(InBrowser browser, Path el)

Display image of an element in a separate window. Does not work as an evaluation within the debugger.

Parameters:
  • browser
    • browser
  • el
    • the element to capture and display

showCanvas

public static void showCanvas(InBrowser browser, Path el)

Display image of an HTML5 canvas element in a separate window. Does not work as an evaluation within the debugger.

Parameters:
  • browser
    • browser
  • el
    • the element to capture and display

showImage

static void showImage(BufferedImage image)