public int getWidth() { return viewportSize.getWidth(); }
/** * @param size The updated size of the region. */ public void setSize(RectangleSize size) { width = size.getWidth(); height = size.getHeight(); }
/** * @param size The updated size of the region. */ public void setSize(RectangleSize size) { width = size.getWidth(); height = size.getHeight(); }
public Response call() { Invocation.Builder invocationBuilder = defaultEndPoint.path(autSessionId) .request(MediaType.APPLICATION_JSON); return invocationBuilder.put(Entity.json("{\"action\": \"setSizeStart\", \"size\":{\"width\": " + size.getWidth() + ", \"height\": " + size.getHeight() + "}}")); } });
public Response call() { Invocation.Builder invocationBuilder = defaultEndPoint.path(autSessionId) .request(MediaType.APPLICATION_JSON); return invocationBuilder.put(Entity.json("{\"action\": \"setSizeStart\", \"size\":{\"width\": " + size.getWidth() + ", \"height\": " + size.getHeight() + "}}")); } });
public Response call() { Invocation.Builder invocationBuilder = defaultEndPoint.path(autSessionId) .request(MediaType.APPLICATION_JSON); return invocationBuilder.put(Entity.json("{\"action\": \"setSizeStart\", \"size\":{\"width\": " + size.getWidth() + ", \"height\": " + size.getHeight() + "}}")); } });
private Region findBoundingBox(Dictionary<Integer, GetRegion> getRegions, ICheckSettings[] checkSettings) { RectangleSize rectSize = getViewportSize(); logger.verbose("rectSize: " + rectSize); EyesScreenshot screenshot = new EyesWebDriverScreenshot(logger, driver, new BufferedImage(rectSize.getWidth(), rectSize.getHeight(), BufferedImage.TYPE_INT_RGB)); return findBoundingBox(getRegions, checkSettings, screenshot); }
@Override public void setViewportSize(RectangleSize size) { ArgumentGuard.notNull(size, "size"); this.viewportSize = new RectangleSize(size.getWidth(), size.getHeight()); }
public ClientResponse call() { WebResource.Builder invocationBuilder = defaultEndPoint.path(autSessionId) .type(MediaType.APPLICATION_JSON); return invocationBuilder.put(ClientResponse.class, "{\"action\": \"setSizeStart\", \"size\":{\"width\": " + size.getWidth() + ", \"height\": " + size.getHeight() + "}}"); } });
/** * Set the viewport size. * @param size The required viewport size. */ @Override public void setViewportSize(RectangleSize size) { ArgumentGuard.notNull(size, "size"); viewportSizeHandler.set(new RectangleSize(size.getWidth(), size.getHeight())); }
ArgumentGuard.notNull(containerRegion, "containerRegion"); ArgumentGuard.notNull(maxSubRegionSize, "maxSubRegionSize"); ArgumentGuard.greaterThanZero(maxSubRegionSize.getWidth(), "maxSubRegionSize.getWidth()"); ArgumentGuard.greaterThanZero(maxSubRegionSize.getHeight(), int currentRight = currentLeft + maxSubRegionSize.getWidth(); if (currentRight > right) { currentRight = right; currentWidth, currentHeight, currentType)); currentLeft += maxSubRegionSize.getWidth();
@SuppressWarnings("UnusedReturnValue") public static boolean setBrowserSizeByViewportSize(Logger logger, WebDriver driver, RectangleSize actualViewportSize, RectangleSize requiredViewportSize) { Dimension browserSize = driver.manage().window().getSize(); logger.verbose("Current browser size: " + browserSize); RectangleSize requiredBrowserSize = new RectangleSize( browserSize.width + (requiredViewportSize.getWidth() - actualViewportSize.getWidth()), browserSize.height + (requiredViewportSize.getHeight() - actualViewportSize.getHeight())); return setBrowserSize(logger, driver, requiredBrowserSize); }
/** * Set the scale ratio based on the given image. * @param imageToScaleWidth The width of the image to scale, used for calculating the scale ratio. */ public void updateScaleRatio(int imageToScaleWidth) { int viewportWidth = viewportSize.getWidth(); int dcesWidth = topLevelContextEntireSize.getWidth(); // If the image's width is the same as the viewport's width or the // top level context's width, no scaling is necessary. if (((imageToScaleWidth >= viewportWidth - ALLOWED_VS_DEVIATION) && (imageToScaleWidth <= viewportWidth + ALLOWED_VS_DEVIATION)) || ((imageToScaleWidth >= dcesWidth - ALLOWED_DCES_DEVIATION) && imageToScaleWidth <= dcesWidth + ALLOWED_DCES_DEVIATION)) { logger.verbose("Image is already scaled correctly."); scaleRatio = 1; } else { logger.verbose("Calculating the scale ratio.."); scaleRatio = 1 / devicePixelRatio; if (isMobileDevice) { logger.verbose("Mobile device, so using 2 step calculation for scale ratio..."); logger.verbose("Scale ratio based on DRP: " + scaleRatio); scaleRatio = getScaleRatioToViewport(viewportWidth, imageToScaleWidth, scaleRatio); } logger.verbose("Final scale ratio: " + scaleRatio); } } }
public Region(Location location, RectangleSize size, CoordinatesType coordinatesType) { ArgumentGuard.notNull(location, "location"); ArgumentGuard.notNull(size, "size"); this.left = location.getX(); this.top = location.getY(); this.width = size.getWidth(); this.height = size.getHeight(); this.coordinatesType = coordinatesType; }
public Region(Location location, RectangleSize size) { ArgumentGuard.notNull(location, "location"); ArgumentGuard.notNull(size, "size"); left = location.getX(); top = location.getY(); width = size.getWidth(); height = size.getHeight(); }
public Region(Location location, RectangleSize size, CoordinatesType coordinatesType) { ArgumentGuard.notNull(location, "location"); ArgumentGuard.notNull(size, "size"); this.left = location.getX(); this.top = location.getY(); this.width = size.getWidth(); this.height = size.getHeight(); this.coordinatesType = coordinatesType; }
private ScreenshotType updateScreenshotType(ScreenshotType screenshotType, BufferedImage image) { if (screenshotType == null) { RectangleSize viewportSize = driver.getEyes().getViewportSize(); boolean scaleViewport = driver.getEyes().shouldStitchContent(); if (scaleViewport) { double pixelRatio = driver.getEyes().getDevicePixelRatio(); viewportSize = viewportSize.scale(pixelRatio); } if (image.getWidth() <= viewportSize.getWidth() && image.getHeight() <= viewportSize.getHeight()) { screenshotType = ScreenshotType.VIEWPORT; } else { screenshotType = ScreenshotType.ENTIRE_FRAME; } } return screenshotType; }
@Override public List<FloatingMatchSettings> getRegions(EyesBase eyesBase, EyesScreenshot screenshot) { List<WebElement> elements = ((Eyes) eyesBase).getDriver().findElements(this.selector); List<FloatingMatchSettings> values = new ArrayList<>(); Logger logger = eyesBase.getLogger(); for (WebElement element : elements) { Point locationAsPoint = element.getLocation(); RectangleSize size = EyesSeleniumUtils.getElementVisibleSize(logger, element); Location adjustedLocation; if (screenshot != null) { // Element's coordinates are context relative, so we need to convert them first. adjustedLocation = screenshot.getLocationInScreenshot(new Location(locationAsPoint.getX(), locationAsPoint.getY()), CoordinatesType.CONTEXT_RELATIVE); } else { adjustedLocation = new Location(locationAsPoint.getX(), locationAsPoint.getY()); } values.add(new FloatingMatchSettings(adjustedLocation.getX(), adjustedLocation.getY(), size.getWidth(), size.getHeight(), maxUpOffset, maxDownOffset, maxLeftOffset, maxRightOffset)); } return values; } }
public static boolean setBrowserSize(Logger logger, WebDriver driver, RectangleSize requiredSize) { final int SLEEP = 1000; int retriesLeft = 3; Dimension dRequiredSize = new Dimension(requiredSize.getWidth(), requiredSize.getHeight()); Dimension dCurrentSize; RectangleSize currentSize; do { logger.verbose("Trying to set browser size to: " + requiredSize); driver.manage().window().setSize(dRequiredSize); GeneralUtils.sleep(SLEEP); dCurrentSize = driver.manage().window().getSize(); currentSize = new RectangleSize(dCurrentSize.getWidth(), dCurrentSize.getHeight()); logger.verbose("Current browser size: " + currentSize); } while (--retriesLeft > 0 && !currentSize.equals(requiredSize)); return currentSize == requiredSize; }
/** * Use this method only if you made a previous call to {@link #open * (WebDriver, String, String)} or one of its variants. * <p> * {@inheritDoc} */ @Override protected void setViewportSize(RectangleSize size) { if (viewportSizeHandler instanceof ReadOnlyPropertyHandler) { logger.verbose("Ignored (viewport size given explicitly)"); return; } if (!EyesSeleniumUtils.isMobileDevice(driver)) { FrameChain originalFrame = driver.getFrameChain(); driver.switchTo().defaultContent(); try { EyesSeleniumUtils.setViewportSize(logger, driver, size); effectiveViewport = new Region(Location.ZERO, size); } catch (EyesException e1) { // Just in case the user catches this error ((EyesTargetLocator) driver.switchTo()).frames(originalFrame); throw new TestFailedException("Failed to set the viewport size", e1); } ((EyesTargetLocator) driver.switchTo()).frames(originalFrame); } viewportSizeHandler.set(new RectangleSize(size.getWidth(), size.getHeight())); }