Search in sources :

Example 11 with ImageDetector

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());
    }
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(java.awt.Rectangle) ScreenshotException(org.openqa.selenium.remote.ScreenshotException) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 12 with ImageDetector

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));
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 13 with ImageDetector

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();
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 14 with ImageDetector

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));
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 15 with ImageDetector

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));
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

ImageDetector (com.seleniumtests.util.imaging.ImageDetector)20 Test (org.testng.annotations.Test)18 GenericTest (com.seleniumtests.GenericTest)17 Rectangle (org.openqa.selenium.Rectangle)13 File (java.io.File)3 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 ScreenshotException (org.openqa.selenium.remote.ScreenshotException)2 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)1 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)1 Rectangle (java.awt.Rectangle)1 Dimension (org.openqa.selenium.Dimension)1