Esempio n. 1
0
        public override void RenderStatusById(TaskListener <List <RenderStatusResults> > taskListener,
                                              IList <string> testIds, IList <string> renderIds)
        {
            List <RenderStatusResults> results = new List <RenderStatusResults>();

            foreach (string renderId in renderIds)
            {
                List <VGRegion> selectorRegions = new List <VGRegion>();
                JToken          request         = renderRequestsById_[renderId];
                JToken          selectors       = request["selectorsToFindRegionsFor"];
                if (selectors != null && selectors is JArray selectorsArr)
                {
                    IWebDriver driver = driverProvider_.ProvideDriver();
                    foreach (JObject selectorToken in selectorsArr)
                    {
                        string      selector = selectorToken["selector"].Value <string>();
                        IWebElement elem     = driver.FindElement(By.XPath(selector));
                        Rectangle   r        = EyesSeleniumUtils.GetElementBounds(elem);
                        selectorRegions.Add(new VGRegion()
                        {
                            X = r.X, Y = r.Y, Width = r.Width, Height = r.Height
                        });
                    }
                }
                RenderStatusResults result = new RenderStatusResults()
                {
                    RenderId        = renderId,
                    Status          = RenderStatus.Rendered,
                    ImageLocation   = "http://image.some.url.com/" + renderId,
                    SelectorRegions = selectorRegions.ToArray()
                };
                results.Add(result);
            }
            taskListener.OnComplete(results);
        }
Esempio n. 2
0
        protected override void StartSessionInternal(TaskListener <RunningSession> taskListener, SessionStartInfo sessionStartInfo)
        {
            Logger.Log(TraceLevel.Info, Stage.Open, StageType.Called, new { sessionStartInfo });

            RunningSession newSession         = null;
            bool           continueInvocation = true;
            bool           callBase           = false;

            if (continueInvocation)
            {
                newSession = new RunningSession()
                {
                    isNewSession_ = false, SessionId = Guid.NewGuid().ToString()
                };
                SessionIds.Add(newSession.SessionId);
                Sessions.Add(newSession.SessionId, newSession);
                SessionsStartInfo.Add(newSession.SessionId, sessionStartInfo);
            }
            if (callBase)
            {
                base.StartSessionInternal(taskListener, sessionStartInfo);
            }
            else
            {
                EnsureHttpClient_();
                taskListener.OnComplete(newSession);
            }
        }
Esempio n. 3
0
        protected override void EndSessionInternal(TaskListener <TestResults> taskListener, SessionStopInfo sessionStopInfo)
        {
            Logger.Log("ending session: {0}", sessionStopInfo.RunningSession.SessionId);
            TestResults testResults = new TestResults();

            AfterEndSession?.Invoke(sessionStopInfo.RunningSession, sessionStopInfo.Aborted, sessionStopInfo.UpdateBaseline);
            taskListener.OnComplete(testResults);
        }
Esempio n. 4
0
 public override void CheckResourceStatus(TaskListener <bool?[]> taskListener, HashSet <string> testId,
                                          string renderId, HashObject[] hashes)
 {
     bool?[] result = new bool?[hashes.Length];
     for (int i = 0; i < hashes.Length; ++i)
     {
         result[i] = true;
     }
     taskListener.OnComplete(result);
 }
        private void GetResponseCallBack_(TaskListener <HttpResponseMessage> listener, IAsyncResult result,
                                          HttpRequestMessage originalRequest, Logger logger, BackoffProvider backoffProvider)
        {
            if (!result.IsCompleted)
            {
                logger.Log(TraceLevel.Warn, Stage.General, StageType.RequestFailed,
                           new { message = "result is not complete.", result });
                return;
            }
            try
            {
                Task <HttpResponseMessage> resultAsTask = (Task <HttpResponseMessage>)result;
                if (resultAsTask.IsFaulted)
                {
                    if (MakeAnotherAttempt_(listener, originalRequest, logger, backoffProvider))
                    {
                        return;
                    }

                    listener.OnFail(
                        new EyesException($"HttpRequestMessage request failed: {originalRequest.Method} {originalRequest.RequestUri}",
                                          resultAsTask.Exception));
                    return;
                }
                if (resultAsTask.IsCanceled)
                {
                    if (MakeAnotherAttempt_(listener, originalRequest, logger, backoffProvider))
                    {
                        return;
                    }

                    listener.OnFail(
                        new TimeoutException($"HttpRequestMessage request timed out: {originalRequest.Method} {originalRequest.RequestUri}"));
                    return;
                }
                HttpResponseMessage response = resultAsTask.Result;
                if (response.StatusCode >= HttpStatusCode.Ambiguous)
                {
                    listener.OnFail(new EyesException($"Wrong response status: {response.StatusCode} {response.ReasonPhrase}"));
                }
                else
                {
                    listener.OnComplete(response);
                }
                response.Dispose();
            }
            catch (WebException ex)
            {
                if (MakeAnotherAttempt_(listener, originalRequest, logger, backoffProvider))
                {
                    return;
                }
                listener.OnFail(ex);
            }
        }
Esempio n. 6
0
        public override void GetJobInfo(TaskListener <IList <JobInfo> > listener, IList <IRenderRequest> renderRequests)
        {
            IList <JobInfo> jobs = new List <JobInfo>();

            for (int i = 0; i < renderRequests?.Count; ++i)
            {
                RenderRequest request  = (RenderRequest)renderRequests[i];
                string        renderer = request.Browser.Name.GetAttribute <System.Runtime.Serialization.EnumMemberAttribute>().Value;
                jobs.Add(new JobInfo()
                {
                    EyesEnvironment = "MockEnvironment", Renderer = renderer
                });
            }
            listener.OnComplete(jobs);
        }
Esempio n. 7
0
 protected override void SendUFGAsyncRequest_ <T>(TaskListener <T> taskListener, HttpRequestMessage request) //where T : class
 {
     if (request.Method == HttpMethod.Post &&
         request.RequestUri.PathAndQuery.StartsWith("/render", StringComparison.OrdinalIgnoreCase))
     {
         byte[] bytes          = request.Content.ReadAsByteArrayAsync().Result;
         string requestJsonStr = Encoding.UTF8.GetString(bytes);
         RenderRequests.Add(requestJsonStr);
         List <RunningRender> response = new List <RunningRender>();
         JArray list = (JArray)JsonConvert.DeserializeObject(requestJsonStr);
         foreach (JToken item in list)
         {
             string id = Guid.NewGuid().ToString();
             renderRequestsById_.Add(id, item);
             response.Add(new RunningRender(id, "abc", RenderStatus.Rendered, null, false));
         }
         taskListener.OnComplete(response as T);
     }
     else
     {
         base.SendUFGAsyncRequest_(taskListener, request);
     }
 }
Esempio n. 8
0
 public override void PostDomCapture(TaskListener <string> listener, string domJson, params string[] testIds)
 {
     listener.OnComplete("http://some.targeturl.com/dom");
 }