Exemplo n.º 1
0
        // Protected members

        protected override Uri GetWebDriverUri(IWebBrowserInfo webBrowserInfo, IHttpWebRequestFactory webRequestFactory)
        {
            Uri versionUri = new Uri("https://chromedriver.storage.googleapis.com/LATEST_RELEASE");

            // If we can get the current version of Google Chrome, we can select an exact web driver version.

            Version browserVersion = webBrowserInfo?.Version;

            if (browserVersion is object)
            {
                versionUri = new Uri(versionUri.AbsoluteUri + $"_{browserVersion.Major}.{browserVersion.Minor}.{browserVersion.Build}");
            }

            using (IWebClient webClient = webRequestFactory.ToWebClientFactory().Create()) {
                // Get the latest web driver version.

                string latestVersionString = webClient.DownloadString(versionUri);

                // Create a download URL for this version.

                if (!string.IsNullOrWhiteSpace(latestVersionString))
                {
                    Uri downloadUri = new Uri(versionUri, $"/{latestVersionString}/chromedriver_{GetPlatformOS()}.zip");

                    return(downloadUri);
                }
            }

            // We weren't able to get information on the latest web driver.

            return(null);
        }
Exemplo n.º 2
0
        private bool DownloadWebDriver(IWebBrowserInfo webBrowserInfo, CancellationToken cancellationToken)
        {
            string webDriverExecutablePath = GetWebDriverExecutablePathInternal();

            OnLog.Info("Getting web driver download url");

            Uri    webDriverDownloadUri = GetWebDriverUri(webBrowserInfo, webRequestFactory);
            string downloadFilePath     = PathUtilities.SetFileExtension(Path.GetTempFileName(), ".zip");

            if (webDriverDownloadUri is object)
            {
                OnLog.Info($"Downloading {webDriverDownloadUri}");

                using (IWebClient webClient = webRequestFactory.ToWebClientFactory().Create()) {
                    webClient.DownloadProgressChanged += (sender, e) => OnDownloadFileProgressChanged(this, new DownloadFileProgressChangedEventArgs(webDriverDownloadUri, downloadFilePath, e));
                    webClient.DownloadFileCompleted   += (sender, e) => OnDownloadFileCompleted(this, new DownloadFileCompletedEventArgs(webDriverDownloadUri, downloadFilePath, e.Error is null));

                    webClient.DownloadFileSync(webDriverDownloadUri, downloadFilePath, cancellationToken);
                }

                try {
                    string filePathInArchive = PathUtilities.GetFilename(webDriverExecutablePath);

                    OnLog.Info($"Extracting {filePathInArchive}");

                    ArchiveUtilities.ExtractFile(downloadFilePath, filePathInArchive, webDriverExecutablePath);
                }
                catch (Exception ex) {
                    OnLog.Error(ex.ToString());

                    throw ex;
                }
                finally {
                    File.Delete(downloadFilePath);
                }

                // We were able to successfully update the web driver.

                return(true);
            }

            // We were not able to successfully update the web driver.

            return(false);
        }
Exemplo n.º 3
0
 private IWebClient CreateWebClient()
 {
     return(webRequestFactory.ToWebClientFactory().Create());
 }
 public static IWebClient CreateWebClient(this IHttpWebRequestFactory webRequestFactory)
 {
     return(webRequestFactory.ToWebClientFactory().Create());
 }