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;
                string        protocolJson;
                using (var chrome = Chrome.OpenChrome())
                {
                    currentVersion = await chrome.GetChromeVersion();

                    protocolJson = await chrome.GetProtocolAsJson();
                }

                protocolData = JObject.Parse(protocolJson);
                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);
        }
Exemplo n.º 2
0
        public static async Task <JsonSchema4> GetProtocolDefinitionSchema(CliArguments args)
        {
            JsonSchema4 protocolSchema;

            if (args.GenerateProtocolSchema || !File.Exists(args.ProtocolSchemaPath))
            {
                Console.WriteLine("Generating protocol definition from current generator interface...");

                protocolSchema = await JsonSchema4.FromTypeAsync <ProtocolDefinition>(new JsonSchemaGeneratorSettings()
                {
                    FlattenInheritanceHierarchy = true
                });
            }
            else
            {
                Console.WriteLine("Using previously obtained protocol schema...");
                protocolSchema = await JsonSchema4.FromFileAsync(args.ProtocolSchemaPath);
            }

            return(protocolSchema);
        }
Exemplo n.º 3
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);
        }