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.smash.revolance.ui.model.element.api.Element.java

License:Open Source License

public static boolean isIncluded(WebElement element, Rectangle rectangle) {
    Point topleft = element.getLocation();
    Dimension dim = element.getSize();
    Rectangle rectangleRef = new Rectangle(topleft.getX(), topleft.getY(), dim.getWidth(), dim.getHeight());

    return rectangleRef.contains(rectangle);
}

From source file:io.appium.java_client.imagecomparison.ComparisonResult.java

License:Apache License

/**
 * Transforms a map into {@link Rectangle} object.
 *
 * @param map the source map.//from   ww  w  .  j ava 2 s.c  o  m
 * @return {@link Rectangle} object
 */
public static Rectangle mapToRect(Map<String, Object> map) {
    return new Rectangle(toSeleniumCoordinate(map.get("x")), toSeleniumCoordinate(map.get("y")),
            toSeleniumCoordinate(map.get("height")), toSeleniumCoordinate(map.get("width")));
}

From source file:org.zanata.util.TestEventForScreenshotListener.java

License:Open Source License

private void createScreenshot(String ofType) {
    File testIDDir = null;//from   w  w w  . j a v  a 2s . com
    try {
        testIDDir = ScreenshotDirForTest.screenshotForTest(testId);
        if (!testIDDir.exists()) {
            log.info("Creating screenshot dir {}", testIDDir.getAbsolutePath());
            boolean createdDirs = testIDDir.mkdirs();
            assert createdDirs;
        }
        String filename = generateFileName(ofType);
        File screenshotFile = new File(testIDDir, filename);

        Optional<Alert> alert = getAlert(driver);
        if (alert.isPresent()) {
            log.error(
                    "ChromeDriver screenshot({}) prevented by browser "
                            + "alert. Attempting Robot screenshot instead. " + "Alert text: {}",
                    testId, alert.get().getText());

            // warning: beta API: if it breaks, you can always use getScreenRectangle()
            WebDriver.Window window = driver.manage().window();
            Point pos = window.getPosition();
            Dimension size = window.getSize();

            Rectangle captureRectangle = new Rectangle(pos.x, pos.y, size.width, size.height);
            //                Rectangle captureRectangle = getScreenRectangle();

            BufferedImage capture = new Robot().createScreenCapture(captureRectangle);
            if (!ImageIO.write(capture, "png", screenshotFile)) {
                log.error("png writer not found for screenshot");
            }
        } else {
            File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
            FileUtils.moveFile(tempFile, screenshotFile);
        }
        log.info("Screenshot saved to file: {}", filename);
    } catch (WebDriverException e) {
        throw new RuntimeException("[Screenshot]: Invalid WebDriver: ", e);
    } catch (IOException e) {
        throw new RuntimeException("[Screenshot]: Failed to write to " + testIDDir, e);
    } catch (NullPointerException e) {
        throw new RuntimeException("[Screenshot]: Null Object: ", e);
    } catch (AWTException e) {
        throw new RuntimeException("[Screenshot]: ", e);
    }
}