Example usage for org.openqa.selenium Point getY

List of usage examples for org.openqa.selenium Point getY

Introduction

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

Prototype

public int getY() 

Source Link

Usage

From source file:org.uiautomation.ios.wkrdp.model.RemoteWebNativeBackedElement.java

License:Apache License

private String getNativeElementClickOnIt() throws Exception {
    // web stuff.
    scrollIntoViewIfNeeded();/*from   w w w . ja  v a 2 s .c  o m*/
    Point location = getLocation();
    String script = "UIATarget.localTarget().tap({'x':x_coord,'y':y_coord});";
    script = script.replace("x_coord", String.valueOf(location.getX())).replace("y_coord",
            String.valueOf(location.getY()));
    return script;
}

From source file:org.xframium.gesture.AbstractGesture.java

License:Open Source License

/**
 * Gets the actual point.//from ww  w  . jav a  2 s. c  om
 *
 * @param percentagePoint the percentage point
 * @param screenDimension the screen dimension
 * @return the actual point
 */
protected Point getActualPoint(Point percentagePoint, Dimension screenDimension) {
    if (webElement != null) {
        if (webElement.getLocation() != null && webElement.getSize() != null
                && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) {
            int x = percentagePoint.getX() * webElement.getSize().getWidth() + webElement.getLocation().getX();
            int y = percentagePoint.getY() * webElement.getSize().getHeight() + webElement.getLocation().getY();
            return new Point(x, y);
        }
    }

    return new Point((int) ((percentagePoint.getX() / 100.0) * (double) screenDimension.getWidth()),
            (int) ((percentagePoint.getY() / 100.0) * (double) screenDimension.getHeight()));
}

From source file:org.xframium.gesture.factory.spi.appium.PressGesture.java

License:Open Source License

@Override
protected boolean _executeGesture(WebDriver webDriver) {
    AppiumDriver appiumDriver = null;/*from  w  w w  .  ja  v  a2  s .c  om*/

    if (webDriver instanceof AppiumDriver)
        appiumDriver = (AppiumDriver) webDriver;
    else if (webDriver instanceof NativeDriverProvider) {
        NativeDriverProvider nativeProvider = (NativeDriverProvider) webDriver;
        if (nativeProvider.getNativeDriver() instanceof AppiumDriver)
            appiumDriver = (AppiumDriver) nativeProvider.getNativeDriver();
        else
            throw new IllegalArgumentException("Unsupported Driver Type " + webDriver);
    }
    Dimension screenDimension = appiumDriver.manage().window().getSize();

    Point pressPosition = getActualPoint(getPressPosition(), screenDimension);

    TouchAction swipeAction = new TouchAction(appiumDriver);
    swipeAction.press(pressPosition.getX(), pressPosition.getY()).waitAction(getPressLength()).release()
            .perform();

    return true;
}

From source file:org.xframium.gesture.factory.spi.appium.SwipeGesture.java

License:Open Source License

@Override
protected boolean _executeGesture(WebDriver webDriver) {
    AppiumDriver appiumDriver = null;//from  www .  j av  a  2 s.c om

    if (webDriver instanceof AppiumDriver)
        appiumDriver = (AppiumDriver) webDriver;
    else if (webDriver instanceof NativeDriverProvider) {
        NativeDriverProvider nativeProvider = (NativeDriverProvider) webDriver;
        if (nativeProvider.getNativeDriver() instanceof AppiumDriver)
            appiumDriver = (AppiumDriver) nativeProvider.getNativeDriver();
        else
            throw new IllegalArgumentException("Unsupported Driver Type " + webDriver);
    }
    Dimension screenDimension = appiumDriver.manage().window().getSize();

    Point actualStart = getActualPoint(getSwipeStart(), screenDimension);
    Point actualEnd = getActualPoint(getSwipeEnd(), screenDimension);

    TouchAction swipeAction = new TouchAction(appiumDriver);
    swipeAction.press(actualStart.getX(), actualStart.getY()).moveTo(actualEnd.getX(), actualEnd.getY())
            .release().perform();

    return true;
}

