protected Size GetViewportSize() { EyesWebDriver driver = eyes_.GetDriver(); if (cachedViewportSize_ == null || cachedUrl_ != driver.Url) { cachedUrl_ = driver.Url; cachedViewportSize_ = EyesSeleniumUtils.GetViewportSize(logger_, driver); } Size originalViewportSize = cachedViewportSize_.Value; return(originalViewportSize); }
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); }