Exemplo n.º 1
0
        private Region GetRegionInScreenshot_(Region region, Bitmap image, double pixelRatio)
        {
            if (region.IsSizeEmpty)
            {
                return(region);
            }

            logger_.Verbose("Creating screenshot object...");
            // We need the screenshot to be able to convert the region to screenshot coordinates.
            EyesScreenshot screenshot = getEyesScreenshot_(image);

            logger_.Verbose("Getting region in screenshot...");

            // Region regionInScreenshot = screenshot.convertRegionLocation(regionProvider.getRegion(), regionProvider.getCoordinatesType(), CoordinatesType.SCREENSHOT_AS_IS);
            Region regionInScreenshot = screenshot.GetIntersectedRegion(region, CoordinatesTypeEnum.SCREENSHOT_AS_IS);

            Size scaledImageSize = new Size((int)Math.Round(image.Width / pixelRatio), (int)Math.Round(image.Height / pixelRatio));

            regionInScreenshot = sizeAdjuster_.AdjustRegion(regionInScreenshot, scaledImageSize);

            logger_.Verbose("Region in screenshot: {0}", regionInScreenshot);
            regionInScreenshot = regionInScreenshot.Scale(pixelRatio);
            logger_.Verbose("Scaled region: {0}", regionInScreenshot);

            regionInScreenshot = regionPositionCompensation_.CompensateRegionPosition(regionInScreenshot, pixelRatio);

            // Handling a specific case where the region is actually larger than
            // the screenshot (e.g., when body width/height are set to 100%, and
            // an internal div is set to value which is larger than the viewport).
            regionInScreenshot.Intersect(new Region(0, 0, image.Width, image.Height));
            logger_.Verbose("Region after intersect: {0}", regionInScreenshot);
            return(regionInScreenshot);
        }
Exemplo n.º 2
0
        public EyesWebDriverScreenshot(Logger logger, EyesWebDriver driver, Bitmap image, ScreenshotTypeEnum?screenshotType, Point?frameLocationInScreenshot)
            : base(image)
        {
            ArgumentGuard.NotNull(logger, nameof(logger));
            ArgumentGuard.NotNull(driver, nameof(driver));
            logger_ = logger;
            driver_ = driver;

            logger_.Verbose("enter");

            UpdateScreenshotType_(screenshotType, image);

            IPositionProvider positionProvider;

            if (frameLocationInScreenshot == null || frameLocationInScreenshot.Value.IsEmpty)
            {
                IWebElement frameScrollRoot = driver.Eyes.GetCurrentFrameScrollRootElement();
                positionProvider = driver.Eyes.GetPositionProvider(logger, driver.Eyes.StitchMode,
                                                                   driver, frameScrollRoot);
                logger_.Verbose("position provider: using the current frame scroll root element's position provider: {0}", positionProvider);
            }
            else if (driver.Eyes.CurrentFramePositionProvider != null)
            {
                positionProvider = driver.Eyes.CurrentFramePositionProvider;
                logger_.Verbose("position provider: using CurrentFramePositionProvider: {0}", positionProvider);
            }
            else
            {
                positionProvider = driver.Eyes.PositionProvider;
                logger_.Verbose("position provider: using PositionProvider: {0}", positionProvider);
            }

            //IPositionProvider positionProvider = driver.Eyes.CurrentFramePositionProvider ?? driver.Eyes.PositionProvider;

            frameChain_ = driver_.GetFrameChain();
            logger_.Verbose("got frame chain. getting frame size...");
            Size frameSize = GetFrameSize_(positionProvider);

            UpdateCurrentScrollPosition_(positionProvider);
            UpdateFrameLocationInScreenshot_(frameLocationInScreenshot);
            Size frameContentSize = GetFrameContentSize();

            logger.Verbose("Calculating frame window...");
            frameWindow_ = new Region(frameLocationInScreenshot_, frameContentSize);
            Region imageSizeAsRegion = new Region(0, 0, image.Width, image.Height);

            logger.Verbose("frameWindow_: {0} ; imageSizeAsRegion: {1}", frameWindow_, imageSizeAsRegion);
            frameWindow_.Intersect(imageSizeAsRegion);
            logger.Verbose("updated frameWindow_: {0}", frameWindow_);

            if (frameWindow_.Width <= 0 || frameWindow_.Height <= 0)
            {
                throw new EyesException("Got empty frame window for screenshot!");
            }

            logger.Verbose("Done!");
        }
        public override Region GetIntersectedRegion(Region region, CoordinatesTypeEnum originalCoordinatesType, CoordinatesTypeEnum resultCoordinatesType)
        {
            if (region.IsSizeEmpty)
            {
                return(region);
            }

            Region intersectedRegion = ConvertRegionLocation(region, originalCoordinatesType, CoordinatesTypeEnum.SCREENSHOT_AS_IS);

            switch (originalCoordinatesType)
            {
            // If the request was context based, we intersect with the frame window.
            case CoordinatesTypeEnum.CONTEXT_AS_IS:
            case CoordinatesTypeEnum.CONTEXT_RELATIVE:
                intersectedRegion.Intersect(frameWindow_);
                break;

            // If the request is screenshot based, we intersect with the image
            case CoordinatesTypeEnum.SCREENSHOT_AS_IS:
                intersectedRegion.Intersect(new Region(0, 0, Image.Width, Image.Height));
                break;

            default:
                throw new CoordinatesTypeConversionException(string.Format("Unknown coordinates type: '{0}'", originalCoordinatesType));
            }

            // If the intersection is empty we don't want to convert the coordinates.
            if (intersectedRegion.IsSizeEmpty)
            {
                return(intersectedRegion);
            }

            // Converting the result to the required coordinates type.
            intersectedRegion = ConvertRegionLocation(intersectedRegion, CoordinatesTypeEnum.SCREENSHOT_AS_IS, resultCoordinatesType);

            return(intersectedRegion);
        }