예제 #1
0
 public Task <TestResultContainer> Abort(Exception exception)
 {
     RemoveAllCheckTasks_();
     openTask_?.SetException(exception);
     if (closeTask_ != null)
     {
         if (closeTask_.TaskType == TaskType.Close)
         {
             closeTask_.SetExceptionAndAbort(exception);
         }
     }
     else
     {
         VisualGridTask abortTask = new VisualGridTask(null, null, eyes_, TaskType.Abort, taskListener_, null, null, this, null);
         lock (TaskList)
         {
             TaskList.Add(abortTask);
         }
         closeTask_ = abortTask;
         Task <TestResultContainer> futureTask = new Task <TestResultContainer>(abortTask.Call, abortTask);
         taskToFutureMapping_[abortTask] = futureTask;
         isCloseTaskIssued_ = true;
     }
     return(taskToFutureMapping_[closeTask_]);
 }
예제 #2
0
 public RenderRequest(Uri webHook, Uri url, Uri stitchingService, RGridDom dom,
                      IDictionary <string, RGridResource> resources, RenderInfo renderInfo,
                      string platform, BrowserType browserName, object scriptHooks,
                      VisualGridSelector[] selectorsToFindRegionsFor, bool sendDom, VisualGridTask task,
                      VisualGridOption[] visualGridOptions)
 {
     Webhook                   = webHook;
     Url                       = url;
     StitchingService          = stitchingService;
     Dom                       = dom;
     Resources                 = resources;
     RenderInfo                = renderInfo;
     PlatformName              = platform;
     BrowserName               = browserName;
     ScriptHooks               = scriptHooks;
     SelectorsToFindRegionsFor = selectorsToFindRegionsFor;
     SendDom                   = sendDom;
     Task                      = task;
     if (visualGridOptions != null)
     {
         Options = new Dictionary <string, object>();
         foreach (VisualGridOption option in visualGridOptions)
         {
             Options[option.Key] = option.Value;
         }
     }
 }
예제 #3
0
        public void TestSerializationIosSimulator()
        {
            Uri      url = new Uri("https://another.url.co.il");
            Uri      stitchingServiceUrl = new Uri("https://another.stitchingserviceuri.co.il");
            RGridDom dom = new RGridDom();
            Dictionary <string, RGridResource> resources = new Dictionary <string, RGridResource>();
            SizeMode           target   = SizeMode.FullPage;
            VisualGridSelector selector = null;

            System.Drawing.Rectangle region     = new System.Drawing.Rectangle(40, 50, 60, 70);
            IosDeviceInfo            deviceInfo = new IosDeviceInfo(IosDeviceName.iPhone_XR, ScreenOrientation.Landscape);
            RenderInfo renderInfo = new RenderInfo(0, 0, target, selector, region, null, deviceInfo);

            VisualGridSelector[] selectorsToFindRegionsFor = new VisualGridSelector[0];
            bool              sendDom     = true;
            TaskType          taskType    = default;
            Logger            logger      = null;
            RunningTest       runningTest = null;
            VisualGridTask    task        = new VisualGridTask(taskType, logger, runningTest);
            RenderBrowserInfo browserInfo = new RenderBrowserInfo(deviceInfo);

            RenderRequest request = new RenderRequest(null, url, stitchingServiceUrl, dom, resources, renderInfo,
                                                      browserInfo.Platform, browserInfo.BrowserType, null, selectorsToFindRegionsFor, sendDom, task, null);

            JsonSerializerSettings settings = JsonUtils.CreateSerializerSettings();

            settings.Formatting = Formatting.Indented;
            string json         = JsonConvert.SerializeObject(request, settings);
            string expectedJson = CommonUtils.ReadResourceFile("Test.Eyes.Sdk.Core.DotNet.Resources.TestRenderRequestSerializationIosDevice.json");

            Assert.AreEqual(expectedJson, json);
        }
