public static void autoAdjustBrowserWindowSizeToFitViewport(WebDriver driver, int width, int height) { driver.manage().window().setSize(new org.openqa.selenium.Dimension(width, height)); Dimension viewport = getViewportArea(driver); if (viewport.getWidth() < width) { int delta = (int) (width - viewport.getWidth()); driver.manage().window().setSize(new org.openqa.selenium.Dimension(width + delta, height)); } }
/** * 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); }
private static WebDriver maximizeScreen(WebDriver driver) { java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Point position = new Point(0, 0); driver.manage().window().setPosition(position); Dimension maximizedScreenSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); driver.manage().window().setSize(maximizedScreenSize); return driver; }
@Override public String toString() { return String.format("#%s element. Expected size: [%s, %s], Actual size: [%s, %s]", element.getAttribute("id"), width, height, element.getSize().getWidth(), element.getSize().getHeight() ); } };
@VisibleForTesting public static void readConfigurationFromEnvVariables() { int sWidth = env.getIntEnvVariable(ZALENIUM_SCREEN_WIDTH, DEFAULT_SCREEN_SIZE.getWidth()); int sHeight = env.getIntEnvVariable(ZALENIUM_SCREEN_HEIGHT, DEFAULT_SCREEN_SIZE.getHeight()); setConfiguredScreenSize(new Dimension(sWidth, sHeight)); String tz = env.getStringEnvVariable(ZALENIUM_TZ, DEFAULT_TZ.getID()); setConfiguredTimeZone(tz); String containerN = env.getStringEnvVariable(ZALENIUM_CONTAINER_NAME, DEFAULT_ZALENIUM_CONTAINER_NAME); setContainerName(containerN); String seleniumImageName = env.getStringEnvVariable(ZALENIUM_SELENIUM_IMAGE_NAME, DEFAULT_DOCKER_SELENIUM_IMAGE); setDockerSeleniumImageName(seleniumImageName); String seleniumNodeParams = env.getStringEnvVariable(SELENIUM_NODE_PARAMS, DEFAULT_SELENIUM_NODE_PARAMS); setSeleniumNodeParameters(seleniumNodeParams); setBrowserTimeout(env.getIntEnvVariable("SEL_BROWSER_TIMEOUT_SECS", DEFAULT_SEL_BROWSER_TIMEOUT_SECS)); sendAnonymousUsageInfo = env.getBooleanEnvVariable("ZALENIUM_SEND_ANONYMOUS_USAGE_INFO", false); addProxyVars(); }
private Point getCurrentLocation() { Point inViewPort = null; switcher.switchTo(getFramePath()); try { Dimension size = webElement.getSize(); inViewPort = ((Locatable) webElement).getCoordinates().inViewPort() .moveBy(size.getWidth() / 2, size.getHeight() / 2); } finally { switcher.switchBack(); } return inViewPort; }
public void mouseOut(String locator) { LOG.keywordAppender().appendLocator(locator); WebElement el = finder.find(locator); if (el == null) { throw new IllegalStateException(String.format("ERROR: Element %s not found", locator)); } Dimension size = el.getSize(); int offsetX = (size.getWidth() / 2 ) + 1; int offsetY = (size.getHeight() / 2 ) + 1; new Actions(driver).moveToElement(el).moveByOffset(offsetX, offsetY).perform(); }
public EditIssueTypeSchemePage moveFromAvailableToAboveSelected(final String availableIssueType, final String selectedIssueType) { WebElement source = getIssueTypeListItemFromAvailableOptions(availableIssueType); WebElement target = getIssueTypeListItemFromSelectedOptions(selectedIssueType); final double offset = target.getSize().getHeight() * DROP_TARGET_RATIO; dragAndDropWithOffset(source, target, (int) -offset); return this; }
public Dimension getSize() { if(is_not_null(_webElement)) { Dimension value = _webElement.getSize(); info("Element '" + super.name() + "' - Dimention is '" + value + "'"); return value; } else { info("Element '" + super.name() + "' - has a null _webelement, cannot do getSize()"); } return new Dimension(0, 0); }
private Dimension getConfiguredScreenResolutionFromCapabilities(Map<String, Object> requestedCapability) { Dimension screenSize = getConfiguredScreenSize(); List<String> screenResolutionNames = Arrays.asList(ZaleniumCapabilityType.SCREEN_RESOLUTION, ZaleniumCapabilityType.SCREEN_RESOLUTION_NO_PREFIX, ZaleniumCapabilityType.RESOLUTION, ZaleniumCapabilityType.RESOLUTION_NO_PREFIX, ZaleniumCapabilityType.SCREEN_RESOLUTION_DASH, ZaleniumCapabilityType.SCREEN_RESOLUTION_DASH_NO_PREFIX); for (String screenResolutionName : screenResolutionNames) { if (requestedCapability.containsKey(screenResolutionName)) { String screenResolution = requestedCapability.get(screenResolutionName).toString(); try { int screenWidth = Integer.parseInt(screenResolution.split("x")[0]); int screenHeight = Integer.parseInt(screenResolution.split("x")[1]); if (screenWidth > 0 && screenHeight > 0) { screenSize = new Dimension(screenWidth, screenHeight); } else { LOGGER.debug("One of the values provided for screenResolution is negative, " + "defaults will be used. Passed value -> " + screenResolution); } } catch (Exception e) { LOGGER.debug("Values provided for screenResolution are not valid integers or " + "either the width or the height is missing, defaults will be used. Passed value -> " + screenResolution); } } } return screenSize; }
@Override public FluentWebElementAssert hasDimension(Dimension dimension) { Dimension actualSize = actual.size(); if (!actualSize.equals(dimension)) { failWithMessage("The element does not have the same size: " + dimension.toString() + ". Actual size found : " + actualSize.toString()); } return this; }