From source file:org.xframium.gesture.factory.spi.appium.TwoFingerGesture.java

License:Open Source License

@Override
protected boolean _executeGesture(WebDriver webDriver) {

    AppiumDriver appiumDriver = null;/*from ww w.j  a  va 2  s. c  om*/

    if (webDriver instanceof AppiumDriver)
        appiumDriver = (AppiumDriver) webDriver;
    else if (webDriver instanceof NativeDriverProvider) {
        NativeDriverProvider nativeProvider = (NativeDriverProvider) webDriver;
        if (nativeProvider.getNativeDriver() instanceof AppiumDriver)
            appiumDriver = (AppiumDriver) nativeProvider.getNativeDriver();
        else
            throw new IllegalArgumentException("Unsupported Driver Type " + webDriver);
    }

    Dimension screenDimension = appiumDriver.manage().window().getSize();

    Point startOne = getActualPoint(getStartOne(), screenDimension);
    Point startTwo = getActualPoint(getStartTwo(), screenDimension);
    Point endOne = getActualPoint(getEndOne(), screenDimension);
    Point endTwo = getActualPoint(getEndTwo(), screenDimension);

    MultiTouchAction tAction = new MultiTouchAction(appiumDriver);

    TouchAction fingerOne = new TouchAction(appiumDriver);
    fingerOne.press(startOne.getX(), startOne.getY()).moveTo(endOne.getX(), endOne.getY()).release();

    TouchAction fingerTwo = new TouchAction(appiumDriver);
    fingerTwo.press(startTwo.getX(), startTwo.getY()).moveTo(endTwo.getX(), endTwo.getY()).release();

    tAction.add(fingerOne).add(fingerTwo).perform();
    return true;
}

From source file:org.xframium.gesture.factory.spi.perfecto.SwipeGesture.java

License:Open Source License

@Override
protected boolean _executeGesture(WebDriver webDriver) {

    String executionId = getExecutionId(webDriver);
    String deviceName = getDeviceName(webDriver);
    if (executionId != null && deviceName != null) {

        if (webElement != null) {
            if (webElement.getLocation() != null && webElement.getSize() != null
                    && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) {
                int x = (int) ((getSwipeStart().getX() / 100.0) * (double) webElement.getSize().getWidth()
                        + webElement.getLocation().getX());
                int y = (int) ((getSwipeStart().getY() / 100.0) * (double) webElement.getSize().getHeight()
                        + webElement.getLocation().getY());
                Point swipeStart = new Point(x, y);

                x = (int) ((getSwipeEnd().getX() / 100.0) * (double) webElement.getSize().getWidth()
                        + webElement.getLocation().getX());
                y = (int) ((getSwipeEnd().getY() / 100.0) * (double) webElement.getSize().getHeight()
                        + webElement.getLocation().getY());
                Point swipeEnd = new Point(x, y);

                PerfectoMobile.instance().gestures().swipe(executionId, deviceName,
                        new PercentagePoint(swipeStart.getX(), swipeStart.getY(), false),
                        new PercentagePoint(swipeEnd.getX(), swipeEnd.getY(), false));
                return true;
            } else {
                log.warn("A relative elements was specified however no size could be determined");
                return false;
            }//from w  w w.j a va 2  s .  c om
        }

        PerfectoMobile.instance().gestures().swipe(executionId, deviceName,
                new PercentagePoint(getSwipeStart().getX(), getSwipeStart().getY()),
                new PercentagePoint(getSwipeEnd().getX(), getSwipeEnd().getY()), 2);
        return true;
    } else
        return false;
}

From source file:org.xframium.gesture.factory.spi.perfecto.TwoFingerGesture.java

License:Open Source License

