private static String boundsToString(Bounds bounds) { Point upperLeftCorner = bounds.getUpperLeftCorner(); Point bottomRightCorner = bounds.getLowerRightCorner(); return pointToString(upperLeftCorner).concat(pointToString(bottomRightCorner)); }
public String constructAttributeSelector(CssAttribute attribute, Object propertyValue) { String propertyStringValue; if (propertyValue instanceof Bounds) { Bounds bounds = (Bounds) propertyValue; Point firstBound = bounds.getUpperLeftCorner(); Point secondBound = bounds.getLowerRightCorner(); propertyStringValue = String.format(BOUNDS_FORMAT, firstBound.getX(), firstBound.getY(), secondBound.getX(), secondBound.getY()); } else { propertyStringValue = propertyValue.toString(); } return String.format(queryString, attribute.getHtmlAttributeName(), propertyStringValue); } }
/** * Simulates a pinch out on the element. NOTE emulator devices may not detect pinch gestures on UI elements with * size smaller than 100x100dp. * * @return <code>true</code> if the pinch out is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean pinchOut() { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); Point firstFingerEnd = elementBounds.getUpperLeftCorner(); Point secondFingerEnd = elementBounds.getLowerRightCorner(); boolean result = (boolean) communicator.sendAction(RoutingAction.GESTURE_PINCH_OUT, firstFingerEnd, secondFingerEnd); return result; }
/** * Check if a {@link Point} is inside the bounds. * * @param point * - a {@link Point} that needs to be contained in the bounds * @return true if the bounds contain the point, false otherwise */ public boolean contains(Point point) { Point lowerRightCorner = getLowerRightCorner(); boolean containsPointX = point.getX() >= upperLeftCorner.getX() && point.getX() <= lowerRightCorner.getX(); boolean containsPointY = point.getY() >= upperLeftCorner.getY() && point.getY() <= lowerRightCorner.getY(); return containsPointX && containsPointY; }
/** * Simulates a pinch in on the element. NOTE emulator devices may not detect pinch gestures on UI elements with size * smaller than 100x100dp. * * @return <code>true</code> if the pinch in is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean pinchIn() { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); final int BOUNDS_OFFSET_DENOMINATOR = 10; final int WIDTH_OFFSET = elementBounds.getWidth() / BOUNDS_OFFSET_DENOMINATOR; final int HEIGHT_OFFSET = elementBounds.getHeight() / BOUNDS_OFFSET_DENOMINATOR; // starting the pinch at a distance from the exact bounds of the element so that it will not affect other UI // elements Point lowerRight = elementBounds.getLowerRightCorner(); int firstFingerInitialX = lowerRight.getX() - WIDTH_OFFSET; int firstFingerInitialY = lowerRight.getY() - HEIGHT_OFFSET; Point firstFingerInitial = new Point(firstFingerInitialX, firstFingerInitialY); Point upperLeft = elementBounds.getUpperLeftCorner(); int secondFingerInitialX = upperLeft.getX() + WIDTH_OFFSET; int secondFingerInitialY = upperLeft.getY() + HEIGHT_OFFSET; Point secondFingerInitial = new Point(secondFingerInitialX, secondFingerInitialY); boolean result = (boolean) communicator.sendAction(RoutingAction.GESTURE_PINCH_IN, firstFingerInitial, secondFingerInitial); return result; }
Point upperRightCorner = elementBounds.getUpperRightCorner(); Point lowerLeftCorner = elementBounds.getLowerLeftCorner(); Point lowerRightCorner = elementBounds.getLowerRightCorner();