Example usage for org.openqa.selenium Point Point

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

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Usage

From source file:org.specrunner.webdriver.actions.input.mouse.AbstractPluginCoordinates.java

License:Open Source License

/**
 * Gets the point from a string, the pattern is 'x,y'.
 * //from w ww.j av  a2s.c  om
 * @param point
 *            The point as string.
 * @return The point.
 */
public static Point getPoint(String point) {
    int pos = point.indexOf(',');
    return new Point(Integer.parseInt(point.substring(0, pos)), Integer.parseInt(point.substring(pos + 1)));
}

From source file:org.specrunner.webdriver.actions.window.PluginPosition.java

License:Open Source License

@Override
protected void doEnd(IContext context, IResultSet result, WebDriver client, Options options, Window window)
        throws PluginException {
    Point p = null;// w  ww . j a va2s  . com
    try {
        p = window.getPosition();
    } catch (Exception e) {
        if (UtilLog.LOG.isDebugEnabled()) {
            UtilLog.LOG.debug(e.getMessage(), e);
        }
    }
    if (getX() == null && getY() == null) {
        throw new PluginException("PluginPosition action requires at least one of attributes 'x' and/or 'y'.");
    }
    if (p != null) {
        window.setPosition(new Point(getX() != null ? getX() : p.getX(), getY() != null ? getY() : p.getY()));
        result.addResult(Success.INSTANCE, context.peek());
    }
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteUIAElement.java

License:Apache License

@Override
public Point getLocation() {
    System.out.println("getLocation in RemoteUIAElement");

    WebDriverLikeRequest request = buildRequest(WebDriverLikeCommand.RECT);
    Map<String, Object> rect = commandExecutor.execute(request);
    Map<String, Long> origin = (Map<String, Long>) rect.get("origin");

    Long x = origin.get("x");
    Long y = origin.get("y");

    Point res = new Point(x.intValue(), y.intValue());
    return res;//from  w  w  w. j  a v  a 2 s .  c  o  m

}

From source file:org.uiautomation.ios.server.command.uiautomation.FlickNHandler.java

License:Apache License

public FlickNHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Point fromPoint;//from   ww w . j  av  a2 s  .c om
    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();

    if (!payload.isNull("element") && !elementId.equals("")) {
        try {
            RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession()
                    .getRemoteWebDriver().createElement(elementId);
            fromPoint = element.getLocation();
        } catch (Exception e) {
            fromPoint = getStartCoordinatesCentered(request, elementId);
        }
    } else {
        fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
    }

    String xOffset = payload.optString("xoffset");
    if (xOffset.equals("")) {
        xOffset = payload.optString("xspeed");
    }
    String yOffset = payload.optString("yoffset");
    if (yOffset.equals("")) {
        yOffset = payload.optString("yspeed");
    }

    String speed = payload.optString("speed").equals("") ? "1" : payload.optString("speed");
    if (Integer.valueOf(speed) < .5) {
        speed = "0.5";
    }

    Point toPoint = new Point(fromPoint.getX() + Integer.valueOf(xOffset),
            fromPoint.getY() + Integer.valueOf(yOffset));

    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);

    String js = dragTemplate.replace(":sessionId", request.getSession())
            .replace("fromX", String.valueOf(fromPoint.getX()))
            .replace("fromY", String.valueOf(fromPoint.getY())).replace("toX", String.valueOf(toPoint.getX()))
            .replace("toY", String.valueOf(toPoint.getY())).replace("duration", speed);
    setJS(js);
}

From source file:org.uiautomation.ios.server.command.web.ScrollHandler.java

License:Apache License

public ScrollHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();

    Point fromPoint;/*from   ww  w  .j  a  va 2  s . co  m*/
    if (!payload.isNull("element") && !elementId.equals("")) {
        RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
                .createElement(elementId);
        fromPoint = element.getLocation();
    } else {
        fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
    }
    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    Point toPoint = new Point(fromPoint.getX() + payload.getInt("xoffset"),
            fromPoint.getY() + payload.getInt("yoffset"));
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    String js = scrollTemplate.replace(":sessionId", request.getSession())
            .replace("fromX", Integer.toString(fromPoint.getX()))
            .replace("fromY", Integer.toString(fromPoint.getY()))
            .replace("toX", Integer.toString(toPoint.getX())).replace("toY", Integer.toString(toPoint.getY()));

    setJS(js);
}

From source file:org.uiautomation.ios.server.utils.CoordinateUtils.java

License:Apache License

