public class ScreenshotState
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ScreenshotState.ScreenshotComparisonError |
static class |
ScreenshotState.ScreenshotComparisonTimeout |
| Constructor and Description |
|---|
ScreenshotState(ComparesImages comparator) |
ScreenshotState(ComparesImages comparator,
java.util.function.Supplier<java.awt.image.BufferedImage> stateProvider)
The class constructor accepts two arguments.
|
| Modifier and Type | Method and Description |
|---|---|
java.time.Duration |
getComparisonInterval()
Gets the interval value in ms between similarity verification rounds in verify* methods.
|
double |
getOverlapScore(java.awt.image.BufferedImage refImage,
java.awt.image.BufferedImage tplImage)
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 |
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.
|
public ScreenshotState(ComparesImages comparator, 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);
}
comparator - image comparatorstateProvider - lambda function, which returns a screenshot for further comparisonpublic ScreenshotState(ComparesImages comparator)
public 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 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 double getOverlapScore(java.awt.image.BufferedImage refImage,
java.awt.image.BufferedImage tplImage)
ComparesImages.getImagesSimilarity(byte[], byte[]).refImage - reference imagetplImage - templateScreenshotState.ScreenshotComparisonError - if provided images are not valid or have
different resolution