public Region expandToContain(Region region) { int left = Math.min(this.left, region.left); int top = Math.min(this.top, region.top); int thisRight = this.left + this.width; int otherRight = region.left + region.width; int maxRight = Math.max(thisRight, otherRight); int width = maxRight - left; int thisBottom = this.top + this.height; int otherBottom = region.top + region.height; int maxBottom = Math.max(thisBottom, otherBottom); int height = maxBottom - top; return new Region(left, top, width, height); }
public Region expandToContain(Region region) { int left = Math.min(this.left, region.left); int top = Math.min(this.top, region.top); int thisRight = this.left + this.width; int otherRight = region.left + region.width; int maxRight = Math.max(thisRight, otherRight); int width = maxRight - left; int thisBottom = this.top + this.height; int otherBottom = region.top + region.height; int maxBottom = Math.max(thisBottom, otherBottom); int height = maxBottom - top; return new Region(left, top, width, height); }
@Override public Region getRegion() { return new Region(targetRegion.getLocation(), targetRegion.getSize(), CoordinatesType.CONTEXT_RELATIVE); } }, name, false, checkSettings);
/** * @param image The screenshot image. * @param location The top/left coordinates of the screenshot in context * relative coordinates type. */ public EyesImagesScreenshot(BufferedImage image, Location location) { super(image); ArgumentGuard.notNull(location, "location"); this.bounds = new Region(location, new RectangleSize(image.getWidth(), image.getHeight())); }
/** * Ctor. * * @param image The screenshot image. * @param location The top/left coordinates of the screenshot in context * relative coordinates type. */ public EyesImagesScreenshot(Logger logger, BufferedImage image, Location location) { super(logger, image); ArgumentGuard.notNull(location, "location"); this.bounds = new Region(location, new RectangleSize(image.getWidth(), image.getHeight())); }
private Region findBoundingBox(Dictionary<Integer, GetRegion> getRegions, ICheckSettings[] checkSettings, EyesScreenshot screenshot) { Region bBox = null; for (int i = 0; i < checkSettings.length; ++i) { GetRegion getRegion = getRegions.get(i); if (getRegion != null) { List<Region> regions = getRegion.getRegions(this, screenshot, true); for (Region region : regions) { if (bBox == null) { bBox = new Region(region); } else { bBox = bBox.expandToContain(region); } } } } return bBox; }
/** * Get an offset region. * @param dx The X axis offset. * @param dy The Y axis offset. * @return A region with an offset location. */ public Region offset(int dx, int dy) { return new Region(getLocation().offset(dx, dy), getSize(), getCoordinatesType()); }
/** * Get an offset region. * @param dx The X axis offset. * @param dy The Y axis offset. * @return A region with an offset location. */ public Region offset(int dx, int dy) { return new Region(getLocation().offset(dx, dy), getSize(), getCoordinatesType()); }
/** * 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()); }
/** * 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()); }
@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; }
/** * Creates a frame-like window screenshot, to be used for checkRegion screenshots. * @param logger A Logger instance. * @param driver The web driver used to get the screenshot. * @param image The actual screenshot image. * @param screenshotRegion The region of the screenshot. */ public EyesWebDriverScreenshot(Logger logger, EyesWebDriver driver, BufferedImage image, Region screenshotRegion) { super(logger, image); ArgumentGuard.notNull(driver, "driver"); ArgumentGuard.notNull(screenshotRegion, "screenshotRegion"); this.driver = driver; frameChain = driver.getFrameChain(); // The frame comprises the entire screenshot. screenshotType = ScreenshotType.ENTIRE_FRAME; currentFrameScrollPosition = new Location(0, 0); frameLocationInScreenshot = new Location(0, 0); frameWindow = new Region(new Location(0, 0), screenshotRegion.getSize()); regionWindow = new Region(screenshotRegion); }
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 Region getRegion() { Point p = targetElement.getLocation(); Dimension d = targetElement.getSize(); return new Region(p.getX(), p.getY(), d.getWidth(), d.getHeight(), CoordinatesType.CONTEXT_RELATIVE); } }, name, false, checkSettings);
/** * Converts a region's location coordinates with the {@code from} * coordinates type to the {@code to} coordinates type. * @param region The region which location's coordinates needs to be converted. * @param from The current coordinates type for {@code region}. * @param to The target coordinates type for {@code region}. * @return A new region which is the transformation of {@code region} to * the {@code to} coordinates type. */ public Region convertRegionLocation(Region region, CoordinatesType from, CoordinatesType to) { ArgumentGuard.notNull(region, "region"); if (region.isSizeEmpty()) { return new Region(region); } ArgumentGuard.notNull(from, "from"); ArgumentGuard.notNull(to, "to"); Location originalLocation = region.getLocation(); logger.verbose("original location: " + originalLocation); Location updatedLocation = convertLocation(originalLocation, from, to); logger.verbose("updated location: " + updatedLocation); return new Region(updatedLocation, region.getSize()); } }
/** * Adds a keyboard trigger. * @param element The element for which we sent keys. * @param text The trigger's text. */ public void addTextTrigger(WebElement element, String text) { if (getIsDisabled()) { logger.verbose(String.format("Ignoring '%s' (disabled)", text)); return; } ArgumentGuard.notNull(element, "element"); Point pl = element.getLocation(); Dimension ds = element.getSize(); Region elementRegion = new Region(pl.getX(), pl.getY(), ds.getWidth(), ds.getHeight()); addTextTrigger(elementRegion, text); }
@Override public List<Region> getRegions(EyesBase eyesBase, EyesScreenshot screenshot, boolean adjustLocation) { List<WebElement> elements = ((Eyes) eyesBase).getDriver().findElements(this.selector); List<Region> values = new ArrayList<>(elements.size()); for (WebElement element : elements) { Point locationAsPoint = element.getLocation(); Dimension size = element.getSize(); 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 Region(adjustedLocation, new RectangleSize(size.getWidth(), size.getHeight()), CoordinatesType.SCREENSHOT_AS_IS)); } return values; } }
@Override public List<Region> getRegions(EyesBase eyesBase, EyesScreenshot screenshot, boolean adjustLocation) { Point locationAsPoint = element.getLocation(); Dimension size = element.getSize(); 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()); } List<Region> value = new ArrayList<>(); value.add(new Region(adjustedLocation, new RectangleSize(size.getWidth(), size.getHeight()), CoordinatesType.SCREENSHOT_AS_IS)); return value; } }
return new Region(region);
private Region getViewportScrollBounds() { if (!getScrollToRegion()) { logger.log("WARNING: no region visibility strategy! returning an empty region!"); return Region.EMPTY; } FrameChain originalFrameChain = driver.getFrameChain().clone(); EyesTargetLocator switchTo = (EyesTargetLocator) driver.switchTo(); switchTo.frames(this.originalFC); ScrollPositionProvider spp = new ScrollPositionProvider(logger, jsExecutor, scrollRootElement); Location location; try { location = spp.getCurrentPosition(); } catch (EyesDriverOperationException e) { logger.log("WARNING: " + e.getMessage()); logger.log("Assuming position is 0,0"); location = new Location(0, 0); } Region viewportBounds = new Region(location, getViewportSize()); switchTo.frames(originalFrameChain); return viewportBounds; }