예제 #4
0
        private void SampleRenderingStatus_(Dictionary <RunningRender, RenderRequest> runningRenders, List <string> ids, List <RenderStatusResults> renderStatusResultsList)
        {
            logger_.Verbose("enter - renderStatusResultsList size: {0}", renderStatusResultsList.Count);

            for (int i = renderStatusResultsList.Count - 1; i >= 0; i--)
            {
                RenderStatusResults renderStatusResults = renderStatusResultsList[i];
                if (renderStatusResults == null)
                {
                    continue;
                }

                RenderStatus renderStatus     = renderStatusResults.Status;
                bool         isRenderedStatus = renderStatus == RenderStatus.Rendered;
                bool         isErrorStatus    = renderStatus == RenderStatus.Error;
                logger_.Verbose("renderStatusResults - {0}", renderStatusResults);
                if (isRenderedStatus || isErrorStatus)
                {
                    string removedId = ids[i];
                    ids.RemoveAt(i);

                    foreach (KeyValuePair <RunningRender, RenderRequest> kvp in runningRenders)
                    {
                        RunningRender renderedRender = kvp.Key;
                        RenderRequest renderRequest  = kvp.Value;
                        if (renderedRender.RenderId.Equals(removedId, StringComparison.OrdinalIgnoreCase))
                        {
                            VisualGridTask task = runningRenders[renderedRender].Task;

                            for (int k = openTasks_.Count - 1; k >= 0; k--)
                            {
                                VisualGridTask openTask = openTasks_[k];
                                if (openTask.RunningTest == task.RunningTest)
                                {
                                    if (isRenderedStatus)
                                    {
                                        logger_.Verbose("setting openTask {0} render result: {1} to url {2}", openTask, renderStatusResults, result_.Url);
                                        openTask.SetRenderResult(renderStatusResults);
                                    }
                                    else
                                    {
                                        logger_.Verbose("setting openTask {0} render error: {1} to url {2}", openTask, removedId, result_.Url);
                                        openTask.SetRenderError(removedId, renderStatusResults.Error, renderRequest);
                                    }
                                    openTasks_.RemoveAt(k);
                                }
                            }

                            logger_.Verbose("setting task {0} render result: {1} to url {2}", task, renderStatusResults, result_.Url);
                            task.SetRenderResult(renderStatusResults);
                            break;
                        }
                    }
                }
            }
            logger_.Verbose("exit");
        }
예제 #5
0
 private void RemoveAllCheckTasks_()
 {
     lock (TaskList)
     {
         for (int i = TaskList.Count - 1; i >= 0; --i)
         {
             VisualGridTask item = TaskList[i];
             if (item.TaskType == TaskType.Check)
             {
                 TaskList.RemoveAt(i);
             }
         }
     }
 }
        private Task <TestResultContainer> GetNextTestToOpen_()
        {
            ScoreTask bestScoreTask = null;
            int       bestMark      = -1;

            lock (allEyes_)
            {
                Logger.Verbose("looking for best test in a list of {0} eyes.", allEyes_.Count);
                foreach (IVisualGridEyes eyes in allEyes_)
                {
                    ScoreTask currentTestMark = eyes.GetBestScoreTaskForOpen();
                    if (currentTestMark == null)
                    {
                        continue;
                    }
                    int currentScore = currentTestMark.Score;
                    if (bestMark < currentScore)
                    {
                        bestMark      = currentScore;
                        bestScoreTask = currentTestMark;
                    }
                }
            }

            if (bestScoreTask == null)
            {
                lock (allEyes_)
                {
                    Logger.Verbose("no relevant test found in: {0}", allEyes_.Concat(" ; "));
                }
                return(null);
            }

            Logger.Verbose("found test with mark {0}", bestMark);
            Logger.Verbose("calling getNextOpenTaskAndRemove on {0}", bestScoreTask);
            VisualGridTask             nextOpenTask = bestScoreTask.Task;
            Task <TestResultContainer> task         = new Task <TestResultContainer>(nextOpenTask.Call, nextOpenTask);

            Logger.Verbose("task id: {0}", task.Id);
            return(task);
        }
