public class ScreenshotState
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ScreenshotState.ResizeMode |
static class |
ScreenshotState.ScreenshotComparisonError |
static class |
ScreenshotState.ScreenshotComparisonTimeout |
Constructor and Description |
---|
ScreenshotState(java.util.function.Supplier<java.awt.image.BufferedImage> stateProvider)
The class constructor accepts single argument, which is
lambda function, that provides the screenshot of the necessary
screen area to be verified for similarity.
|
Modifier and Type | Method and Description |
---|---|
java.time.Duration |
getComparisonInterval()
Gets the interval value in ms between similarity verification rounds in verify* methods.
|
static double |
getOverlapScore(java.awt.image.BufferedImage refImage,
java.awt.image.BufferedImage tplImage)
A shortcut to
getOverlapScore(BufferedImage, BufferedImage, ResizeMode) method
for the case if both reference and template images are expected to have the same dimensions. |
static double |
getOverlapScore(java.awt.image.BufferedImage refImage,
java.awt.image.BufferedImage tplImage,
ScreenshotState.ResizeMode resizeMode)
Compares two valid java bitmaps and calculates similarity score between them.
|
ScreenshotState |
remember()
Call this method to save the initial screenshot state.
|
ScreenshotState |
remember(java.awt.image.BufferedImage customInitialState)
This method allows to pass a custom bitmap for further comparison
instead of taking one using screenshot provider function.
|
ScreenshotState |
setComparisonInterval(java.time.Duration comparisonInterval)
Sets the interval between similarity verification rounds in verify* methods.
|
ScreenshotState |
verifyChanged(java.time.Duration timeout,
double minScore)
Verifies whether the state of the screenshot provided by stateProvider lambda function
is changed within the given timeout.
|
ScreenshotState |
verifyChanged(java.time.Duration timeout,
double minScore,
ScreenshotState.ResizeMode resizeMode)
Verifies whether the state of the screenshot provided by stateProvider lambda function
is changed within the given timeout.
|
ScreenshotState |
verifyNotChanged(java.time.Duration timeout,
double minScore)
Verifies whether the state of the screenshot provided by stateProvider lambda function
is not changed within the given timeout.
|
ScreenshotState |
verifyNotChanged(java.time.Duration timeout,
double minScore,
ScreenshotState.ResizeMode resizeMode)
Verifies whether the state of the screenshot provided by stateProvider lambda function
is changed within the given timeout.
|
public ScreenshotState(java.util.function.Supplier<java.awt.image.BufferedImage> stateProvider)
remember()
method in order to call it.
Examples of provider function with Appium driver:
() -> {
final byte[] srcImage = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return ImageIO.read(new ByteArrayInputStream(srcImage));
}
or
() -> {
final byte[] srcImage = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
final BufferedImage screenshot = ImageIO.read(new ByteArrayInputStream(srcImage));
final WebElement element = driver.findElement(locator);
// Can be simplified in Selenium 3.0+ by using getRect method of WebElement interface
final Point elementLocation = element.getLocation();
final Dimension elementSize = element.getSize();
return screenshot.getSubimage(
new Rectangle(elementLocation.x, elementLocation.y, elementSize.width, elementSize.height);
}
stateProvider
- lambda function, which returns a screenshot for further comparisonpublic java.time.Duration getComparisonInterval()
public ScreenshotState setComparisonInterval(java.time.Duration comparisonInterval)
comparisonInterval
- interval value. 500 ms by defaultpublic ScreenshotState remember()
public ScreenshotState remember(java.awt.image.BufferedImage customInitialState)
customInitialState
- valid bitmappublic ScreenshotState verifyChanged(java.time.Duration timeout, double minScore)
timeout
- timeout valueminScore
- the value in range (0.0, 1.0)ScreenshotState.ScreenshotComparisonTimeout
- if the calculated score is still
greater or equal to the given score after timeout happensScreenshotState.ScreenshotComparisonError
- if remember()
method has not been invoked yetpublic ScreenshotState verifyChanged(java.time.Duration timeout, double minScore, ScreenshotState.ResizeMode resizeMode)
timeout
- timeout valueminScore
- the value in range (0.0, 1.0)resizeMode
- one of ResizeMode enum values.
Set it to a value different from NO_RESIZE
if the actual screenshot is expected to have different
dimensions in comparison to the previously remembered oneScreenshotState.ScreenshotComparisonTimeout
- if the calculated score is still
greater or equal to the given score after timeout happensScreenshotState.ScreenshotComparisonError
- if remember()
method has not been invoked yetpublic ScreenshotState verifyNotChanged(java.time.Duration timeout, double minScore)
timeout
- timeout valueminScore
- the value in range (0.0, 1.0)ScreenshotState.ScreenshotComparisonTimeout
- if the calculated score is still
less than the given score after timeout happensScreenshotState.ScreenshotComparisonError
- if remember()
method has not been invoked yetpublic ScreenshotState verifyNotChanged(java.time.Duration timeout, double minScore, ScreenshotState.ResizeMode resizeMode)
timeout
- timeout valueminScore
- the value in range (0.0, 1.0)resizeMode
- one of ResizeMode enum values.
Set it to a value different from NO_RESIZE
if the actual screenshot is expected to have different
dimensions in comparison to the previously remembered oneScreenshotState.ScreenshotComparisonTimeout
- if the calculated score is still
less than the given score after timeout happensScreenshotState.ScreenshotComparisonError
- if remember()
method has not been invoked yetpublic static double getOverlapScore(java.awt.image.BufferedImage refImage, java.awt.image.BufferedImage tplImage)
getOverlapScore(BufferedImage, BufferedImage, ResizeMode)
method
for the case if both reference and template images are expected to have the same dimensions.refImage
- reference imagetplImage
- templateScreenshotState.ScreenshotComparisonError
- if provided images are not valid or have different resolutionpublic static double getOverlapScore(java.awt.image.BufferedImage refImage, java.awt.image.BufferedImage tplImage, ScreenshotState.ResizeMode resizeMode)
refImage
- reference imagetplImage
- templateresizeMode
- one of possible enum values. Set it either to TEMPLATE_TO_REFERENCE_RESOLUTION or
REFERENCE_TO_TEMPLATE_RESOLUTION if given bitmaps have different dimensionsScreenshotState.ScreenshotComparisonError
- if provided images are not valid or have
different resolution, but resizeMode has been set to NO_RESIZE