Class Images
- java.lang.Object
-
- com.github.loyada.jdollarx.visual.Images
-
public class Images extends Object
-
-
Constructor Summary
Constructors Constructor Description Images()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertCanvasImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)
Verify that the element's image is pixel-perfectstatic void
assertHTMLImgSoureIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)
Verify that an image downloaded from an HTML img src attribute, is pixel-perfectstatic void
assertImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput)
Verify that the element's image is pixel-perfectstatic void
assertImageIsEqualToExpected(BufferedImage img, InputStream expectedImageInput)
Verify that the element's image is pixel-perfectstatic void
assertImageIsEqualToExpectedNoScaling(InBrowser browser, Path el, InputStream expectedImageInput)
Verify that the element's image is pixel-perfectstatic void
assertImageIsEqualToExpectedWithShiftAndCrop(InBrowser browser, Path el, InputStream expectedImageInput, int maxShift)
Verify that the element's image is pixel-perfect, but allowing some crop/shiftstatic void
assertImageIsSimilarToExpected(InBrowser browser, Path el, InputStream expectedImageInput, int maxBadPixelsRatio)
Verify the picture is "similar" to the reference image.static void
assertImageIsSimilarToExpectedWithFilter(InBrowser browser, Path el, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio)
Verify the picture is "similar" to the reference image.static void
assertImageIsSimilarToExpectedWithFilter(BufferedImage elementImage, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio)
Verify the picture is "similar" to the reference image.static void
assertImageIsSimilarToExpectedWithShift(InBrowser browser, Path el, InputStream expectedImageInput, int maxBadPixelsRatio, int maxShift)
Verify the picture is "similar" to the reference image.static void
assertWindowIsSimilarToExpected(InBrowser browser, InputStream expectedImageInput, int maxBadPixelsRatio)
Verify the picture is "similar" to the reference image.static void
assertWindowIsSimilarToExpectedWithFilter(InBrowser browser, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio)
Verify the picture is "similar" to the reference image.static BufferedImage
captureCanvas(InBrowser browser, Path canvas)
Capture a canvas DOM element to an image as a png.static void
captureCanvasToFile(InBrowser browser, Path el, File outputFile)
Save an HTML5 canvas to file.static BufferedImage
captureImage(InBrowser browser)
capture the image of the entire window in the browser and return the image objectstatic BufferedImage
captureImage(InBrowser browser, Path el)
capture the image of the element in the browser and return the image object.static BufferedImage
captureImageNoScaling(InBrowser browser, Path el)
Same as captureImage(), but will not autoscale back to the size as the browser "sees" it.static void
captureImgSrcToFile(InBrowser browser, Path imgEl, File outputFile)
Save the source of an HTML img element to filestatic void
captureToFile(InBrowser browser, Path el, File outputFile)
Save image to file, scaling the image to the size in the browserstatic void
captureToFile(InBrowser browser, File outputFile)
Save screenshot to file, scaling the image to the size in the browserstatic void
captureToFileNoScaling(InBrowser browser, Path el, File outputFile)
Save image to filestatic Map<String,Long>
getBrowserInnerDimensions(InBrowser browser)
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 imagestatic Optional<BufferedImage>
getFuzzyErrorImage(InBrowser browser, Path el, InputStream expectedImageInput)
create and return an image that highlights the different pixels between the captured image and the reference imagestatic Optional<BufferedImage>
getFuzzyErrorsImage(InBrowser browser, Path el, InputStream expectedImageInput)
create and return an image that highlights the different pixels between the captured image and the reference imagestatic Optional<BufferedImage>
getFuzzyErrorsImage(InputStream actualImageInput, InputStream expectedImageInput)
create and return an image that highlights the different pixels between the captured image and the reference imagestatic Map<String,Long>
getVisibleDimensions(InBrowser browser, Path path)
static BufferedImage
resize(BufferedImage img, long newW, long newH)
Resize an image to the wanted size.static void
show(InBrowser browser, Path el)
Display image of an element in a separate window.static void
showCanvas(InBrowser browser, Path el)
Display image of an HTML5 canvas element in a separate window.static void
showImage(BufferedImage image, String header)
Display an image on a JFrame
-
-
-
Method Detail
-
captureToFile
public static void captureToFile(InBrowser browser, Path el, File outputFile)
Save image to file, scaling the image to the size in the browser- Parameters:
browser
- - browserel
- - Path element to captureoutputFile
- - output file
-
captureToFileNoScaling
public static void captureToFileNoScaling(InBrowser browser, Path el, File outputFile)
Save image to file- Parameters:
browser
- - browserel
- - Path element to captureoutputFile
- - output file
-
captureToFile
public static void captureToFile(InBrowser browser, File outputFile)
Save screenshot to file, scaling the image to the size in the browser- Parameters:
browser
- - browseroutputFile
- - output file
-
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
- - browserel
- - Path element to captureoutputFile
- - 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
- - browserimgEl
- - HTML img element to captureoutputFile
- - output file
-
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
- - browserel
- - 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
- - browserel
- - the element to capture and display
-
assertHTMLImgSoureIsEqualToExpected
public static void assertHTMLImgSoureIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
Verify that an image downloaded from an HTML img src attribute, is pixel-perfect- Parameters:
browser
- - browserel
- - HTML img element to capture and verifyexpectedImageInput
- reference image file- Throws:
IOException
- - file could not be read
-
assertImageIsEqualToExpected
public static void assertImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
Verify that the element's image is pixel-perfect- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image file- Throws:
IOException
- - file could not be read
-
assertImageIsEqualToExpectedNoScaling
public static void assertImageIsEqualToExpectedNoScaling(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
Verify that the element's image is pixel-perfect- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image file- Throws:
IOException
- - file could not be read
-
assertImageIsEqualToExpected
public static void assertImageIsEqualToExpected(BufferedImage img, InputStream expectedImageInput) throws IOException
Verify that the element's image is pixel-perfect- Parameters:
img
- - an image to be validatedexpectedImageInput
- reference image file- Throws:
IOException
- - file could not be read
-
assertCanvasImageIsEqualToExpected
public static void assertCanvasImageIsEqualToExpected(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
Verify that the element's image is pixel-perfect- Parameters:
browser
- - browserel
- - canvas to capture and verifyexpectedImageInput
- reference image file- Throws:
IOException
- - file could not be read
-
getErrorsImage
public static Optional<BufferedImage> getErrorsImage(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
create and return an image that highlights the different pixels between the captured image and the reference image- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image file- Returns:
- an image that highlights the different pixels. If the images are equal, returns an empty optional.
- Throws:
IOException
- - file could not be readAssertionError
- - images are not the same size
-
getFuzzyErrorsImage
public static Optional<BufferedImage> getFuzzyErrorsImage(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
create and return an image that highlights the different pixels between the captured image and the reference image- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image file- Returns:
- an image that highlights the different pixels. If the images are equal, returns an empty optional.
- Throws:
IOException
- - file could not be readAssertionError
- - images are not the same size
-
getFuzzyErrorsImage
public static Optional<BufferedImage> getFuzzyErrorsImage(InputStream actualImageInput, InputStream expectedImageInput) throws IOException
create and return an image that highlights the different pixels between the captured image and the reference image- Parameters:
expectedImageInput
- reference image file- Returns:
- an image that highlights the different pixels. If the images are equal, returns an empty optional.
- Throws:
IOException
- - file could not be readAssertionError
- - images are not the same size
-
getFuzzyErrorImage
public static Optional<BufferedImage> getFuzzyErrorImage(InBrowser browser, Path el, InputStream expectedImageInput) throws IOException
create and return an image that highlights the different pixels between the captured image and the reference image- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image file- Returns:
- an image that highlights the different pixels. If the images are equal, returns an empty optional.
- Throws:
IOException
- - file could not be readAssertionError
- - images are not the same size
-
assertImageIsEqualToExpectedWithShiftAndCrop
public static void assertImageIsEqualToExpectedWithShiftAndCrop(InBrowser browser, Path el, InputStream expectedImageInput, int maxShift) throws IOException
Verify that the element's image is pixel-perfect, but allowing some crop/shift- Parameters:
browser
- - browserel
- - element to capture and verifyexpectedImageInput
- reference image filemaxShift
- 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) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
browser
- - browserel
- - element to capture and validateexpectedImageInput
- - reference imagemaxBadPixelsRatio
- - 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
-
assertWindowIsSimilarToExpected
public static void assertWindowIsSimilarToExpected(InBrowser browser, InputStream expectedImageInput, int maxBadPixelsRatio) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
expectedImageInput
- - reference imagemaxBadPixelsRatio
- - 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
-
assertImageIsSimilarToExpectedWithShift
public static void assertImageIsSimilarToExpectedWithShift(InBrowser browser, Path el, InputStream expectedImageInput, int maxBadPixelsRatio, int maxShift) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
browser
- - browserel
- - element to capture and validateexpectedImageInput
- - reference imagemaxBadPixelsRatio
- - 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
- - image file could not be read
-
assertImageIsSimilarToExpectedWithFilter
public static void assertImageIsSimilarToExpectedWithFilter(InBrowser browser, Path el, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
browser
- - browserel
- - element to capture and validateexpectedImageInput
- - reference imagefilterImageInput
- - image that filters interesting areasmaxBadPixelsRatio
- - 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
-
assertWindowIsSimilarToExpectedWithFilter
public static void assertWindowIsSimilarToExpectedWithFilter(InBrowser browser, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
browser
- - browserexpectedImageInput
- - reference imagefilterImageInput
- - image that filters interesting areasmaxBadPixelsRatio
- - 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
-
assertImageIsSimilarToExpectedWithFilter
public static void assertImageIsSimilarToExpectedWithFilter(BufferedImage elementImage, InputStream filterImageInput, InputStream expectedImageInput, int maxBadPixelsRatio) throws IOException
Verify the picture is "similar" to the reference image. Ignores minor differences between the pixels.- Parameters:
elementImage
- - actual imageexpectedImageInput
- - reference imagefilterImageInput
- - image that filters interesting areasmaxBadPixelsRatio
- - 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)
Capture a canvas DOM element to an image as a png. The reason for the special treatment for canvas is that capturing it as a raster image is much more efficient than a generic element.- Parameters:
browser
- - the browsercanvas
- - a Path to the canvas element- Returns:
- a raster image
-
showImage
public static void showImage(BufferedImage image, String header)
Display an image on a JFrame- Parameters:
image
- - the imageheader
- - display title
-
resize
public static BufferedImage resize(BufferedImage img, long newW, long newH)
Resize an image to the wanted size.- Parameters:
img
- the imagenewW
- new widthnewH
- new height- Returns:
- resized image
-
getVisibleDimensions
public static Map<String,Long> getVisibleDimensions(InBrowser browser, Path path)
-
getBrowserInnerDimensions
public static Map<String,Long> getBrowserInnerDimensions(InBrowser browser)
-
captureImage
public static BufferedImage captureImage(InBrowser browser, Path el)
capture the image of the element in the browser and return the image object. It requires the entire element to be visible, so if it is not, first you need to scroll to it, or resize (see WindowResizer or ElementResizer).- Parameters:
browser
- - browserel
- - element to capture and validate- Returns:
- the image
-
captureImage
public static BufferedImage captureImage(InBrowser browser)
capture the image of the entire window in the browser and return the image object- Parameters:
browser
- - browser- Returns:
- the image
-
captureImageNoScaling
public static BufferedImage captureImageNoScaling(InBrowser browser, Path el)
Same as captureImage(), but will not autoscale back to the size as the browser "sees" it. This may result in a much larger image.- Parameters:
browser
- - browserel
- - element to capture and validate- Returns:
- the image
-
-