@Override
protected boolean _executeGesture(WebDriver webDriver) {

    String executionId = getExecutionId(webDriver);
    String deviceName = getDeviceName(webDriver);
    if (executionId != null && deviceName != null) {

        if (webElement != null) {
            if (webElement.getLocation() != null && webElement.getSize() != null
                    && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) {
                int x = getStartOne().getX() * webElement.getSize().getWidth()
                        + webElement.getLocation().getX();
                int y = getStartOne().getY() * webElement.getSize().getHeight()
                        + webElement.getLocation().getY();
                Point swipeStart = new Point(x, y);

                x = getEndOne().getX() * webElement.getSize().getWidth() + webElement.getLocation().getX();
                y = getEndOne().getY() * webElement.getSize().getHeight() + webElement.getLocation().getY();
                Point swipeEnd = new Point(x, y);

                PerfectoMobile.instance().gestures().pinch(executionId, deviceName,
                        new PercentagePoint(swipeStart.getX(), swipeStart.getY(), false),
                        new PercentagePoint(swipeEnd.getX(), swipeEnd.getY(), false));
                return true;
            } else {
                log.warn("A relative elements was specified however no size could be determined");
                return false;
            }/*from www  . ja va 2 s .  com*/
        }

        PerfectoMobile.instance().gestures().pinch(executionId, deviceName,
                new PercentagePoint(getStartOne().getX(), getStartOne().getY()),
                new PercentagePoint(getEndOne().getX(), getEndOne().getY()));
        return true;
    } else
        return false;
}

From source file:org.xframium.page.keyWord.step.spi.KWSAt.java

License:Open Source License

@Override
public boolean _executeStep(Page pageObject, WebDriver webDriver, Map<String, Object> contextMap,
        Map<String, PageData> dataMap, Map<String, Page> pageMap) {
    if (pageObject == null)
        throw new IllegalStateException("There was no Page Object defined");

    Element currentElement = getElement(pageObject, contextMap, webDriver, dataMap).cloneElement();
    currentElement.setCacheNative(true);
    Point at = ((WebElement) currentElement.getNative()).getLocation();
    Dimension size = ((WebElement) currentElement.getNative()).getSize();

    String contextName = getContext();
    if (contextName == null)
        contextName = getName();//from w  ww . j  av a2 s  .  c o  m

    if (getContext() != null) {
        if (log.isDebugEnabled())
            log.debug("Setting Context Data to [" + currentElement.getValue() + "] for [" + getContext() + "]");

        contextMap.put(contextName + ".x", at.getX() + "");
        contextMap.put(contextName + ".y", at.getY() + "");
        contextMap.put(contextName + ".width", size.getWidth() + "");
        contextMap.put(contextName + ".height", size.getHeight() + "");
    }

    return currentElement.isPresent();
}

From source file:org.xframium.page.keyWord.step.spi.KWSCheckColor.java

License:Open Source License

