Class SingltonBrowserImage


  • public class SingltonBrowserImage
    extends Object
    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.
    • Constructor Detail

      • SingltonBrowserImage

        public SingltonBrowserImage​(Path el)
        Parameters:
        el - The element the represents the image we are interested in
    • Method Detail

      • captureToFile

        public void captureToFile​(File outputFile)
        Capture the image of an element as a png, and save it to the given file
        Parameters:
        outputFile - - output file
      • captureImgSourceToFile

        public void captureImgSourceToFile​(File outputFile)
        Capture the source of an img element as a png, and save it to the given file
        Parameters:
        outputFile - - output file
      • 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
      • show

        public void show()
        Display the element image in a separate window. This is useful for troubleshooting/development. Note that this will not work well if you do it inside a debugger evaluation.
      • showCanvas

        public void showCanvas()
        Similar to show(), but optimized for an HTML5 canvas element
      • assertImageIsEqualToExpected

        public void assertImageIsEqualToExpected​(InputStream expectedImageInput)
                                          throws IOException
        Verify that the element's image is pixel-perfect
        Parameters:
        expectedImageInput - - reference png image
        Throws:
        IOException - - file could not be read
      • assertCanvasImageIsEqualToExpected

        public void assertCanvasImageIsEqualToExpected​(InputStream expectedImageInput)
                                                throws IOException
        Verify that the canvas image is pixel-perfect
        Parameters:
        expectedImageInput - - reference png image
        Throws:
        IOException - - file could not be read
      • assertImgSourceIsEqualToExpected

        public void assertImgSourceIsEqualToExpected​(InputStream expectedImageInput)
                                              throws IOException
        Verify that the HTML img source is pixel-perfect
        Parameters:
        expectedImageInput - - reference png image
        Throws:
        IOException - - file could not be read
      • getErrorImage

        public Optional<BufferedImage> getErrorImage​(InputStream expectedImageInput)
                                              throws IOException
        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
        Returns:
        an image that highlights the different pixels. If the images are equal, returns an empty optional.
        Throws:
        IOException - - file could not be read
        AssertionError - - images are not the same size
      • assertImageIsEqualToExpectedWithShiftAndCrop

        public void assertImageIsEqualToExpectedWithShiftAndCrop​(InputStream expectedImageInput,
                                                                 int maxShift)
                                                          throws IOException
        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
      • assertImageIsSimilarToExpected

        public void assertImageIsSimilarToExpected​(InputStream expectedImageInput,
                                                   int maxBadPixelsRatio)
                                            throws IOException
        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
      • assertImageIsSimilarToExpectedWithShift

        public void assertImageIsSimilarToExpectedWithShift​(InputStream expectedImageInput,
                                                            int maxBadPixelsRatio,
                                                            int maxShift)
                                                     throws IOException
        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.
        maxShift - - max shift allowed
        Throws:
        IOException - - file could not be read
      • assertImageIsSimilarToExpectedWithFilter

        public void assertImageIsSimilarToExpectedWithFilter​(InputStream filterImageInput,
                                                             InputStream expectedImageInput,
                                                             int maxBadPixelsRatio)
                                                      throws IOException
        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:
        filterImageInput - - filter image
        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