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); }
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; } } }
private void SendMissingResources_(List <RunningRender> runningRenders, RGridDom dom, IDictionary <string, RGridResource> resources, bool isNeedMoreDom) { logger_.Verbose("enter - sending {0} missing resources. need more dom: {1}", resources.Count, isNeedMoreDom); List <PutFuture> allPuts = new List <PutFuture>(); if (isNeedMoreDom) { RunningRender runningRender = runningRenders[0]; PutFuture future = null; try { future = connector_.RenderPutResource(runningRender, dom.AsResource()); } catch (JsonException e) { logger_.Log("Error (4): " + e); } logger_.Verbose("locking putResourceCache"); lock (putResourceCache_) { allPuts.Add(future); } logger_.Verbose("releasing putResourceCache"); } logger_.Verbose("creating PutFutures for {0} runningRenders", runningRenders.Count); foreach (RunningRender runningRender in runningRenders) { CreatePutFutures_(allPuts, runningRender, resources); } logger_.Verbose("calling future.get on {0} PutFutures", allPuts.Count); foreach (PutFuture future in allPuts) { logger_.Verbose("calling future.get on {0}", future); try { future.Get(TimeSpan.FromSeconds(120)); } catch (Exception e) { logger_.Log("Error (5): " + e); } } logger_.Verbose("exit"); }
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 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); }
private IDictionary <string, RGridResource> BuildAllRGDoms_(IDictionary <string, RGridResource> resourceMapping, FrameData currentFrame) { Uri baseUrl = currentFrame.Url; logger_.Verbose("enter - baseUrl: " + baseUrl); ConcurrentDictionary <string, RGridResource> mapping = new ConcurrentDictionary <string, RGridResource>(); ConcurrentDictionary <string, RGridResource> frames = new ConcurrentDictionary <string, RGridResource>(); logger_.Verbose("iterating {0} sub-frames", currentFrame.Frames.Count); foreach (FrameData frame in currentFrame.Frames) { logger_.Verbose("iterating {0} sub-frame blobs", frame.Blobs.Count); foreach (BlobData blob in frame.Blobs) { string urlStr = blob.Url.OriginalString; if (resourceMapping.TryGetValue(urlStr, out RGridResource rGridResource)) { mapping.TryAdd(urlStr, rGridResource); } } logger_.Verbose("iterating {0} sub-frame resource urls", frame.ResourceUrls.Count); foreach (Uri resourceUrl in frame.ResourceUrls) { string urlStr = resourceUrl.OriginalString; if (resourceMapping.TryGetValue(urlStr, out RGridResource rGridResource)) { mapping.TryAdd(urlStr, rGridResource); } } Uri frameUrl = frame.Url; /*if ("about:blank".Equals(frameUrl.ToString(), StringComparison.OrdinalIgnoreCase)) * { * continue; * } * else */ if (!frameUrl.IsAbsoluteUri) { frameUrl = new Uri(baseUrl, frameUrl); } try { logger_.Verbose("entering recursion. url: {0}", frameUrl); IDictionary <string, RGridResource> innerFrameResourceMap = BuildAllRGDoms_(resourceMapping, frame); logger_.Verbose("exiting recursion. url: {0}", frameUrl); foreach (KeyValuePair <string, RGridResource> kvp in innerFrameResourceMap) { mapping.TryAdd(kvp.Key, kvp.Value); } logger_.Verbose("mapped resources: {0}", mapping.Count); // Sort mapped resources by their URL for constant, testable results. SortedDictionary <string, RGridResource> sortedMapping = new SortedDictionary <string, RGridResource>(mapping); RGridDom rGridDom = new RGridDom(frame.Cdt, sortedMapping, frameUrl, logger_, "buildAllRGDoms"); logger_.Verbose("adding resources to dictionary. url: {0}", frameUrl); RGridResource frameResource = rGridDom.AsResource(); resourceMapping[frameUrl.OriginalString] = frameResource; frames[frameUrl.OriginalString] = frameResource; } catch (Exception e) { logger_.Log("Error (10): " + e); } } logger_.Verbose("exit"); return(frames); }