@Override
public boolean _executeStep(Page pageObject, WebDriver webDriver, Map<String, Object> contextMap,
        Map<String, PageData> dataMap, Map<String, Page> pageMap) {
    if (pageObject == null)
        throw new IllegalStateException("Page Object was not defined");

    if (getParameterList().size() < 2)
        throw new IllegalArgumentException(
                "Verify Color must have 3 parameters - Resolution, location(x, y) and color");

    long fileKey = System.currentTimeMillis();
    Resolution resolution = Resolution//ww w .  j  a va2s  .c  om
            .valueOf((getParameterValue(getParameterList().get(0), contextMap, dataMap) + "").toLowerCase());
    Point location = createPoint(getParameterValue(getParameterList().get(1), contextMap, dataMap) + "");
    int percentDeviation = 0;
    String colorCode = null;

    if (getParameterList().size() >= 3) {
        if (log.isInfoEnabled())
            log.info("Extracted information for color comparison");
        colorCode = getParameterValue(getParameterList().get(2), contextMap, dataMap) + "";
        percentDeviation = Integer
                .parseInt(getParameterValue(getParameterList().get(3), contextMap, dataMap) + "");
    }

    BufferedImage elementValue = (BufferedImage) getElement(pageObject, contextMap, webDriver, dataMap)
            .getImage(resolution);
    String imagePath = null;
    if (elementValue != null)
        imagePath = PageManager.instance().writeImage(elementValue, fileKey + "-" + getName() + ".png");

    int elementColor = elementValue.getRGB(location.getX(), location.getY());

    if (getContext() != null) {
        if (log.isInfoEnabled())
            log.info("Setting Context Data to [" + elementColor + "] for [" + getContext() + "]");
        contextMap.put(getContext(), elementColor + "");
    }

    if (colorCode != null) {
        int[] expectedColors = extractColors(colorCode);
        int[] extractColors = new int[] { ((elementColor & 0x00ff0000) >> 16),
                ((elementColor & 0x0000ff00) >> 8), ((elementColor & 0x000000ff)) };

        int redChange = compareColor(expectedColors[0], extractColors[0]);
        int greenChange = compareColor(expectedColors[1], extractColors[1]);
        int blueChange = compareColor(expectedColors[2], extractColors[2]);

        if (((redChange + greenChange + blueChange) / 3) > percentDeviation) {

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("The COLOR value of [#" + Integer.toHexString(elementColor) + "] for ["
                    + getName() + "] was off by " + ((redChange + greenChange + blueChange) / 3)
                    + "% - Here is the break down - ");
            if (redChange > 0)
                stringBuilder.append("The RED channel was off by " + redChange + "% ");
            if (greenChange > 0)
                stringBuilder.append("The GREEN channel was off by " + greenChange + "% ");
            if (blueChange > 0)
                stringBuilder.append("The BLUE channel was off by " + blueChange + "% ");

            ArtifactManager.instance().notifyArtifactListeners(ArtifactType.WCAG_REPORT,
                    new WCAGRecord(getPageName(), getName(), WCAGType.ColorVerification,
                            System.currentTimeMillis(), System.currentTimeMillis() - fileKey, false, imagePath,
                            colorCode, Integer.toHexString(elementColor), stringBuilder.toString()));

            throw new IllegalArgumentException(stringBuilder.toString());
        } else
            ArtifactManager.instance().notifyArtifactListeners(ArtifactType.WCAG_REPORT,
                    new WCAGRecord(getPageName(), getName(), WCAGType.ColorVerification,
                            System.currentTimeMillis(), System.currentTimeMillis() - fileKey, true, imagePath,
                            colorCode, Integer.toHexString(elementColor), "OK"));
    }

    return true;
}

From source file:org.xwiki.test.selenium.framework.AbstractXWikiTestCase.java

License:Open Source License

/**
 * @param elementLocator the locator used to get the desired element. e.g. By.id("someId")
 * @return true if the element is in the window's viewport, i.e. is scrolled to; false otherwise.
 * @since 6.2//from w  ww.  ja  va2  s  .c o  m
 */
public boolean isElementInView(By elementLocator) {
    Point elementLocation = getDriver().findElement(elementLocator).getLocation();

    int windowXLeft = Integer.parseInt(getSelenium().getEval("window.scrollX"));
    int windowYTop = Integer.parseInt(getSelenium().getEval("window.scrollY"));

    int width = Integer.parseInt(getSelenium().getEval("document.documentElement.clientWidth"));
    int height = Integer.parseInt(getSelenium().getEval("document.documentElement.clientHeight"));

    int windowXRight = windowXLeft + width;
    int windowYBottom = windowYTop + height;

    return (elementLocation.getX() >= windowXLeft && elementLocation.getX() <= windowXRight
            && elementLocation.getY() >= windowYTop && elementLocation.getY() <= windowYBottom);
}