SingltonBrowserImage¶
-
public class
SingltonBrowserImage
¶ Capturing and asserting the image (screenshot) of a Path element. It supports both canvas and a standard element image. It supports both accurate and fuzzy assertion. It provides utility functions to display an element in a separate window.
Constructors¶
Methods¶
assertCanvasImageIsEqualToExpected¶
-
public void
assertCanvasImageIsEqualToExpected
(InputStream expectedImageInput)¶ Verify that the canvas image is pixel-perfect
Parameters: - expectedImageInput –
- reference png image
Throws: - IOException –
- file could not be read
- expectedImageInput –
assertImageIsEqualToExpected¶
-
public void
assertImageIsEqualToExpected
(InputStream expectedImageInput)¶ Verify that the element’s image is pixel-perfect
Parameters: - expectedImageInput –
- reference png image
Throws: - IOException –
- file could not be read
- expectedImageInput –
assertImageIsEqualToExpectedWithShiftAndCrop¶
-
public void
assertImageIsEqualToExpectedWithShiftAndCrop
(InputStream expectedImageInput, int maxShift)¶ Verify that the element’s image is pixel-perfect, but allowing one to be a cropped/shifted version of the other.
Parameters: - expectedImageInput –
- reference png image
- maxShift – maximum pixels the images are shifted/cropped compared to each other
Throws: - IOException –
- file could not be read
- expectedImageInput –
assertImageIsSimilarToExpected¶
-
public void
assertImageIsSimilarToExpected
(InputStream expectedImageInput, int maxBadPixelsRatio)¶ Verify the picture is “similar” to the reference image. Ignores minor differences between the pixels. Does not identify offsets and rotation. It uses a VERY simplistic approach (no wavelets or any other transform).
Parameters: - expectedImageInput –
- reference png 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 –
- file could not be read
- expectedImageInput –
assertImgSourceIsEqualToExpected¶
-
public void
assertImgSourceIsEqualToExpected
(InputStream expectedImageInput)¶ Verify that the HTML img source is pixel-perfect
Parameters: - expectedImageInput –
- reference png image
Throws: - IOException –
- file could not be read
- expectedImageInput –
captureCanvasToFile¶
-
public void
captureCanvasToFile
(File outputFile)¶ Capture the image of an HTML5 canvas as a png, and save it to the given file. If the element given is not a canvas, this will fail. Note that it is more optimized - it downloads only the section of the canvas as an image.
Parameters: - outputFile –
- output file
- outputFile –
captureImgSourceToFile¶
captureToFile¶
getErrorImage¶
-
public Optional<BufferedImage>
getErrorImage
(InputStream expectedImageInput)¶ compare captured image to a reference image and return an image that highlights the differences. Both images are expected to have the same dimensions, otherwise it throws in AssertionError.
Parameters: - expectedImageInput –
- reference png image
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.
- expectedImageInput –