Example #1
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, IosVersion.ONE_VERSION_BACK);
            RenderInfo renderInfo = new RenderInfo(0, 0, target, selector, region, null, deviceInfo);

            VisualGridSelector[] selectorsToFindRegionsFor = new VisualGridSelector[0];
            bool sendDom = true;
            RenderBrowserInfo browserInfo = new RenderBrowserInfo(deviceInfo);

            RenderRequest request = new RenderRequest("id", null, url, stitchingServiceUrl, dom, resources, renderInfo,
                                                      browserInfo.Platform, browserInfo.BrowserType, null, selectorsToFindRegionsFor, sendDom, null, null, 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);
        }
Example #2
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");
        }
Example #3
0
        private Dictionary <RunningRender, RenderRequest> MapRequestToRunningRender_(List <RunningRender> runningRenders, RenderRequest[] requests)
        {
            Dictionary <RunningRender, RenderRequest> mapping = new Dictionary <RunningRender, RenderRequest>();

            if (runningRenders != null && requests != null && runningRenders.Count >= requests.Length)
            {
                for (int i = 0; i < requests.Length; i++)
                {
                    RenderRequest request       = requests[i];
                    RunningRender runningRender = runningRenders[i];
                    mapping.Add(runningRender, request);
                }
            }
            return(mapping);
        }
        private string GetUserAgent_(RenderRequest renderRequest)
        {
            if (renderRequest.RenderInfo.EmulationInfo != null || renderRequest.RenderInfo.IosDeviceInfo != null)
            {
                return(null);
            }

            BrowserType browser = renderRequest.BrowserName;
            Dictionary <BrowserType, string> userAgents = EyesConnector.GetUserAgents();

            if (!userAgents.TryGetValue(browser, out string userAgent))
            {
                logger_.Verbose("could not find browser {0} in list", browser);
                return(null);
            }

            return(userAgent);
        }
        internal void SetRenderError(string renderId, string error, RenderRequest renderRequest)
        {
            logger_.Verbose("enter - renderId: {0}", renderId);
            RenderStatusResults renderResult = new RenderStatusResults();
            string userAgent = GetUserAgent_(renderRequest);

            if (userAgent != null)
            {
                renderResult.UserAgent = userAgent;
            }
            Size deviceSize = GetCorrectDeviceSize_(renderRequest);

            renderResult.DeviceSize = deviceSize;
            renderResult_           = renderResult;
            logger_.Verbose("device size: " + deviceSize);
            listener_.OnTaskFailed(new Exception($"Render Failed for {BrowserInfo} (renderId: {renderId}) with reason: {error}"), this);
            logger_.Verbose("exit - renderId: {0}", renderId);
        }
Example #6
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 Size GetCorrectDeviceSize_(RenderRequest renderRequest)
        {
            Size deviceSize = configuration_.ViewportSize;

            if (deviceSize.IsEmpty)
            {
                IosDeviceInfo       iosDeviceInfo = renderRequest.RenderInfo.IosDeviceInfo;
                ChromeEmulationInfo emulationInfo = renderRequest.RenderInfo.EmulationInfo as ChromeEmulationInfo;
                if (iosDeviceInfo != null)
                {
                    IosDeviceName deviceName = iosDeviceInfo.DeviceName;
                    Dictionary <IosDeviceName, DeviceSize> iosDevicesSizes = EyesConnector.GetIosDevicesSizes();
                    if (!iosDevicesSizes.TryGetValue(deviceName, out DeviceSize deviceSizes))
                    {
                        logger_.Verbose("could not find device in list.");
                        return(Size.Empty);
                    }
                    deviceSize = iosDeviceInfo.ScreenOrientation == ScreenOrientation.Portrait
                        ? deviceSizes.Portrait
                        : deviceSizes.LandscapeLeft;
                }
                else if (emulationInfo != null)
                {
                    DeviceName deviceName = emulationInfo.DeviceName;
                    Dictionary <DeviceName, DeviceSize> emulatedDevicesSizes = EyesConnector.GetEmulatedDevicesSizes();
                    if (!emulatedDevicesSizes.TryGetValue(deviceName, out DeviceSize deviceSizes))
                    {
                        logger_.Verbose("could not find device in list.");
                        return(Size.Empty);
                    }
                    deviceSize = emulationInfo.ScreenOrientation == ScreenOrientation.Portrait
                        ? deviceSizes.Portrait
                        : deviceSizes.Landscape;
                }
            }
            return(deviceSize);
        }
