コード例 #1
0
        public override Bitmap GetImage()
        {
            Bitmap image = base.GetImage();

            logger_.Verbose("Bitmap Size: {0}x{1}", image.Width, image.Height);

            eyes_.DebugScreenshotProvider.Save(image, "SAFARI");

            if (eyes_.IsCutProviderExplicitlySet)
            {
                return(image);
            }

            double scaleRatio = eyes_.DevicePixelRatio;

            Size originalViewportSize = GetViewportSize();

            Size viewportSize = new Size(
                (int)Math.Ceiling(originalViewportSize.Width * scaleRatio),
                (int)Math.Ceiling(originalViewportSize.Height * scaleRatio));

            logger_.Verbose("logical viewport size: " + originalViewportSize);

            if (userAgent_.OS.Equals(OSNames.IOS))
            {
                image = CropIOSImage(image, originalViewportSize, logger_);
            }
            else if (!eyes_.ForceFullPageScreenshot)
            {
                Point      loc;
                FrameChain currentFrameChain = eyes_.GetDriver().GetFrameChain();

                if (currentFrameChain.Count == 0)
                {
                    IWebElement       scrollRootElement = eyes_.GetCurrentFrameScrollRootElement();
                    IPositionProvider positionProvider  = SeleniumPositionProviderFactory.GetPositionProvider(logger_, StitchModes.Scroll, jsExecutor_, scrollRootElement, userAgent_);
                    loc = positionProvider.GetCurrentPosition();
                }
                else
                {
                    loc = currentFrameChain.GetDefaultContentScrollPosition();
                }

                loc = new Point((int)Math.Ceiling(loc.X * scaleRatio), (int)Math.Ceiling(loc.Y * scaleRatio));

                image = BasicImageUtils.Crop(image, new Rectangle(loc, viewportSize));
            }
            eyes_.DebugScreenshotProvider.Save(image, "SAFARI_CROPPED");

            return(image);
        }
        public override Bitmap GetImage()
        {
            logger_.Verbose("Getting current position...");
            Point  loc;
            double scaleRatio = eyes_.DevicePixelRatio;

            FrameChain        currentFrameChain = eyes_.GetDriver().GetFrameChain();
            IPositionProvider positionProvider  = null;

            if (currentFrameChain.Count == 0)
            {
                IWebElement scrollRootElement = eyes_.GetCurrentFrameScrollRootElement();
                positionProvider = eyes_.GetPositionProvider(logger_, StitchModes.Scroll,
                                                             jsExecutor_, scrollRootElement, userAgent_);
                loc = positionProvider.GetCurrentPosition();
            }
            else
            {
                loc = currentFrameChain.GetDefaultContentScrollPosition();
            }
            Point scaledLoc = new Point((int)Math.Round(loc.X * scaleRatio), (int)Math.Round(loc.Y * scaleRatio));

            Bitmap        image  = base.GetImage();
            EyesWebDriver driver = eyes_.GetDriver();
            RectangleSize originalViewportSize = EyesSeleniumUtils.GetViewportSize(logger_, driver);
            RectangleSize viewportSize         = originalViewportSize.Scale(scaleRatio);

            if (image.Height > viewportSize.Height || image.Width > viewportSize.Width)
            {
                //Damn IE driver returns full page screenshot even when not asked to!
                logger_.Verbose("seems IE returned full page screenshot rather than only the viewport.");
                eyes_.DebugScreenshotProvider.Save(image, "IE");
                if (!eyes_.IsCutProviderExplicitlySet)
                {
                    Bitmap croppedImage = BasicImageUtils.Crop(image, new Rectangle(scaledLoc, viewportSize));
                    image.Dispose();
                    image = croppedImage;
                }
            }

            positionProvider?.SetPosition(loc);
            return(image);
        }
コード例 #3
0
        public override Bitmap GetImage()
        {
            Bitmap image = base.GetImage();

            if (eyes_.CachedSessionDetails != null &&
                eyes_.CachedSessionDetails.TryGetValue("deviceOrientation", out object orientation))
            {
                if ("landscape".Equals(orientation as string, StringComparison.OrdinalIgnoreCase) && image.Width < image.Height)
                {
                    logger_.Verbose("rotating image...");
                    image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                }
            }

            logger_.Verbose("Bitmap Size: {0}x{1}", image.Width, image.Height);
            eyes_.DebugScreenshotProvider.Save(image, "SAFARI");

            if (eyes_.IsCutProviderExplicitlySet)
            {
                return(image);
            }

            double scaleRatio = eyes_.DevicePixelRatio;

            Size originalViewportSize = GetViewportSize();

            Size viewportSize = new Size(
                (int)Math.Ceiling(originalViewportSize.Width * scaleRatio),
                (int)Math.Ceiling(originalViewportSize.Height * scaleRatio));

            logger_.Verbose("logical viewport size: " + originalViewportSize);

            Bitmap croppedImage = null;

            if (userAgent_.IsiOS ||
                "ios".Equals(eyes_.PlatformName, StringComparison.OrdinalIgnoreCase) ||
                (eyes_.CachedSessionDetails.TryGetValue("PlatformName", out object platformName) &&
                 "ios".Equals(platformName as string, StringComparison.OrdinalIgnoreCase)))
            {
                croppedImage = CropIOSImage(image, originalViewportSize, logger_);
            }
            else if (!eyes_.ForceFullPageScreenshot)
            {
                Point      loc;
                FrameChain currentFrameChain = eyes_.GetDriver().GetFrameChain();

                if (currentFrameChain.Count == 0)
                {
                    IWebElement       scrollRootElement = eyes_.GetCurrentFrameScrollRootElement();
                    IPositionProvider positionProvider  = eyes_.GetPositionProvider(
                        logger_, StitchModes.Scroll, jsExecutor_, scrollRootElement,
                        userAgent_);
                    loc = positionProvider.GetCurrentPosition();
                }
                else
                {
                    loc = currentFrameChain.GetDefaultContentScrollPosition();
                }

                loc = new Point((int)Math.Ceiling(loc.X * scaleRatio), (int)Math.Ceiling(loc.Y * scaleRatio));

                croppedImage = BasicImageUtils.Crop(image, new Rectangle(loc, viewportSize));
            }
            if (croppedImage != null && !ReferenceEquals(croppedImage, image))
            {
                image.Dispose();
                image = croppedImage;
            }
            eyes_.DebugScreenshotProvider.Save(image, "SAFARI_CROPPED");

            return(image);
        }