public static void setConfiguredScreenSize(Dimension configuredScreenSize) { if (configuredScreenSize.getWidth() <= 0 || configuredScreenSize.getHeight() <= 0) { DockeredSeleniumStarter.configuredScreenSize = DEFAULT_SCREEN_SIZE; } else { DockeredSeleniumStarter.configuredScreenSize = configuredScreenSize; } }
public static Dimension getConfiguredScreenSize() { if (configuredScreenSize == null || configuredScreenSize.getWidth() <= 0 || configuredScreenSize.getHeight() <= 0) { return DEFAULT_SCREEN_SIZE; } return DockeredSeleniumStarter.configuredScreenSize; }
private boolean isScreenResolutionMatching(Map<String, Object> nodeCapability, Map<String, Object> requestedCapability) { boolean screenResolutionCapabilityMatches = true; boolean screenSizeCapabilityIsRequested = false; List<String> screenResolutionNames = Arrays.asList(ZaleniumCapabilityType.SCREEN_RESOLUTION, ZaleniumCapabilityType.RESOLUTION, ZaleniumCapabilityType.SCREEN_RESOLUTION_DASH); for (String screenResolutionName : screenResolutionNames) { if (requestedCapability.containsKey(screenResolutionName)) { screenSizeCapabilityIsRequested = true; screenResolutionCapabilityMatches = nodeCapability.containsKey(screenResolutionName) && requestedCapability.get(screenResolutionName).equals(nodeCapability.get(screenResolutionName)); } } /* This node has a screen size different from the default/configured one, and no special screen size was requested... then this validation prevents requests using nodes that were created with specific screen sizes */ String defaultScreenResolution = String.format("%sx%s", DockeredSeleniumStarter.getConfiguredScreenSize().getWidth(), DockeredSeleniumStarter.getConfiguredScreenSize().getHeight()); String nodeScreenResolution = nodeCapability.get(ZaleniumCapabilityType.SCREEN_RESOLUTION).toString(); if (!screenSizeCapabilityIsRequested && !defaultScreenResolution.equalsIgnoreCase(nodeScreenResolution)) { screenResolutionCapabilityMatches = false; } return screenResolutionCapabilityMatches; }
envVars.put("NOVNC_PORT", String.valueOf(noVncPort)); envVars.put("VNC_PORT", String.valueOf(vncPort)); envVars.put("SCREEN_WIDTH", String.valueOf(screenSize.getWidth())); envVars.put("SCREEN_HEIGHT", String.valueOf(screenSize.getHeight())); envVars.put("TZ", timeZone.getID());
@Override public Dimension getScreenSize() { org.openqa.selenium.Dimension windowSize = driver.manage().window().getSize(); return new Dimension(windowSize.getWidth(), windowSize.getHeight()); }
private BufferedImage takeScreenshotAsImage(WebDriver webdriver, WebElement element) { if (!(webdriver instanceof TakesScreenshot)) { log.warning("Cannot take screenshot because browser does not support screenshots"); return null; } byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES); Point elementLocation = element.getLocation(); try { BufferedImage img = ImageIO.read(new ByteArrayInputStream(screen)); int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight(); if (elementWidth > img.getWidth()) { elementWidth = img.getWidth() - elementLocation.getX(); } if (elementHeight > img.getHeight()) { elementHeight = img.getHeight() - elementLocation.getY(); } return img.getSubimage(elementLocation.getX(), elementLocation.getY(), elementWidth, elementHeight); } catch (IOException e) { log.log(SEVERE, "Failed to take screenshot of " + element, e); return null; } catch (RasterFormatException e) { log.warning("Cannot take screenshot because element is not displayed on current screen position"); return null; } }
@Override public Rect findArea(WebPageElement webPageElement) { WebElement webElement = webPageElement.getWebElement(); Point location = webElement.getLocation(); Dimension size = webElement.getSize(); return new Rect(location.getX(), location.getY(), size.getWidth(), size.getHeight()); } }),
int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight(); if (elementWidth > iframeWidth) {
@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(); }
@Override public void afterWindowChangeSize(WebDriver driver, WebDriver.Window window, Dimension targetSize) { messages.add("Externally defined listener: Size of the window has " + "been changed. The height is " + targetSize.getHeight() + " the width is " + targetSize.getWidth()); }
@Override public void beforeWindowChangeSize(WebDriver driver, WebDriver.Window window, Dimension targetSize) { messages.add("Attempt to change size of the window. The height is " + targetSize.getHeight() + " the width is " + targetSize.getWidth()); }
@Override public void beforeWindowChangeSize(WebDriver driver, WebDriver.Window window, Dimension targetSize) { messages.add("Externally defined listener: Attempt to change size of the window. " + "The height is " + targetSize.getHeight() + " the width is " + targetSize.getWidth()); }
@Override public void afterWindowChangeSize(WebDriver driver, WebDriver.Window window, Dimension targetSize) { messages.add("Size of the window has been changed. The height is " + targetSize.getHeight() + " the width is " + targetSize.getWidth()); }
/** * 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); }
public JSONObject toJson() throws JSONException { JSONObject json = new JSONObject(); json.put("profileName", getProfileName()); json.put("width", getResolution().getWidth()); json.put("height", getResolution().getHeight()); json.put("ppi", getPPI()); json.put("ime", getIME().toString().toLowerCase()); json.put("userAgent", getUserAgent()); return json; }
@Override public int getRight() { return getLeft() + getElement().getSize().getWidth(); }
/** * Tap with TouchAction by the center of element * * @param element ExtendedWebElement */ default public void tap(ExtendedWebElement element) { Point point = element.getLocation(); Dimension size = helper.performIgnoreException(() -> element.getSize()); tap(point.getX() + size.getWidth() / 2, point.getY() + size.getHeight() / 2); }
@Override public void setSize(Dimension targetSize) { WebWindow topWindow = getCurrentWindow().getTopWindow(); int width = targetSize.getWidth(); if (width < SCROLLBAR_WIDTH) width = SCROLLBAR_WIDTH; topWindow.setOuterWidth(width); topWindow.setInnerWidth(width - SCROLLBAR_WIDTH); int height = targetSize.getHeight(); if (height < HEADER_HEIGHT) height = HEADER_HEIGHT; topWindow.setOuterHeight(height); topWindow.setInnerHeight(height - HEADER_HEIGHT); }
/** * Tap with TouchAction by the center of element * * @param element ExtendedWebElement */ public static void tap(ExtendedWebElement element) { Point point = element.getLocation(); Dimension size = helper.performIgnoreException(() -> element.getSize()); tap(point.getX() + size.getWidth() / 2, point.getY() + size.getHeight() / 2); }