Example #8
0
        private List <RenderRequest> BuildRenderRequests_(FrameData currentFrame, IDictionary <string, RGridResource> resourceMapping)
        {
            Uri      url = currentFrame.Url;
            RGridDom dom = new RGridDom(currentFrame.Cdt, resourceMapping, url, logger_, "buildRenderRequests");

            //Create RG requests
            List <RenderRequest>   allRequestsForRG = new List <RenderRequest>();
            ICheckSettingsInternal csInternal       = (ICheckSettingsInternal)settings_;

            foreach (VisualGridTask task in taskList_)
            {
                RenderBrowserInfo browserInfo = task.BrowserInfo;
                RenderInfo        renderInfo  = new RenderInfo(browserInfo.Width, browserInfo.Height,
                                                               csInternal.GetSizeMode(), csInternal.GetTargetSelector(),
                                                               csInternal.GetTargetRegion(), browserInfo.EmulationInfo, browserInfo.IosDeviceInfo);

                List <VisualGridSelector> regionSelectors = new List <VisualGridSelector>();
                if (regionSelectors_ != null)
                {
                    foreach (VisualGridSelector[] vgs in regionSelectors_)
                    {
                        regionSelectors.AddRange(vgs);
                    }
                }

                RenderRequest request = new RenderRequest(renderingInfo_.ResultsUrl, url,
                                                          renderingInfo_.StitchingServiceUrl, dom,
                                                          resourceMapping, renderInfo, browserInfo.Platform,
                                                          browserInfo.BrowserType, csInternal.GetScriptHooks(),
                                                          regionSelectors.ToArray(), csInternal.GetSendDom() ?? false, task,
                                                          csInternal.GetVisualGridOptions());

                allRequestsForRG.Add(request);
            }
            return(allRequestsForRG);
        }
Example #9
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");
        }
Example #10
0
        public async Task <RenderStatusResults> CallAsync()
        {
            logger_.Verbose("enter");

            List <RunningRender> runningRenders = null;

            isTaskStarted_ = true;

            RenderRequest[] requests = new RenderRequest[0];

            try
            {
                logger_.Verbose("step 1");

                AddRenderingTaskToOpenTasks_();

                bool isSecondRequestAlreadyHappened = false;

                //Parse to Map
                logger_.Verbose("step 2");
                //Build RenderRequests
                requests = PrepareDataForRG_(result_);

                logger_.Verbose("step 3");
                bool      stillRunning          = true;
                bool      isForcePutAlreadyDone = false;
                Stopwatch timeoutTimer          = Stopwatch.StartNew();
                do
                {
                    try
                    {
                        runningRenders = await connector_.RenderAsync(requests);
                    }
                    catch (Exception e)
                    {
                        var    settings = JsonUtils.CreateSerializerSettings();
                        string j        = JsonConvert.SerializeObject(requests, settings);

                        string responseBodyStr = string.Empty;
                        if (e is WebException we && we.Response != null)
                        {
                            Stream stream            = we.Response.GetResponseStream();
                            byte[] responseBodyBytes = CommonUtils.ReadToEnd(stream);
                            responseBodyStr = Encoding.UTF8.GetString(responseBodyBytes);
                        }

                        logger_.Verbose("/render throws exception. sleeping for 1.5s");
                        Thread.Sleep(1500);

                        if (responseBodyStr.Contains("Second request, yet still some resources were not PUT in renderId"))
                        {
                            if (isSecondRequestAlreadyHappened)
                            {
                                logger_.Verbose("Second request already happened");
                            }
                            isSecondRequestAlreadyHappened = true;
                        }
                        logger_.Verbose("Error (1): " + e);
                        logger_.Verbose("Error Response Body: " + responseBodyStr);
                    }
                    logger_.Verbose("step 4.1");
                    if (runningRenders == null)
                    {
                        logger_.Verbose("ERROR - runningRenders is null.");
                        SetRenderErrorToTasks_(requests);
                        continue;
                    }

                    for (int i = 0; i < requests.Length; i++)
                    {
                        RenderRequest request = requests[i];
                        request.RenderId = runningRenders[i].RenderId;
                    }
                    logger_.Verbose("step 4.2");

                    RunningRender runningRender = runningRenders[0];
                    RenderStatus  worstStatus   = runningRender.RenderStatus;

                    worstStatus = CalcWorstStatus_(runningRenders, worstStatus);

                    bool isNeedMoreDom = runningRender.NeedMoreDom;

                    if (isForcePutNeeded_ && !isForcePutAlreadyDone)
                    {
                        ForcePutAllResources_(requests[0].Resources, runningRender);
                        isForcePutAlreadyDone = true;
                    }

                    logger_.Verbose("step 4.3");
                    stillRunning = (worstStatus == RenderStatus.NeedMoreResources || isNeedMoreDom) && (timeoutTimer.Elapsed.TotalSeconds < FETCH_TIMEOUT_SECONDS);
                    if (stillRunning)
                    {
                        SendMissingResources_(runningRenders, requests[0].Dom, requests[0].Resources, isNeedMoreDom);
                    }

                    logger_.Verbose("step 4.4");
                } while (stillRunning);
            }
            catch (Exception e)
            {
                logger_.Log("Error: " + e);
                SetRenderErrorToTasks_(requests);
            }

            Dictionary <RunningRender, RenderRequest> mapping = MapRequestToRunningRender_(runningRenders, requests);

            logger_.Verbose("step 5");
            try
            {
                PollRenderingStatus_(mapping);
            }
            catch (Exception e)
            {
                isTaskInException = true; // FOR DEBUGGING
                logger_.Log("Error (2): " + e);
                foreach (VisualGridTask visualGridTask in taskList_)
                {
                    visualGridTask.SetExceptionAndAbort(e);
                }
            }

            IsTaskComplete = true;
            logger_.Verbose("exit");
            return(null);
        }