Beispiel #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);
        }
Beispiel #2
0
        public MatchResult MatchWindow(Rectangle?region, IList <Trigger> userInputs, string tag, bool shouldRunOnceOnRetryTimeout, bool replaceLast,
                                       ICheckSettingsInternal checkSettingsInternal, string source, string domUrl = null)
        {
            ImageMatchSettings imageMatchSettings = CreateImageMatchSettings(checkSettingsInternal, eyes_);
            int retryTimeout = checkSettingsInternal.GetTimeout();

            if (retryTimeout < 0)
            {
                retryTimeout = defaultRetryTimeout_;
            }

            Logger_.Verbose("retryTimeout: {0} ; replaceLast: {1}", retryTimeout, replaceLast);
            EyesScreenshot screenshot = TakeScreenshot_(
                region, userInputs, tag, shouldRunOnceOnRetryTimeout,
                replaceLast, checkSettingsInternal, imageMatchSettings, retryTimeout, source);

            if (replaceLast)
            {
                return(matchResult_);
            }

            UpdateLastScreenshot_(screenshot);

            return(matchResult_);
        }
Beispiel #3
0
        private EyesScreenshot RetryTakingScreenshot_(Rectangle?region, IList <Trigger> userInputs, string tag, bool replaceLast, ICheckSettingsInternal checkSettingsInternal,
                                                      ImageMatchSettings imageMatchSettings, int retryTimeout, string source)
        {
            Logger_.Verbose("enter");
            // Retry matching and ignore mismatches while the retry timeout does not expires.
            var            sw2        = Stopwatch.StartNew();
            EyesScreenshot screenshot = null;

            while (sw2.ElapsedMilliseconds < retryTimeout)
            {
                Thread.Sleep(MatchInterval_);
                screenshot = TryTakingScreenshot_(region, userInputs, tag, replaceLast, checkSettingsInternal, imageMatchSettings, source);

                if (matchResult_.AsExpected)
                {
                    break;
                }
            }

            if (!matchResult_.AsExpected)
            {
                // Try one last time...
                screenshot = TryTakingScreenshot_(region, userInputs, tag, replaceLast, checkSettingsInternal, imageMatchSettings, source);
            }
            Logger_.Verbose("exit");
            return(screenshot);
        }
Beispiel #4
0
 private void DisposeLastScreenshot_()
 {
     if (lastScreenshot_ != null)
     {
         lastScreenshot_.Image.DisposeIfNotNull();
         lastScreenshot_ = null;
     }
 }
 private static void CollectSimpleRegions_(ICheckSettingsInternal checkSettingsInternal,
                                           ImageMatchSettings imageMatchSettings, EyesBase eyes,
                                           EyesScreenshot screenshot)
 {
     imageMatchSettings.Ignore  = CollectSimpleRegions_(eyes, screenshot, checkSettingsInternal.GetIgnoreRegions(), "Ignore");
     imageMatchSettings.Strict  = CollectSimpleRegions_(eyes, screenshot, checkSettingsInternal.GetStrictRegions(), "Strict");
     imageMatchSettings.Layout  = CollectSimpleRegions_(eyes, screenshot, checkSettingsInternal.GetLayoutRegions(), "Layout");
     imageMatchSettings.Content = CollectSimpleRegions_(eyes, screenshot, checkSettingsInternal.GetContentRegions(), "Content");
 }
Beispiel #6
0
 public static void CollectRegions(EyesBase eyes, EyesScreenshot screenshot,
                                   ICheckSettingsInternal checkSettingsInternal, ImageMatchSettings imageMatchSettings)
 {
     eyes.Logger.Verbose("enter");
     CollectSimpleRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
     CollectFloatingRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
     CollectAccessibilityRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
     LogRegions_(eyes.Logger, imageMatchSettings);
     eyes.Logger.Verbose("exit");
 }
Beispiel #7
0
        public AppOutputWithScreenshot(AppOutput appOutput, EyesScreenshot screenshot)
        {
            ArgumentGuard.NotNull(appOutput, nameof(appOutput));
            if (appOutput.ScreenshotUrl == null)
            {
                ArgumentGuard.NotNull(screenshot, nameof(screenshot));
            }

            AppOutput  = appOutput;
            Screenshot = screenshot;
        }