예제 #7
0
        public void TestSerialization()
        {
            Uri      webHook             = new Uri("https://some.uri.com");
            Uri      url                 = new Uri("https://another.url.co.il");
            Uri      stitchingServiceUrl = new Uri("https://some.stitchingserviceuri.com");
            RGridDom dom                 = new RGridDom();
            Dictionary <string, RGridResource> resources = new Dictionary <string, RGridResource>();
            int                width    = 1600;
            int                height   = 1200;
            SizeMode           target   = SizeMode.FullPage;
            VisualGridSelector selector = null;

            System.Drawing.Rectangle region        = new System.Drawing.Rectangle(40, 50, 60, 70);
            EmulationBaseInfo        emulationInfo = new ChromeEmulationInfo(DeviceName.Galaxy_S5, ScreenOrientation.Portrait);
            RenderInfo  renderInfo  = new RenderInfo(width, height, target, selector, region, emulationInfo, null);
            string      platform    = "android";
            BrowserType browserName = BrowserType.IE_10;
            object      scriptHooks = null;
            string      xpath       = "//html/body/some/path/to/some/element[@with:attribute]";
            object      category    = "cat";

            VisualGridSelector[] selectorsToFindRegionsFor = new VisualGridSelector[] {
                new VisualGridSelector(xpath, category)
            };
            bool           sendDom     = true;
            TaskType       taskType    = default;
            Logger         logger      = null;
            RunningTest    runningTest = null;
            VisualGridTask task        = new VisualGridTask(taskType, logger, runningTest);

            RenderRequest request = new RenderRequest(webHook, url, stitchingServiceUrl, dom, resources, renderInfo, platform, browserName,
                                                      scriptHooks, selectorsToFindRegionsFor, sendDom, task, null);

            JsonSerializerSettings settings = JsonUtils.CreateSerializerSettings();

            settings.Formatting = Formatting.Indented;
            string json         = JsonConvert.SerializeObject(request, settings);
            string expectedJson = CommonUtils.ReadResourceFile("Test.Eyes.Sdk.Core.DotNet.Resources.TestRenderRequestSerialization.json");

            Assert.AreEqual(expectedJson, json);
        }
        private Task <TestResultContainer> GetNextCheckTask_()
        {
            ScoreTask bestScoreTask = null;
            int       bestScore     = -1;

            lock (allEyes_)
            {
                Logger.Verbose("looking for best test in a list of {0}", allEyes_.Count);
                //Logger.Verbose("locking allEyes_");

                foreach (IVisualGridEyes eyes in allEyes_)
                {
                    ScoreTask currentScoreTask = eyes.GetBestScoreTaskForCheck();
                    if (currentScoreTask == null)
                    {
                        continue;
                    }
                    int currentTestMark = currentScoreTask.Score;
                    if (bestScore < currentTestMark)
                    {
                        bestScoreTask = currentScoreTask;
                        bestScore     = currentTestMark;
                    }
                }
            }
            //Logger.Verbose("releasing allEyes_");

            if (bestScoreTask == null)
            {
                Logger.Verbose("no test found.");
                return(null);
            }
            Logger.Verbose("found test with score {0}", bestScore);
            VisualGridTask             vgTask = bestScoreTask.Task;
            Task <TestResultContainer> task   = new Task <TestResultContainer>(vgTask.Call, vgTask);

            Logger.Verbose("task id: {0}", task.Id);
            return(task);
        }
        void OnTaskComplete(VisualGridTask task, IVisualGridEyes eyes)
        {
            Logger.Verbose("Enter with: {0}", task.TaskType);
            TaskType type = task.TaskType;

            try
            {
                switch (type)
                {
                case TaskType.Open:
                    Logger.Verbose("locking eyesToOpenList");
                    lock (eyesToOpenList_)
                    {
                        Logger.Verbose("removing task {0}", task);
                        eyesToOpenList_.Remove(eyes);
                    }
                    Logger.Verbose("releasing eyesToOpenList");
                    break;

                case TaskType.Abort:
                case TaskType.Close:
                    Logger.Verbose("Task {0}", type);
                    eyesOpenerService_.DecrementConcurrency();
                    openerServiceConcurrencyLock_.Set();
                    break;

                case TaskType.Check:
                    Logger.Verbose("Check complete.");
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Log("Error: " + e);
            }

            NotifyAllServices();
        }
예제 #10
0
        private void PollRenderingStatus_(Dictionary <RunningRender, RenderRequest> runningRenders)
        {
            logger_.Verbose("enter");
            List <string> ids       = GetRenderIds_(runningRenders.Keys);
            Stopwatch     stopwatch = Stopwatch.StartNew();

            do
            {
                List <RenderStatusResults> renderStatusResultsList = null;
                try
                {
                    renderStatusResultsList = connector_.RenderStatusById(ids.ToArray());
                }
                catch (Exception e)
                {
                    logger_.Log("Error (3): " + e);
                    continue;
                }
                if (renderStatusResultsList == null || renderStatusResultsList.Count == 0)
                {
                    logger_.Verbose("No reason to sample. (ids.Count: {0})", ids.Count);
                    Thread.Sleep(500);
                    continue;
                }
                if (renderStatusResultsList[0] == null)
                {
                    logger_.Verbose("First element is null. Total number of elements: {0}. Continuing.", renderStatusResultsList.Count);
                    Thread.Sleep(500);
                    continue;
                }
                SampleRenderingStatus_(runningRenders, ids, renderStatusResultsList);

                if (ids.Count > 0)
                {
                    Thread.Sleep(1500);
                }

                logger_.Verbose("ids.Count: {0} ; runtime: {1}", ids.Count, stopwatch.Elapsed);
            } while (ids.Count > 0 && stopwatch.Elapsed < pollTimeout_);

            foreach (string id in ids)
            {
                foreach (KeyValuePair <RunningRender, RenderRequest> kvp in runningRenders)
                {
                    RunningRender renderedRender = kvp.Key;
                    RenderRequest renderRequest  = kvp.Value;
                    if (renderedRender.RenderId.Equals(id, StringComparison.OrdinalIgnoreCase))
                    {
                        VisualGridTask task = runningRenders[renderedRender].Task;
                        logger_.Verbose("removing failed render id: {0}", id);
                        task.SetRenderError(id, "too long rendering(rendering exceeded 150 sec)", renderRequest);
                        break;
                    }
                }
            }

            ICheckSettingsInternal rcInternal = (ICheckSettingsInternal)settings_;

            logger_.Verbose("marking task as complete: {0}", rcInternal.GetName());
            IsTaskComplete = true;
            NotifySuccessAllListeners_();
            logger_.Verbose("exit");
        }