default void waitUntilAnimationFinished() { SeleniumUtils.keepTrying(SeleniumGlobals.getLongTimeoutInSeconds(), () -> { WebElement element = element(); if (element.isDisplayed()) { return false; } Rectangle bounds = element.getRect(); SeleniumUtils.waitForSeconds(0.1); return Objects.equals(element.getRect(), bounds) ? true : null; }); }
@Override public Rectangle getRect() { Rectangle returnValue = null; webDriver.getExecutionContext().startStep( createStep( "AT" ), null, null ); try { returnValue = baseElement.getRect(); } catch( Exception e ) { webDriver.getExecutionContext().completeStep( StepStatus.FAILURE, e ); } webDriver.getExecutionContext().completeStep( StepStatus.SUCCESS, null ); return returnValue; }
@Override public List<WebElement> findElements( SearchContext context ) { if ( imageName != null ) { Rectangle r = webDriver.getCloud().getCloudActionProvider().findImage( webDriver, imageName, propertyMap ); if ( r != null ) { List<WebElement> elementList = new ArrayList<WebElement>( 1 ); elementList.add( new VisualWebElement( webDriver, r ) ); return elementList; } } return null; }
@Override public List<WebElement> findElements( SearchContext context ) { if ( text != null ) { Rectangle r = webDriver.getCloud().getCloudActionProvider().findText( webDriver, text, propertyMap ); if ( r != null ) { List<WebElement> elementList = new ArrayList<WebElement>( 1 ); elementList.add( new VisualWebElement( webDriver, r ) ); return elementList; } } return null; }
@Override public ExtendedWebElement getElementsByCoordinates(int x, int y) { String elementName = String.format("Element founded by x:%d - y:%d", x, y); WebDriver driver = DriverPool.getDriver(); List<WebElement> elements = getEndLevelElements(driver); List<WebElement> result = new ArrayList<WebElement>(); Rectangle rect; for (WebElement webElement : elements) { try { rect = getRect(webElement); } catch (Exception e) { continue; } if (isInside(rect, x, y)) { result.add(webElement); } } return generateExtenedElement(result, driver, elementName); }
@Override public Rectangle findImage( DeviceWebDriver webDriver, String imageName, Map<String, String> propertyMap ) { ImageExecution imageExec = PerfectoMobile.instance( webDriver.getxFID() ).imaging().imageExists( webDriver.getExecutionId(), webDriver.getDeviceName(), imageName, propertyMap ); if ( imageExec != null && Boolean.parseBoolean( imageExec.getStatus() ) ) return new Rectangle( new Point( Integer.parseInt( imageExec.getLeft() ), Integer.parseInt( imageExec.getTop() ) ), new Dimension( Integer.parseInt( imageExec.getWidth() ), Integer.parseInt( imageExec.getHeight() ) ) ); return null; }
@Override public Rectangle findText( DeviceWebDriver webDriver, String text, Map<String, String> propertyMap ) { ImageExecution imageExec = PerfectoMobile.instance( webDriver.getxFID() ).imaging().textExists( webDriver.getExecutionId(), webDriver.getDeviceName(), text, propertyMap ); if ( imageExec != null && Boolean.parseBoolean( imageExec.getStatus() ) ) return new Rectangle( new Point( Integer.parseInt( imageExec.getLeft() ), Integer.parseInt( imageExec.getTop() ) ), new Dimension( Integer.parseInt( imageExec.getWidth() ), Integer.parseInt( imageExec.getHeight() ) ) ); return null; }
public VisualWebElement ( DeviceWebDriver webDriver, Rectangle r ) { this.location = r.getPoint(); this.size = r.getDimension(); this.webDriver = webDriver; }
@Override public Rectangle getRect() { if (rectCache == null) { rectCache = new ObjectCache<>(super::getRect); } return rectCache.getValue(); }
@Test public void shouldCallGetRectOnUnderlyingWebElement() { WebDriver.TargetLocator locator = mock(WebDriver.TargetLocator.class); WebDriverTarget target = mock(WebDriverTarget.class); TargetedWebElement element = mock(TargetedWebElement.class); when(element.getRect()).thenReturn(mock(Rectangle.class)); TargetedWebElement targetedWebElement = new TargetedWebElement(locator, target, element); targetedWebElement.getRect(); verify(element).getRect(); }
@Override public ICapturable highlight(Rectangle rect) { try { Graphics2D g2d = screenshot.createGraphics(); g2d.setColor(Color.red); g2d.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } catch (Exception e) { LOGGER.error("Unable to highligh screenshot: " + e.getMessage()); } return this; }
/** * Method return 1 in case if y is lower than element, -1 if higher, 0 - if * 'y' within the element's range * * @param rect Rectangle * @param y int * @return int */ public int isLower(Rectangle rect, int y) { LOGGER.debug(String.format("isLower(): Rectangle: x - %d. y - %d. Width: %d, height: %d", rect.x, rect.y, rect.width, rect.height)); if (y > rect.y + rect.height) { return 1; } else if (y < rect.y) { return -1; } return 0; }
@Override public ExtendedWebElement getElementsByCoordinates(int x, int y) { String elementName = String.format("Element founded by x:%d - y:%d", x, y); WebDriver driver = DriverPool.getDriver(); List<WebElement> elements = getEndLevelElements(driver); WebElement tempElement; int index = 0; int isLower; Rectangle tempRect; while (elements.size() != 1) { index = (int) (Math.round(elements.size() / 2)); tempElement = elements.get(index); tempRect = getRect(tempElement); isLower = isLower(tempRect, y); LOGGER.debug("Is Lower: " + isLower); if (isInside(tempRect, x, y) || isLower == 0) { break; } if (isLower == 1) { elements = elements.subList(index, elements.size()); } else { elements = elements.subList(0, index); } } LOGGER.debug("Index: " + index); if (elements.size() == 1) { return generateExtenedElement(elements, driver, elementName); } return generateExtenedElement(checkBoundaryElements(elements, x, y, index), driver, elementName); }
/** * Method to check boundary elements since there is a chance that there are * some elements in the same 'y' range * * @param elements * @param x * @param y * @param index * @return */ private List<WebElement> checkBoundaryElements(List<WebElement> elements, int x, int y, int index) { LOGGER.debug(String.format("Index: %d.", index)); List<WebElement> elementsFirstPart = elements.subList(0, index); List<WebElement> elementsSecondPart = elements.subList(index, elements.size()); List<WebElement> elementsInside = new ArrayList<WebElement>(); WebElement element; Rectangle tempRect; for (int i = elementsFirstPart.size() - 1; i >= 0; i--) { element = elementsFirstPart.get(i); tempRect = getRect(element); if (isInside(tempRect, x, y)) { elementsInside.add(element); } else if (tempRect.y > y) { // stop validation as soon as 'y' coordinate will be out of // element's location break; } } for (int i = 0; i < elementsSecondPart.size(); i++) { element = elementsSecondPart.get(i); tempRect = getRect(element); if (isInside(tempRect, x, y)) { elementsInside.add(element); } else if (tempRect.y + tempRect.height < y) { // stop validation as soon as 'y' coordinate will be out of // element's location break; } } return elementsInside; }
@Override public Rectangle getRect() { ensureReferenceNotStaled(); return this.mElement.getRect(); }
@Override public Rectangle getRect() { return element.getRect(); }
public Rectangle getRect() { return new Rectangle( getLocation(), getSize() ); }
@Override public Rectangle findText( DeviceWebDriver webDriver, String text, Map<String, String> propertyMap ) { return null; }
@Override public Rectangle findImage( DeviceWebDriver webDriver, String imageName, Map<String, String> propertyMap ) { return null; }
@Override public Rectangle getRect() { return new Rectangle( location, size ); }
@Override public Rectangle getRect() { return this.mElement.getRect(); }
@Override public Rectangle getRect() { return parent.getRect(); }
@Override public Rectangle getRect() { return element().getRect(); }
@Override public Rectangle getRect() { webDriver.ensureSwitch(); return webElement.getRect(); }
@Override public Rectangle getRect() { return null; }
public boolean isInside(Rectangle rect, int x, int y) { return rect.x <= x && rect.x + rect.width >= x && rect.y <= y && rect.y + rect.height >= y; }
/** * Highlights rectangle on screenshot. * @param rect - of region to highlight * @return {@link ICapturable} instance */ ICapturable highlight(Rectangle rect);
/** * Method to generate rectangle for the element since current version of * appium driver throws unimplemented exception * * @param element WebElement * @return Rectangle */ public Rectangle getRect(WebElement element) { return new Rectangle(element.getLocation(), element.getSize()); }
public Rectangle findImage( DeviceWebDriver webDriver, String imageName, Map<String,String> propertyMap );
public Rectangle findText( DeviceWebDriver webDriver, String text, Map<String,String> propertyMap );
Rectangle getRect(WebLocator el);