Beispiel #8
0
        private void UpdateLastScreenshot_(EyesScreenshot screenshot)
        {
            // Server will register the failed image so we keep it as the last screenshot
            // to compress against.
            DisposeLastScreenshot_();

            if (screenshot != null)
            {
                lastScreenshot_ = screenshot;
            }
        }
        private static IMutableRegion[] CollectSimpleRegions_(EyesBase eyes,
                                                              EyesScreenshot screenshot, IGetRegions[] regionProviders, string type)
        {
            List <IMutableRegion> mutableRegions = new List <IMutableRegion>();

            foreach (IGetRegions regionProvider in regionProviders)
            {
                mutableRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            eyes.Logger.Log(TraceLevel.Debug, eyes.TestId, Stage.Check, new { type, regions = mutableRegions });
            return(mutableRegions.ToArray());
        }
        private void UpdateLastScreenshot_(EyesScreenshot screenshot)
        {
            // Server will register the failed image so we keep it as the last screenshot
            // to compress against.
            DisposeLastScreenshot_();

            if (screenshot != null)
            {
                lastScreenshot_      = screenshot;
                LastScreenshotBounds = new Rectangle(Point.Empty, screenshot.Image.Size);
            }
        }
Beispiel #11
0
        private static IMutableRegion[] CollectSimpleRegions_(EyesBase eyes,
                                                              EyesScreenshot screenshot, IGetRegions[] regionProviders, string type)
        {
            eyes.Logger.Verbose("enter - region type: {0}", type);
            List <IMutableRegion> mutableRegions = new List <IMutableRegion>();

            foreach (IGetRegions regionProvider in regionProviders)
            {
                mutableRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            eyes.Logger.Verbose("exit");
            return(mutableRegions.ToArray());
        }
Beispiel #12
0
        private static void CollectFloatingRegions_(ICheckSettingsInternal checkSettingsInternal,
                                                    ImageMatchSettings imageMatchSettings, EyesBase eyes,
                                                    EyesScreenshot screenshot)
        {
            eyes.Logger.Verbose("enter");
            List <FloatingMatchSettings> floatingRegions = new List <FloatingMatchSettings>();

            foreach (IGetFloatingRegion regionProvider in checkSettingsInternal.GetFloatingRegions())
            {
                floatingRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            imageMatchSettings.Floating = floatingRegions.ToArray();
            eyes.Logger.Verbose("exit");
        }
        private static void CollectAccessibilityRegions_(ICheckSettingsInternal checkSettingsInternal,
                                                         ImageMatchSettings imageMatchSettings, EyesBase eyes,
                                                         EyesScreenshot screenshot)
        {
            List <AccessibilityRegionByRectangle> accessibilityRegions = new List <AccessibilityRegionByRectangle>();

            foreach (IGetAccessibilityRegion regionProvider in checkSettingsInternal.GetAccessibilityRegions())
            {
                accessibilityRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            imageMatchSettings.Accessibility = accessibilityRegions.ToArray();
            eyes.Logger.Log(TraceLevel.Debug, eyes.TestId, Stage.Check,
                            new { type = "accessibility", regions = accessibilityRegions });
        }
        private static void CollectFloatingRegions_(ICheckSettingsInternal checkSettingsInternal,
                                                    ImageMatchSettings imageMatchSettings, EyesBase eyes,
                                                    EyesScreenshot screenshot)
        {
            List <FloatingMatchSettings> floatingRegions = new List <FloatingMatchSettings>();

            foreach (IGetFloatingRegion regionProvider in checkSettingsInternal.GetFloatingRegions())
            {
                floatingRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            imageMatchSettings.Floating = floatingRegions.ToArray();
            eyes.Logger.Log(TraceLevel.Debug, eyes.TestId, Stage.Check,
                            new { type = "floating", regions = floatingRegions });
        }
Beispiel #15
0
        private static void CollectAccessibilityRegions_(ICheckSettingsInternal checkSettingsInternal,
                                                         ImageMatchSettings imageMatchSettings, EyesBase eyes,
                                                         EyesScreenshot screenshot)
        {
            eyes.Logger.Verbose("enter");
            List <AccessibilityRegionByRectangle> accessibilityRegions = new List <AccessibilityRegionByRectangle>();

            foreach (IGetAccessibilityRegion regionProvider in checkSettingsInternal.GetAccessibilityRegions())
            {
                accessibilityRegions.AddRange(regionProvider.GetRegions(eyes, screenshot));
            }
            imageMatchSettings.Accessibility = accessibilityRegions.ToArray();
            eyes.Logger.Verbose("exit");
        }
Beispiel #16
0
        public MatchResult PerformMatch(AppOutputWithScreenshot appOutput,
                                        string tag, bool ignoreMismatch,
                                        ICheckSettingsInternal checkSettingsInternal,
                                        ImageMatchSettings imageMatchSettings,
                                        IList <IRegion> regions,
                                        IList <VisualGridSelector[]> regionSelectors,
                                        EyesBase eyes, string source, string renderId = null)
        {
            EyesScreenshot screenshot    = appOutput.Screenshot;
            string         agentSetupStr = eyes.GetAgentSetupString();

            CollectRegions_(imageMatchSettings, regions, regionSelectors);
            CollectRegions_(imageMatchSettings, checkSettingsInternal);
            return(PerformMatch_(new Trigger[0], appOutput, tag, ignoreMismatch, imageMatchSettings, agentSetupStr, source, renderId));
        }
 public IList <FloatingMatchSettings> GetRegions(EyesBase eyesBase, EyesScreenshot screenshot)
 {
     return(new FloatingMatchSettings[] {
         new FloatingMatchSettings()
         {
             Left = rect_.Left,
             Top = rect_.Top,
             Width = rect_.Width,
             Height = rect_.Height,
             MaxLeftOffset = maxLeftOffset_,
             MaxUpOffset = maxUpOffset_,
             MaxRightOffset = maxRightOffset_,
             MaxDownOffset = maxDownOffset_
         }
     });
 }
Beispiel #18
0
        private EyesScreenshot TryTakingScreenshot_(Rectangle?region, IList <Trigger> userInputs, string tag, bool replaceLast, ICheckSettingsInternal checkSettingsInternal,
                                                    ImageMatchSettings imageMatchSettings, string source)
        {
            Logger_.Verbose("enter");
            AppOutputWithScreenshot appOutputWithScreenshot = GetAppOutput_(region, checkSettingsInternal, imageMatchSettings);
            EyesScreenshot          screenshot = appOutputWithScreenshot.Screenshot;
            AppOutput appOutput             = appOutputWithScreenshot.AppOutput;
            string    currentScreenshotHash = screenshot == null ? appOutput.ScreenshotUrl : CommonUtils.GetSha256Hash(appOutput.ScreenshotBytes);

            Logger_.Verbose("current screenshot hash: {0}", currentScreenshotHash);
            if (lastScreenshotHash_ == currentScreenshotHash)
            {
                Logger_.Log("second screenshot is the same as the first, no point in uploading to server.");
            }
            else
            {
                matchResult_ = PerformMatch(userInputs, appOutputWithScreenshot, tag,
                                            replaceLast || (lastScreenshotHash_ != null), imageMatchSettings, eyes_, source);
                lastScreenshotHash_ = currentScreenshotHash;
            }
            Logger_.Verbose("exit");
            return(screenshot);
        }
        public static ImageMatchSettings CreateImageMatchSettings(ICheckSettingsInternal checkSettingsInternal, EyesBase eyes, EyesScreenshot screenshot)
        {
            ImageMatchSettings imageMatchSettings = CreateImageMatchSettings(checkSettingsInternal, eyes);

            if (imageMatchSettings != null)
            {
                CollectSimpleRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
                CollectFloatingRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
                CollectAccessibilityRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
            }
            eyes.Logger.Log(TraceLevel.Info, eyes.TestId, Stage.Check, new { regions = imageMatchSettings });
            return(imageMatchSettings);
        }
 public IList <IMutableRegion> GetRegions(EyesBase eyesBase, EyesScreenshot screenshot)
 {
     return(new IMutableRegion[] { region });
 }
Beispiel #21
0
        public static ImageMatchSettings CreateImageMatchSettings(ICheckSettingsInternal checkSettingsInternal, EyesBase eyes, EyesScreenshot screenshot)
        {
            eyes.Logger.Verbose("enter");
            ImageMatchSettings imageMatchSettings = CreateImageMatchSettings(checkSettingsInternal, eyes);

            if (imageMatchSettings != null)
            {
                CollectSimpleRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
                CollectFloatingRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
                CollectAccessibilityRegions_(checkSettingsInternal, imageMatchSettings, eyes, screenshot);
                LogRegions_(eyes.Logger, imageMatchSettings);
            }
            eyes.Logger.Verbose("exit");
            return(imageMatchSettings);
        }
Beispiel #22
0
 public IList <AccessibilityRegionByRectangle> GetRegions(EyesBase eyesBase, EyesScreenshot screenshot)
 {
     return(new AccessibilityRegionByRectangle[] { this });
 }