/** * Gets the given bounds equivalent relative to the bounds upper left corner; * * @param bounds * - {@link Bounds} for which to get the relative bounds to the bounds upper left corner * @return the bounds equivalent relative to the bounds upper left corner */ public Bounds getRelativeBounds(Bounds bounds) { Point boundsUpperLeftCorner = bounds.getUpperLeftCorner(); int boundsWidth = bounds.getWidth(); int boundsHeight = bounds.getHeight(); Point relativeUpperLeftCorner = getRelativePoint(boundsUpperLeftCorner); Bounds relativeBounds = new Bounds(relativeUpperLeftCorner, boundsWidth, boundsHeight); return relativeBounds; }
/** * 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; }
private static String boundsToString(Bounds bounds) { Point upperLeftCorner = bounds.getUpperLeftCorner(); Point bottomRightCorner = bounds.getLowerRightCorner(); return pointToString(upperLeftCorner).concat(pointToString(bottomRightCorner)); }
/** * Simulates long press on the current element with passed timeout value. * * @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(int timeout) { Bounds elementBounds = propertiesContainer.getBounds(); Point centerPoint = elementBounds.getCenter(); Point tapPoint = elementBounds.getRelativePoint(centerPoint); return longPress(tapPoint, timeout); }
Pair<Integer, Integer> resolution) { Point upperLeftCorner = elementBounds.getUpperLeftCorner(); Point upperRightCorner = elementBounds.getUpperRightCorner(); Point lowerLeftCorner = elementBounds.getLowerLeftCorner(); Point lowerRightCorner = elementBounds.getLowerRightCorner(); upperLeftCornerPointX = lowerLeftCorner.getY(); upperLeftCornerPointY = lowerLeftCorner.getX(); elementWidth = elementBounds.getHeight(); elementHeight = elementBounds.getWidth(); upperLeftCornerPointX = upperRightCorner.getX(); upperLeftCornerPointY = upperRightCorner.getY(); elementWidth = elementBounds.getHeight(); elementHeight = elementBounds.getWidth(); upperLeftCornerPointX = upperLeftCorner.getX(); upperLeftCornerPointY = upperLeftCorner.getY(); elementWidth = elementBounds.getWidth(); elementHeight = elementBounds.getHeight(); upperLeftCornerPointX = lowerRightCorner.getX(); upperLeftCornerPointY = lowerRightCorner.getY(); elementWidth = elementBounds.getWidth(); elementHeight = elementBounds.getHeight();
/** * 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 selectorBoundsUpperCorner = selectorBounds.getUpperLeftCorner(); if ((nodeBounds.height() != selectorBounds.getHeight()) || (nodeBounds.width() != selectorBounds.getWidth()) || (selectorBoundsUpperCorner.getX() != nodeBounds.left) || (selectorBoundsUpperCorner.getY() != nodeBounds.top)) {
/** * 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); } }
@Override public Bounds getBounds() { Point upperLeft = new Point(bounds.left, bounds.top); // As Bounds are initially constructed with width and height int width = bounds.right - bounds.left; int height = bounds.bottom - bounds.top; return new Bounds(upperLeft, width, height); } }
/** * Drags the element until his center point stands at (Point endPoint) on the screen. * * @param endPoint * - the point where we want to move the element * @return <code>true</code> if the dragging is successful, <code>false</code> if it fails */ public boolean drag(Point endPoint) { Point startPoint = propertiesContainer.getBounds().getCenter(); return (boolean) communicator.sendAction(RoutingAction.GESTURE_DRAG, startPoint, endPoint); }
/** * 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; }
Point selectorBoundsUpperCorner = propertiesContainerBounds.getUpperLeftCorner(); if ((accessibilityNodeBounds.height() != propertiesContainerBounds.getHeight()) || (accessibilityNodeBounds.width() != propertiesContainerBounds.getWidth()) || (selectorBoundsUpperCorner.getX() != accessibilityNodeBounds.left) || (selectorBoundsUpperCorner.getY() != accessibilityNodeBounds.top)) {
/** * 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 tapping in the center of this UI Element. * * @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() { Bounds elementBounds = propertiesContainer.getBounds(); Point centerPoint = elementBounds.getCenter(); Point tapPoint = elementBounds.getRelativePoint(centerPoint); return tap(tapPoint); }
Point second = new Point(secondPointX, secondPointY); Bounds result = new Bounds(first, second); return result; } else {
/** * Simulates swiping this UiElement. * * @param swipeDirection * - a {@link SwipeDirection}, describing the direction of the swipe. * @return <code>true</code> if the swiping is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean swipe(SwipeDirection swipeDirection) { Bounds elementBounds = propertiesContainer.getBounds(); Point centerPoint = elementBounds.getCenter(); return swipe(centerPoint, swipeDirection); }
/** * 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; }
/** * 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); } }
/** * Simulates double-tapping in the center of this UiElement. * * @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() { Bounds elementBounds = propertiesContainer.getBounds(); Point centerPoint = elementBounds.getCenter(); Point tapPoint = elementBounds.getRelativePoint(centerPoint); return doubleTap(tapPoint); }
protected void setCommonProperties(AccessibilityNodeInfo nodeInfo, AccessibilityElement element, int index) { element.setText(CharSequenceUtils.getString(nodeInfo.getText())); element.setClassName(CharSequenceUtils.getString(nodeInfo.getClassName())); element.setPackageName(CharSequenceUtils.getString(nodeInfo.getPackageName())); element.setContentDescriptor(CharSequenceUtils.getString(nodeInfo.getContentDescription())); element.setChechkable(nodeInfo.isCheckable()); element.setChechked(nodeInfo.isChecked()); element.setClickable(nodeInfo.isClickable()); element.setEnabled(nodeInfo.isEnabled()); element.setFocusable(nodeInfo.isFocusable()); element.setFocused(nodeInfo.isFocused()); element.setScrollable(nodeInfo.isScrollable()); element.setLongClickable(nodeInfo.isLongClickable()); element.setPassword(nodeInfo.isPassword()); element.setSelected(nodeInfo.isSelected()); element.setIndex(index); Rect boundsRect = new Rect(); nodeInfo.getBoundsInScreen(boundsRect); Point topLeft = new Point(boundsRect.left, boundsRect.top); Point bottomRight = new Point(boundsRect.right, boundsRect.bottom); Bounds bounds = new Bounds(topLeft, bottomRight); element.setBounds(bounds); }