Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="MatchWindowData"/> instance.
        /// </summary>
        /// <param name="appOutput">The appOutput for the current matchWindow call.</param>
        /// <param name="tag">The step name to use.</param>
        /// <param name="agentSetup">The test setup parameters used.</param>
        public MatchWindowData(AppOutput appOutput, string tag, object agentSetup = null)
        {
            ArgumentGuard.NotNull(appOutput, nameof(appOutput));

            AppOutput  = appOutput;
            Tag        = tag;
            AgentSetup = agentSetup;
        }
        /// <summary>
        /// Creates a new <see cref="MatchWindowData"/> instance.
        /// </summary>
        /// <param name="appOutput">The appOutput for the current matchWindow call.</param>
        /// <param name="tag">The step name to use.</param>
        /// <param name="agentSetup">The test setup parameters used.</param>
        public MatchWindowData(RunningSession runningSession, AppOutput appOutput, string tag, object agentSetup = null)
        {
            ArgumentGuard.NotNull(appOutput, nameof(appOutput));

            RunningSession = runningSession;
            AppOutput      = appOutput;
            Tag            = tag;
            AgentSetup     = agentSetup;
        }
        public void TestCtor()
        {
            byte[]    contentBytes = Encoding.UTF8.GetBytes("some fake base64 screenshot serialized");
            AppOutput ao           = new AppOutput("title", new Location(10, 30), contentBytes, "abc");

            Assert.AreEqual("title", ao.Title);
            Assert.AreEqual(new Location(10, 30), ao.Location);
            Assert.AreEqual(contentBytes, ao.ScreenshotBytes);
            Assert.AreEqual("abc", ao.ScreenshotUrl);
        }
Esempio n. 4
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;
        }
        private EyesScreenshot TryTakingScreenshot_(Rectangle?region, IList <Trigger> userInputs, string tag, bool replaceLast, ICheckSettingsInternal checkSettingsInternal,
                                                    ImageMatchSettings imageMatchSettings, string source)
        {
            AppOutput appOutput             = GetAppOutput_(region, checkSettingsInternal, imageMatchSettings);
            string    currentScreenshotHash = appOutput.ScreenshotUrl ?? CommonUtils.GetSha256Hash(appOutput.ScreenshotBytes);

            logger_.Log(TraceLevel.Info, Stage.Check, StageType.CaptureScreenshot,
                        new { currentScreenshotHash, lastScreenshotHash_ });
            if (lastScreenshotHash_ != currentScreenshotHash)
            {
                MatchWindowData data = eyes_.PrepareForMatch(checkSettingsInternal, userInputs, appOutput,
                                                             tag, replaceLast || (lastScreenshotHash_ != null), imageMatchSettings, null, source);

                matchResult_        = eyes_.PerformMatch(data);
                lastScreenshotHash_ = currentScreenshotHash;
            }
            return((EyesScreenshot)appOutput.Screenshot);
        }
Esempio n. 6
0
        public void TryUploadImage(string testId, MatchWindowData data, TaskListener taskListener)
        {
            AppOutput appOutput = data.AppOutput;

            if (appOutput.ScreenshotUrl != null)
            {
                taskListener.OnComplete();
                return;
            }

            // Getting the screenshot bytes
            TaskListener <string> uploadListener = new TaskListener <string>(
                (url) =>
            {
                if (url == null)
                {
                    Logger.Verbose("Got null url from upload. Test id: {0}", testId);
                    appOutput.ScreenshotUrl = null;
                    taskListener.OnFail(new EyesException("Failed uploading image"));
                    return;
                }
                Logger.Log(TraceLevel.Info, testId, Stage.Check, StageType.UploadComplete, new { url });
                appOutput.ScreenshotUrl = url;
                appOutput.ClearScreenshotBytes();
                taskListener.OnComplete();
            },
                (ex) =>
            {
                appOutput.ScreenshotUrl = null;
                taskListener.OnFail(new EyesException("Failed uploading image", ex));
            }
                );

            try
            {
                Logger.Log(TraceLevel.Info, testId, Stage.Check, StageType.UploadStart,
                           new { dataLength = appOutput.ScreenshotBytes.Length });
                ServerConnector.UploadImage(uploadListener, appOutput.ScreenshotBytes, testId);
            }
            catch (Exception ex)
            {
                taskListener.OnFail(ex);
            }
        }
Esempio n. 7
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 void Setup()
 {
     trigger_ = new MouseTrigger(MouseAction.Click, new Region(0, 0, 0, 0), new Location(0, 0));
     appOut_  = new AppOutput("Dummy", new Location(20, 40), Encoding.UTF8.GetBytes("blob as base64"), "bla");
 }