Exemplo n.º 1
0
        /// <summary>
        /// Returns a merged ProtocolDefinition JObject
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static async Task <JObject> GetProtocolDefinitionData(CliArguments args)
        {
            JObject protocolData;

            if (args.ForceDownload || !File.Exists(args.ProtocolPath))
            {
                Console.WriteLine("Obtaining protocol definition from installed Chrome version...");

                ChromeVersion currentVersion;
                using (var chrome = Chrome.OpenChrome())
                {
                    currentVersion = await chrome.GetChromeVersion();
                }

                var browserProtocolPdl = await Chrome.GetBrowserProtocolForChromeVersion(currentVersion);

                var javaScriptProtocolPdl = await Chrome.GetJavaScriptProtocolForChromeVersion(currentVersion);

                var pdlScript = await Chrome.GetInspectorProtocolConverterPythonScript(currentVersion);

                var pdlConverter    = new PdlConverter(pdlScript);
                var browserProtocol = pdlConverter.ToJson(browserProtocolPdl, "browser_protocol.pdl");
                var jsProtocol      = pdlConverter.ToJson(javaScriptProtocolPdl, "js_protocol.pdl");

                protocolData = Chrome.MergeJavaScriptProtocolDefinitions(browserProtocol, jsProtocol);
                protocolData["chromeVersion"] = JToken.FromObject(currentVersion);
                File.WriteAllText(args.ProtocolPath, JsonConvert.SerializeObject(protocolData, Formatting.Indented));
            }
            else
            {
                Console.WriteLine("Using previously obtained protocol definition...");
                var protocolJson = File.ReadAllText(args.ProtocolPath);
                protocolData = JObject.Parse(protocolJson);
            }

            return(protocolData);
        }