use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.
the class UiElement method detectViewPortPosition.
private Rectangle detectViewPortPosition(File screenshotFile) {
BufferedImage image;
try {
image = ImageProcessor.loadFromFile(screenshotFile);
BufferedImage croppedImage = ImageProcessor.cropImage(image, 0, 0, image.getWidth(), 50);
File cropScreenshotFile = File.createTempFile("img", ".png");
ImageIO.write(croppedImage, "png", cropScreenshotFile);
File desktopScreenshotFile = getDesktopScreenshotFile();
if (desktopScreenshotFile == null) {
throw new ScreenshotException("Desktop screenshot does not exist");
}
ImageDetector imageDetector = new ImageDetector(desktopScreenshotFile, cropScreenshotFile, 0.2);
imageDetector.detectExactZoneWithoutScale();
org.openqa.selenium.Rectangle detectedRectangle = imageDetector.getDetectedRectangle();
return new Rectangle(detectedRectangle.x, detectedRectangle.y, detectedRectangle.height, detectedRectangle.width);
} catch (IOException e) {
throw new ScreenshotException("Error getting position of viewport: " + e.getMessage());
}
}
use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.
the class TestImageDetector method searchPictureWith270degRotation.
/**
* Search an image inside an other one, 180° rotation, no resizing
* @throws IOException
*/
@Test(groups = { "ut" }, enabled = false)
public void searchPictureWith270degRotation() throws IOException {
ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/p9.png"), createFileFromResource("tu/images/vosAlertesRotate270.png"));
detector.detectCorrespondingZone();
Assert.assertEquals(detector.getRotationAngle(), 270);
Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(575, 135, 29, 107));
}
use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.
the class TestImageDetector method searchPictureWithNonProportianalResizing.
/**
* Search an image inside an other one, 0° rotation, 80% resizing in width and 100% in height
* Error should be raised
* @throws IOException
*/
@Test(groups = { "ut" }, expectedExceptions = ImageSearchException.class, enabled = false)
public void searchPictureWithNonProportianalResizing() throws IOException {
ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/RIB.png"), createFileFromResource("tu/images/creditMutuelLogo0.8-1.png"));
detector.detectCorrespondingZone();
}
use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.
the class TestImageDetector method searchExactPicture.
/**
* Search an image with template matching
* @throws IOException
*/
@Test(groups = { "ut" })
public void searchExactPicture() throws IOException {
ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/p9.png"), createFileFromResource("tu/images/vosAlertes.png"));
detector.detectExactZoneWithScale();
Rectangle detectedRectangle = detector.getDetectedRectangle();
Assert.assertEquals(detectedRectangle, new Rectangle(575, 137, 30, 108));
}
use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.
the class TestImageDetector method searchPictureWithoutRotationDriverPage.
/**
* Search an image inside an other one, no rotation, no resizing
* @throws IOException
*/
@Test(groups = { "ut" }, enabled = false)
public void searchPictureWithoutRotationDriverPage() throws IOException {
ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/driverTestPage.png"), createFileFromResource("tu/images/logo_text_field.png"));
detector.detectCorrespondingZone();
Assert.assertEquals(detector.getRotationAngle(), 0);
Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(3, 714, 94, 138));
}
Aggregations