@Override public void setViewportSize(RectangleSize size) { ArgumentGuard.notNull(size, "size"); this.viewportSize = new RectangleSize(size.getWidth(), size.getHeight()); }
RectangleSize requiredSize = new RectangleSize(size.getWidth(), size.getHeight()); RectangleSize actualViewportSize = getViewportSize((JavascriptExecutor) driver); logger.verbose("Initial viewport size:" + actualViewportSize); if (actualViewportSize.equals(requiredSize)) { logger.verbose("Required size already set."); return; if (actualViewportSize.equals(requiredSize)) { return; if (actualViewportSize.equals(requiredSize)) { return; int widthDiff = actualViewportSize.getWidth() - requiredSize.getWidth(); int widthStep = widthDiff > 0 ? -1 : 1; // -1 for smaller size, 1 for larger int heightDiff = actualViewportSize.getHeight() - requiredSize.getHeight(); int heightStep = heightDiff > 0 ? -1 : 1; RectangleSize browserSize = new RectangleSize(dBrowserSize.getWidth(), dBrowserSize.getHeight()); actualViewportSize.getWidth() != requiredSize.getWidth()) { currWidthChange += widthStep; actualViewportSize.getHeight() != requiredSize.getHeight()) { currHeightChange += heightStep; RectangleSize requiredBrowserSize = new RectangleSize(browserSize.getWidth() + currWidthChange,
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; }
/** * * @return The (top,left) position of the current region. */ public RectangleSize getSize() { return new RectangleSize(width, height); }
public int getWidth() { return viewportSize.getWidth(); }
public int getHeight() { return viewportSize.getHeight(); }
public EyesWebDriverScreenshot getSubScreenshotForRegion(Region region, boolean throwIfClipped) { logger.verbose(String.format("getSubScreenshot([%s], %b)", region, throwIfClipped)); ArgumentGuard.notNull(region, "region"); // We calculate intersection based on as-is coordinates. Region asIsSubScreenshotRegion = getIntersectedRegion(region, CoordinatesType.SCREENSHOT_AS_IS); if (asIsSubScreenshotRegion.isEmpty() || (throwIfClipped && !asIsSubScreenshotRegion.getSize().equals( region.getSize()))) { throw new OutOfBoundsException(String.format( "Region [%s] is out of screenshot bounds [%s]", region, frameWindow)); } BufferedImage subScreenshotImage = ImageUtils.getImagePart(image, asIsSubScreenshotRegion); EyesWebDriverScreenshot result = new EyesWebDriverScreenshot(logger, driver, subScreenshotImage, new Region(region.getLocation(), new RectangleSize(subScreenshotImage.getWidth(), subScreenshotImage.getHeight()))); logger.verbose("Done!"); return result; }
@Override public EyesWebDriverScreenshot getSubScreenshot(Region region, boolean throwIfClipped) { logger.verbose(String.format("getSubScreenshot([%s], %b)", region, throwIfClipped)); ArgumentGuard.notNull(region, "region"); // We calculate intersection based on as-is coordinates. Region asIsSubScreenshotRegion = getIntersectedRegion(region, CoordinatesType.SCREENSHOT_AS_IS); if (asIsSubScreenshotRegion.isSizeEmpty() || (throwIfClipped && !asIsSubScreenshotRegion.getSize().equals( region.getSize()))) { throw new OutOfBoundsException(String.format( "Region [%s] is out of screenshot bounds [%s]", region, frameWindow)); } BufferedImage subScreenshotImage = ImageUtils.getImagePart(image, asIsSubScreenshotRegion); EyesWebDriverScreenshot result = new EyesWebDriverScreenshot(logger, driver, subScreenshotImage, new Region(region.getLeft(), region.getTop(), subScreenshotImage.getWidth(), subScreenshotImage.getHeight())); logger.verbose("Done!"); return result; }
/** * Get a region which is a scaled version of the current region. * IMPORTANT: This also scales the LOCATION(!!) of the region (not just its size). * @param scaleRatio The ratio by which to scale the region. * @return A new region which is a scaled version of the current region. */ public Region scale(double scaleRatio) { return new Region(getLocation().scale(scaleRatio), getSize().scale(scaleRatio), getCoordinatesType()); }
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; }
public RenderBrowserInfo(int width, int height, RenderingConfiguration.BrowserType browserType, EmulationInfo emulationInfo, String baselineEnvName) { this.baselineEnvName = baselineEnvName; this.viewportSize = new RectangleSize(width, height); this.browserType = browserType; this.emulationInfo = emulationInfo; }
/** * 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); } } }
/** * Get sub screenshot. * @param region The region for which we should get the sub screenshot. * @param throwIfClipped Throw an EyesException if the region is not fully contained in the screenshot. * @return Sub screenshot. */ @Override public EyesScreenshot getSubScreenshot(Region region, boolean throwIfClipped) { ArgumentGuard.notNull(region, "region"); // We want to get the sub-screenshot in as-is coordinates type. Region subScreenshotRegion = getIntersectedRegion(region, CoordinatesType.SCREENSHOT_AS_IS); if (subScreenshotRegion.isSizeEmpty() || (throwIfClipped && !subScreenshotRegion.getSize().equals(region.getSize()))) { throw new OutOfBoundsException(String.format( "Region [%s] is out of screenshot bounds [%s]", region, bounds)); } BufferedImage subScreenshotImage = ImageUtils.getImagePart(image, subScreenshotRegion); // Notice that we need the bounds-relative coordinates as parameter // for new sub-screenshot. Region relativeSubScreenshotRegion = convertRegionLocation(subScreenshotRegion, CoordinatesType.SCREENSHOT_AS_IS, CoordinatesType.CONTEXT_RELATIVE); return new EyesImagesScreenshot(logger, subScreenshotImage, relativeSubScreenshotRegion.getLocation()); }
/** * Get a region which is a scaled version of the current region. * IMPORTANT: This also scales the LOCATION(!!) of the region (not just its size). * @param scaleRatio The ratio by which to scale the region. * @return A new region which is a scaled version of the current region. */ public Region scale(double scaleRatio) { return new Region(getLocation().scale(scaleRatio), getSize().scale(scaleRatio), getCoordinatesType()); }
/** * 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())); }
public RenderBrowserInfo(int width, int height, RenderingConfiguration.BrowserType browserType, String baselineEnvName) { this.baselineEnvName = baselineEnvName; this.viewportSize = new RectangleSize(width, height); this.browserType = browserType; }
@Override public EyesScreenshot getSubScreenshot(Region region, CoordinatesType coordinatesType, boolean throwIfClipped) { ArgumentGuard.notNull(region, "region"); ArgumentGuard.notNull(coordinatesType, "coordinatesType"); // We want to get the sub-screenshot in as-is coordinates type. Region subScreenshotRegion = getIntersectedRegion(region, coordinatesType, CoordinatesType.SCREENSHOT_AS_IS); if (subScreenshotRegion.isEmpty() || (throwIfClipped && !subScreenshotRegion.getSize().equals(region.getSize()))) { throw new OutOfBoundsException(String.format( "Region [%s, (%s)] is out of screenshot bounds [%s]", region, coordinatesType, bounds)); } BufferedImage subScreenshotImage = ImageUtils.getImagePart(image, subScreenshotRegion); // Notice that we need the bounds-relative coordinates as parameter // for new sub-screenshot. Region relativeSubScreenshotRegion = convertRegionLocation(subScreenshotRegion, CoordinatesType.SCREENSHOT_AS_IS, CoordinatesType.CONTEXT_RELATIVE); return new EyesImagesScreenshot(subScreenshotImage, relativeSubScreenshotRegion.getLocation()); }