@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; }
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; }
/** * 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()); }
@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()); }
if (actualViewportSize.equals(requiredSize)) { logger.verbose("Required size already set."); return; if (actualViewportSize.equals(requiredSize)) { return; logger.verbose("Current viewport size: " + actualViewportSize); if (actualViewportSize.equals(requiredSize)) { return; if (requiredBrowserSize.equals(lastRequiredBrowserSize)) { logger.verbose("Browser size is as required but viewport size does not match!"); logger.verbose("Browser size: " + requiredBrowserSize + " , Viewport size: " + actualViewportSize); logger.verbose("Current viewport size: " + actualViewportSize); if (actualViewportSize.equals(requiredSize)) { return;
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; }