public Region CompensateRegionPosition(Region region, double pixelRatio) { if (pixelRatio == 1.0) { return(region); } EyesWebDriver eyesWebDriver = eyes.GetDriver(); FrameChain frameChain = eyesWebDriver.GetFrameChain(); if (frameChain.Count > 0) { return(region); } System.Drawing.Rectangle rect = region.ToRectangle(); rect.Offset(0, -(int)Math.Ceiling(pixelRatio / 2)); if (rect.Width <= 0 || rect.Height <= 0) { return(Region.Empty); } Region compensatedRegion = new Region(rect); logger.Verbose($"compensating for firefox: {region} ==> {compensatedRegion}"); return(compensatedRegion); }
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); }
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 screenshot..."); EyesWebDriver eyesWebDriver = eyes_.GetDriver(); FrameChain frameChain = eyesWebDriver.GetFrameChain().Clone(); logger_.Verbose("temporarilly switching to default content."); eyesWebDriver.SwitchTo().DefaultContent(); Bitmap image = BasicImageUtils.CreateBitmap(tsInstance_.GetScreenshot().AsByteArray); eyes_.DebugScreenshotProvider.Save(image, "FIREFOX"); logger_.Verbose("switching back to original frame."); ((EyesWebDriverTargetLocator)eyesWebDriver.SwitchTo()).Frames(frameChain); return(image); }
public MobileScreenshotImageProvider(SeleniumEyes eyes, Logger logger, ITakesScreenshot tsInstance, UserAgent userAgent) : base(logger, tsInstance, userAgent) { eyes_ = eyes; jsExecutor_ = new SeleniumJavaScriptExecutor(eyes.GetDriver()); }