Search in sources :

Example 1 with ImageDetector

use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.

the class HtmlElement method detectViewPortPosition.

private Rectangle detectViewPortPosition() {
    BufferedImage image;
    try {
        image = ImageProcessor.loadFromFile(getViewportScreenshotFile());
        BufferedImage croppedImage = ImageProcessor.cropImage(image, 0, 0, image.getWidth(), 150);
        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 : Rectangle(org.openqa.selenium.Rectangle) ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) ScreenshotException(org.openqa.selenium.remote.ScreenshotException) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ImageDetector

use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.

the class TestImageDetector method searchPictureWith180degRotation.

/**
 * Search an image inside an other one, 180° rotation, no resizing
 * @throws IOException
 */
@Test(groups = { "ut" }, enabled = false)
public void searchPictureWith180degRotation() throws IOException {
    ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/p9.png"), createFileFromResource("tu/images/vosAlertesRotate180.png"));
    detector.detectCorrespondingZone();
    Assert.assertEquals(detector.getRotationAngle(), 180);
    Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(574, 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 3 with ImageDetector

use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.

the class TestImageDetector method searchPicturesByTemplate.

/**
 * Search an image inside an other with templace matching
 * @throws IOException
 */
// low resolution
@Test(groups = { "ut" })
public void searchPicturesByTemplate() throws IOException {
    ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/infolidays.png"), createFileFromResource("tu/images/bouton_enregistrer.png"), 0.06);
    detector.detectExactZoneWithScale();
    Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(457, 1582, 232, 487));
    Assert.assertEquals(detector.getSizeRatio(), 2.5, 0.05);
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 4 with ImageDetector

use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.

the class TestImageDetector method searchPictureWithResizing.

/**
 * Search an image inside an other one, 0° rotation, 80% resizing
 * @throws IOException
 */
@Test(groups = { "ut" }, enabled = false)
public void searchPictureWithResizing() throws IOException {
    ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/RIB.png"), createFileFromResource("tu/images/creditMutuelLogo0.8.png"));
    detector.detectCorrespondingZone();
    Assert.assertEquals(detector.getRotationAngle(), 0);
    Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(603, 147, 77, 493));
}
Also used : ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Rectangle(org.openqa.selenium.Rectangle) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 5 with ImageDetector

use of com.seleniumtests.util.imaging.ImageDetector in project seleniumRobot by bhecquet.

the class TestImageDetector method searchPictureWith90degRotation.

/**
 * Search an image inside an other one, 90° rotation, no resizing
 * @throws IOException
 */
@Test(groups = { "ut" }, enabled = false)
public void searchPictureWith90degRotation() throws IOException {
    ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/p9.png"), createFileFromResource("tu/images/vosAlertesRotate90.png"));
    detector.detectCorrespondingZone();
    Assert.assertEquals(detector.getRotationAngle(), 90);
    Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(574, 136, 29, 107));
}
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