public static Point forcePointOnScreen(Point point, Dimension screenSize) {

    int x;/*from  w w w.  jav a  2 s  .  c  o  m*/
    int y;

    if (point.getX() < 0) {
        x = 0;
    } else if (point.getX() > screenSize.getWidth()) {
        x = screenSize.getWidth();
    } else {
        x = point.getX();
    }

    if (point.getY() < 0) {
        y = 0;
    } else if (point.getY() > screenSize.getHeight()) {
        y = screenSize.getHeight();
    } else {
        y = point.getY();
    }

    return new Point(x, y);

}

From source file:org.uiautomation.ios.server.utils.CoordinateUtils.java

License:Apache License

private static Point getCenterPoint(int xCoord, int yCoord, int width, int height) {
    int centerX = xCoord + (width / 2);
    int centerY = yCoord + (height / 2);

    Point center = new Point(centerX, centerY);
    return center;
}

From source file:org.uiautomation.ios.server.utils.CoordinateUtilsTest.java

License:Apache License

@Test
public void getCenterPointFromResponseReturnsCenterOfRectangle() {
    Map<String, Object> origin = Maps.newHashMap();
    origin.put("x", "100");
    origin.put("y", "200");

    Map<String, Object> size = Maps.newHashMap();
    size.put("width", "10");
    size.put("height", "20");

    Map<String, Object> obj = Maps.newHashMap();
    obj.put("origin", origin);
    obj.put("size", size);

    Response response = new Response();
    response.setValue(obj);//w  w  w  .j  av  a 2  s.c  o m

    Point expectedPoint = new Point(105, 210);
    Point actualPoint = CoordinateUtils.getCenterPointFromResponse(response);

    Assert.assertEquals("Point should be center of response rectangle", expectedPoint, actualPoint);
}

From source file:org.uiautomation.ios.webInspector.DOM.RemoteWebElement.java

License:Apache License

public Point findPosition() throws Exception {

    StringBuilder b = new StringBuilder();
    b.append("(function(){");
    b.append("var element = this;\n");
    b.append("var rect = element.getClientRects()[0];\n");
    b.append("var res = {'x': rect.left, 'y': rect.top};\n");

    b.append(" var doc = element.ownerDocument;\n");
    b.append(" var win = doc.defaultView;\n");
    b.append(" var topWin = win.top;\n");

    b.append(" var parentFrame = function (doc) {\n");
    b.append("    var win = doc.defaultView;\n");
    b.append("    var parentWin = win.parent;\n");
    b.append("    var parentDoc = parentWin.document;\n");
    b.append("    var frames = parentDoc.querySelectorAll('iframe,frame');\n");
    b.append("    for (var i = 0; i < frames.length; i++) {\n");
    b.append("        if (frames[i].contentDocument === doc) {\n");
    b.append("            var r = frames[i];\n");
    b.append("            return r;\n");
    b.append("        }\n");
    b.append("    }\n");
    b.append("    return null;\n");
    b.append("}\n");

    b.append(" while (win !== topWin) {\n");
    b.append("    rect = parentFrame(doc).getClientRects()[0];\n");
    b.append("    var xoff = rect.left;\n");
    b.append("    var yoff = rect.top;\n");
    b.append("    if (xoff > 0) {\n");
    b.append("        res.x += xoff;\n");
    b.append("    }\n");
    b.append("    if (yoff > 0) {\n");
    b.append("        res.y += yoff;\n");
    b.append("    }\n");
    b.append("     win = win.parent;\n");
    b.append("    doc = win.document;\n");
    b.append("}\n");
    b.append("return " + IosAtoms.STRINGIFY + "(res);\n");
    b.append("})");

    JSONObject cmd = new JSONObject();

    cmd.put("method", "Runtime.callFunctionOn");

    cmd.put("params", new JSONObject().put("objectId", getRemoteObject().getId())
            .put("functionDeclaration", b.toString()).put("returnByValue", false));

    JSONObject response = inspector.sendCommand(cmd);
    String s = inspector.cast(response);
    JSONObject o = new JSONObject(s);
    return new Point(o.getInt("x"), o.getInt("y"));
}

From source file:org.uiautomation.ios.webInspector.DOM.RemoteWebElement.java

License:Apache License

public Point findPositionOld() throws Exception {
    String f = "(function(a) { " + "var el = this;" + " var rect = el.getClientRects()[0];" + " var res = "
            + IosAtoms.STRINGIFY + "({'top': rect.top,'left': rect.left });" + "return res;" + "})";

    JSONObject cmd = new JSONObject();

    cmd.put("method", "Runtime.callFunctionOn");

    cmd.put("params", new JSONObject().put("objectId", getRemoteObject().getId()).put("functionDeclaration", f)
            .put("returnByValue", false));

    JSONObject response = inspector.sendCommand(cmd);
    String s = inspector.cast(response);
    JSONObject o = new JSONObject(s);
    return new Point(o.getInt("left"), o.getInt("top"));
}