/** * Simulates tapping on a relative point in the current UI element. * * @param point * - the relative point that will be added to the upper left corner's coordinates * @return <code>true</code> if the tapping is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean tap(Point point) { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); Point tapPoint = elementBounds.getUpperLeftCorner(); tapPoint.addVector(point); if (elementBounds.contains(tapPoint)) { boolean isElementTapped = (boolean) communicator.sendAction(RoutingAction.GESTURE_TAP, tapPoint); finalizeUiElementOperation(); return isElementTapped; } else { String message = String.format("Point %s not in element bounds.", point.toString()); LOGGER.error(message); throw new IllegalArgumentException(message); } }
/** * Simulates long press on given point inside the current {@link UiElement uielement} for given time. * * @param innerPoint * - point, representing the relative coordinates of the point for long press, inside the element's bounds * @param timeout * - time in ms for which the element should be held * @return true, if operation is successful, and false otherwise * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean longPress(Point innerPoint, int timeout) { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); Point longPressPoint = elementBounds.getUpperLeftCorner(); longPressPoint.addVector(innerPoint); if (elementBounds.contains(longPressPoint)) { boolean isElementTapped = (boolean) communicator.sendAction(RoutingAction.GESTURE_LONG_PRESS, longPressPoint, timeout); finalizeUiElementOperation(); return isElementTapped; } else { String message = String.format("Point %s not in element bounds.", innerPoint.toString()); LOGGER.error(message); throw new IllegalArgumentException(message); } }
/** * Simulates double-tapping on a point in this UiElement. * * @param point * - a {@link Point} object, representing the relative coordinates of the point to tap inside this UiElement. * <i><b><u>Note</u></b>: the point with relative coordinates (0,0) denotes the upper-left corner of the * UiElement</i> * @return <code>true</code> if the double tapping is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean doubleTap(Point point) { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); Point tapPoint = elementBounds.getUpperLeftCorner(); tapPoint.addVector(point); if (elementBounds.contains(tapPoint)) { boolean isElementTapped = (boolean) communicator.sendAction(RoutingAction.GESTURE_DOUBLE_TAP, tapPoint); finalizeUiElementOperation(); return isElementTapped; } else { String message = String.format("Point %s not in element bounds.", point.toString()); LOGGER.error(message); throw new IllegalArgumentException(message); } }
/** * Check if certain {@link Bounds} parameter is inside the bounds. * * @param bounds * - a {@link Bounds} parameter that needs to be contained in the bounds * @return true if the bounds contain the bounds parameter, false otherwise */ public boolean contains(Bounds bounds) { Point boundsUpperLeftCorner = bounds.getUpperLeftCorner(); int boundsWidth = bounds.getWidth(); int boundsHeight = bounds.getHeight(); boolean containsUpperLeftCorner = contains(boundsUpperLeftCorner); boolean containsWidth = boundsUpperLeftCorner.getX() + boundsWidth <= upperLeftCorner.getX() + width; boolean containsHeight = boundsUpperLeftCorner.getY() + boundsHeight <= upperLeftCorner.getY() + height; return containsUpperLeftCorner && containsWidth && containsHeight; }