Example usage for org.openqa.selenium Rectangle Rectangle

List of usage examples for org.openqa.selenium Rectangle Rectangle

Introduction

In this page you can find the example usage for org.openqa.selenium Rectangle Rectangle.

Prototype

public Rectangle(int x, int y, int height, int width) 

Source Link

Usage

From source file:com.seleniumtests.uipage.htmlelements.GenericPictureElement.java

License:Apache License

/**
 * Search the picture in the screenshot taken by Robot or WebDriver
 * Robot is used in Desktop mode//  w w w. j a va 2  s  .  co m
 * WebDriver is used in mobile, because Robot is not available for mobile platforms
 * 
 */
public void findElement() {

    LocalDateTime start = LocalDateTime.now();

    File screenshotFile = getScreenshotFile();

    if (screenshotFile == null) {
        throw new WebDriverException("Screenshot does not exist");
    }

    // for desktop search, without reference image, do not search
    if (detector != null) {
        detector.setSceneImage(screenshotFile);
        detector.detectExactZoneWithScale();
        detectedObjectRectangle = detector.getDetectedRectangle();
        pictureSizeRatio = detector.getSizeRatio();
    } else {
        detectedObjectRectangle = new Rectangle(0, 0, 0, 0);
        pictureSizeRatio = 1.0;
    }
    actionDuration = Duration.between(start, LocalDateTime.now()).toMillis();

    doAfterPictureSearch();
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestPictureElement.java

License:Apache License

@Test(groups = { "ut" })
public void testClick() {
    PictureElement picElement = spy(pictureElement);
    picElement.setObjectPictureFile(new File(""));

    PowerMockito.mockStatic(WebUIDriver.class);
    when(WebUIDriver.getWebDriver()).thenReturn(driver);
    when(driver.getMouse()).thenReturn(mouse);
    when(driver.getKeyboard()).thenReturn(keyboard);
    when(screenshotUtil.capture(Target.PAGE, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);
    when(coordinates.inViewPort()).thenReturn(new Point(100, 120));
    when(coordinates.onPage()).thenReturn(new Point(100, 120));
    when(intoElement.getCoordinates()).thenReturn(coordinates);
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();

    picElement.click();//from   w w w .j a  v  a2s .co m
    verify(picElement).moveAndClick(intoElement, -65, -60);
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestPictureElement.java

License:Apache License

@Test(groups = { "ut" })
public void testPictureVisible() throws AWTException {
    PictureElement picElement = spy(pictureElement);
    picElement.setObjectPictureFile(new File(""));
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.PAGE, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    Assert.assertTrue(picElement.isElementPresent(2000));
    verify(picElement).findElement();//from   w  w w  . j ava2s  .  c  o m

}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestScreenZone.java

License:Apache License

@Test(groups = { "ut" })
public void testClick() {
    ScreenZone picElement = spy(screenZone);
    picElement.setObjectPictureFile(new File(""));

    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.SCREEN, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    picElement.click();/*www .  j a v a 2 s .co  m*/
    verify(picElement).moveAndLeftClick(35, 60);
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestScreenZone.java

License:Apache License

@Test(groups = { "ut" })
public void testDoubleClick() {
    ScreenZone picElement = spy(screenZone);
    picElement.setObjectPictureFile(new File(""));

    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.SCREEN, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    picElement.doubleClickAt(0, 0);//www  .ja  v a2  s  .c  o m
    verify(picElement).moveAndDoubleClick(35, 60);
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestScreenZone.java

License:Apache License

@Test(groups = { "ut" })
public void testRightClick() {
    ScreenZone picElement = spy(screenZone);
    picElement.setObjectPictureFile(new File(""));

    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.SCREEN, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    picElement.rightClickAt(0, 0);/*from w ww.  j a v  a2 s .c o  m*/
    verify(picElement).moveAndRightClick(35, 60);
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestScreenZone.java

License:Apache License

@Test(groups = { "ut" })
public void testSendKeys() {
    ScreenZone picElement = spy(screenZone);
    picElement.setObjectPictureFile(new File(""));

    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.SCREEN, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    picElement.sendKeys(0, 0, KeyEvent.VK_0);
    verify(picElement).moveAndLeftClick(35, 60);
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestScreenZone.java

License:Apache License

@Test(groups = { "ut" })
public void testPictureVisible() throws AWTException {
    ScreenZone picElement = spy(screenZone);
    picElement.setObjectPictureFile(new File(""));
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(Target.SCREEN, File.class, true)).thenReturn(new File(""));
    when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
    when(imageDetector.getSizeRatio()).thenReturn(1.0);

    Assert.assertTrue(picElement.isElementPresent(2000));
    verify(picElement).findElement();/*from w w w .j  av  a 2  s . co  m*/
}

From source file:com.seleniumtests.ut.util.imaging.TestImageDetector.java

License:Apache License

/**
 * Search an image inside an other with templace matching
 * @throws IOException // www.ja  v  a  2  s  . c  o m
 */
// 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);
}

From source file:com.seleniumtests.ut.util.imaging.TestImageDetector.java

License:Apache License

@Test(groups = { "ut" })
public void searchPicturesByTemplate2() throws IOException {
    ImageDetector detector = new ImageDetector(createFileFromResource("tu/images/infolidays.png"),
            createFileFromResource("tu/images/bouton_enregistrer2.png"), 0.06);
    detector.detectExactZoneWithScale();
    Assert.assertEquals(detector.getDetectedRectangle(), new Rectangle(69, 1609, 185, 1299));
    Assert.assertEquals(detector.getSizeRatio(), 1.2, 0.05);
}