WebDriver adjustBrowserPosition(Config config, WebDriver driver) { if (config.browserPosition() != null) { log.info("Set browser position to " + config.browserPosition()); String[] coordinates = config.browserPosition().split("x"); int x = Integer.parseInt(coordinates[0]); int y = Integer.parseInt(coordinates[1]); Point target = new Point(x, y); Point current = driver.manage().window().getPosition(); if (!current.equals(target)) { driver.manage().window().setPosition(target); } } return driver; }
/** * It defines x and y coordinates. * This is offset from the upper left corner of the screen. * * @param xOffset is x value. * @param yOffset is y value. * @return self-reference */ public T withCoordinates(int xOffset, int yOffset) { coordinates = new Point(xOffset, yOffset); //noinspection unchecked return (T) this; }
/** * Transforms a map into {@link Point} object. * * @param map the source map. * @return {@link Point} object */ public static Point mapToPoint(Map<String, Object> map) { return new Point(toSeleniumCoordinate(map.get("x")), toSeleniumCoordinate(map.get("y"))); } }
/** * Method returns central coordinates of an element. * @return The instance of the {@link org.openqa.selenium.Point} */ public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
@Test public void tapOptionsShouldBuildProperly() { final Map<String, Object> actualOpts = tapOptions() .withPosition(point(new Point(0, 0))) .withTapsCount(2) .build(); final Map<String, Object> expectedOpts = new HashMap<>(); expectedOpts.put("x", 0); expectedOpts.put("y", 0); expectedOpts.put("count", 2); assertThat(actualOpts.entrySet(), everyItem(isIn(expectedOpts.entrySet()))); assertThat(expectedOpts.entrySet(), everyItem(isIn(actualOpts.entrySet()))); }
@Test public void invalidOptionsArgumentsShouldFailOnAltering() { final List<Runnable> invalidOptions = new ArrayList<>(); invalidOptions.add(() -> waitOptions(ofMillis(-1))); invalidOptions.add(() -> new ElementOption().withCoordinates(new Point(0, 0)).withElement(null)); invalidOptions.add(() -> new WaitOptions().withDuration(null)); invalidOptions.add(() -> tapOptions().withTapsCount(-1)); invalidOptions.add(() -> longPressOptions().withDuration(null)); invalidOptions.add(() -> longPressOptions().withDuration(ofMillis(-1))); for (Runnable item : invalidOptions) { assertThat(item, failsWith(RuntimeException.class)); } }
private Point getCoordForColRow(int col, int row) { int adjustLeft = CELL_WIDTH / 2; int adjustTop = CELL_HEIGHT / 2; int destinationY = (row * CELL_HEIGHT) - adjustTop; int destinationX = (col * CELL_WIDTH) - adjustLeft; return new Point(destinationX, destinationY); } }
window.setSize(d); Point p = new Point(50, 50); window.setPosition(p);
private void calculateCoordinates() { int relativeX = x - scrollTo.getX(); int relativeY = y - scrollTo.getY(); elementCoordinates = new Point(relativeX, relativeY); } }
private void calculateScroll() { int deltaX = Math.max(0, document.getWidth() - viewport.getWidth()); int scrollX = Math.min(x, deltaX); int deltaY = Math.max(0, document.getHeight() - viewport.getHeight()); int scrollY = Math.min(y, deltaY); scrollTo = new Point(scrollX, scrollY); }
public void mouseMove(Coordinates where, long xOffset, long yOffset) { Point p = getPoint(where, "mouse move"); // We can't compare against Integer.MAX_VALUE and throw because this method isn't defined as // able to throw an Exception. Weird things will just happen here... int xO = (int) xOffset; int yO = (int) yOffset; lastMousePosition = new Point(p.x + xO, p.y + yO); exec.mouseAction(p.x + xO, p.y + yO); }
public CachedHtmlElement(Element jsoupElement) { location = new Point(0, 0); size = new Dimension(0, 0); rectangle = new Rectangle(location, size); selected = false; cachedElement = jsoupElement; realElement = null; }
@Override public Point getLocation() { assertElementNotStale(); try { return new Point(readAndRound("left"), readAndRound("top")); } catch (Exception e) { throw new WebDriverException("Cannot determine size of element", e); } }
@Override public void swipeLeft(WebElement webElement) { logger.entering(webElement); Point point = webElement.getLocation(); Dimension dimension = webElement.getSize(); Point start = new Point(point.getX() + dimension.getWidth() - 1, point.getY()); Point end = new Point(point.getX(), point.getY()); performSwipeAction(start, end); logger.exiting(); }
@Override public void swipeRight(WebElement webElement) { logger.entering(webElement); Point point = webElement.getLocation(); Dimension dimension = webElement.getSize(); Point start = new Point(point.getX(), point.getY()); Point end = new Point(point.getX() + dimension.getWidth() - 1, point.getY()); performSwipeAction(start, end); logger.exiting(); }
@Override public void swipeUp(WebElement webElement) { logger.entering(webElement); Point point = webElement.getLocation(); Dimension dimension = webElement.getSize(); Point start = new Point(point.getX(), point.getY() + dimension.getHeight() - 1); Point end = new Point(point.getX(), point.getY()); performSwipeAction(start, end); logger.exiting(); }
protected void resizeBrowserTo(WebDriver driver, int height, int width) { LOGGER.info("Setting browser dimensions to {}/{}", height, width); driver.manage().window().setSize(new Dimension(width, height)); driver.manage().window().setPosition(new Point(0,0)); }
/** * Method returns central coordinates of an element. * @return The instance of the {@link org.openqa.selenium.Point} */ public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
@Override public void redimension(WebDriver driver) { try { driver.manage().window().setSize(new Dimension(width, height)); driver.manage().window().setPosition(new Point(0, 0)); } catch (WebDriverException couldNotResizeScreen) { if (couldNotResizeScreen.getMessage().contains("Invalid requested size")) { driver.manage().window().maximize(); } } } }
private void setSize(Dimension dimension) { support.getDriver().manage().window().setPosition(new Point(0,0)); support.getDriver().manage().window().setSize(dimension); // _not_ a mistake... don't ask support.getDriver().manage().window().setSize(dimension); }