Exemplo n.º 1
0
        // Protected members

        protected override Uri GetWebDriverUri(IWebBrowserInfo webBrowserInfo, IHttpWebRequestFactory webRequestFactory)
        {
            // Note that Edge and EdgeHTML use different web drivers-- MicrosoftEdgeDriver.exe and msedgedriver.exe, respectively.
            // The latest version of EdgeHTML is 18.19041, so that can be used to determine which web driver to download.
            // Currently, this method only gets web driver URIs for Edge, and not EdgeHTML.

            string edgeMajorVersionStr = webBrowserInfo.Version.Major.ToString(CultureInfo.InvariantCulture);

            // We'll get an XML document listing all web driver versions available for this version of Edge.
            // There might not be one for this specific version, so we'll pick the closest.

            using (IWebClient client = webRequestFactory.CreateWebClient()) {
                int    maxResults  = 999;
                string responseXml = client.DownloadString($"https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver?prefix={edgeMajorVersionStr}&delimiter=%2F&maxresults={maxResults}&restype=container&comp=list");

                string webDriverVersionStr = Regex.Matches(responseXml, @"<Name>([\d.]+)", RegexOptions.IgnoreCase).Cast <Match>()
                                             .Select(m => m.Groups[1].Value) // version strings
                                             .OrderByDescending(versionString => CountMatchingRevisions(versionString, edgeMajorVersionStr))
                                             .ThenByDescending(versionString => versionString, new NaturalSortComparer())
                                             .FirstOrDefault();

                if (string.IsNullOrWhiteSpace(webDriverVersionStr))
                {
                    webDriverVersionStr = edgeMajorVersionStr;
                }

                return(new Uri($"https://msedgedriver.azureedge.net/{webDriverVersionStr}/edgedriver_{GetPlatformOS()}.zip"));
            }
        }