ToCapabilities() private méthode

Returns DesiredCapabilities for Chrome with these options included as capabilities. This does not copy the options. Further changes will be reflected in the returned capabilities.
private ToCapabilities ( ) : ICapabilities
Résultat ICapabilities
Exemple #1
1
        public static IWebDriver CreateChromeGridDriver(string profileName, string hubAddress)
        {
            if (hubAddress == null)
            {
                throw new ArgumentException("remoteAddress");
            }

            var chromeOptions = new ChromeOptions();
            if (!string.IsNullOrWhiteSpace(profileName))
            {
                var fileChars = Path.GetInvalidFileNameChars();
                var pathChars = Path.GetInvalidFileNameChars();
                var invalidChars = fileChars.Union(pathChars);

                profileName = String.Join("", profileName.Where(c => !invalidChars.Contains(c)));

                chromeOptions.AddArguments(String.Format("user-data-dir=c:\\ChromeProfiles\\{0}", profileName));
            }

            RemoteWebDriver Driver = new RemoteWebDriver(new Uri(hubAddress), chromeOptions.ToCapabilities());

            Driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
            Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
            Driver.Manage().Window.Maximize();
            return Driver;
        }
Exemple #2
0
        public void Start()
        {
            var options = new ChromeOptions();
              options.AddArgument("--test-type");

              Instance = new RemoteWebDriver(ChromeDriver.BaseUrl, options.ToCapabilities());
        }
 private static ICapabilities ConvertOptionsToCapabilities(ChromeOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options", "options must not be null");
     }
     return(options.ToCapabilities());
 }
 private static void CrawlFirstPage(Uri startUrl)
 {
     ChromeOptions chromeOptions = new ChromeOptions();
     chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
     
     var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
     try
     {
         _driver.Navigate().GoToUrl(startUrl);
         SaveHtmlAndScreenShot(startUrl, _driver);
         pageVisitedURLMapping.TryAdd(startUrl, startUrl);
         _driver.Close();
         _driver.Quit();
     }
     catch (Exception ex)
     {
         logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
         _driver.Close();
         _driver.Quit();
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ChromeDriver"/> class using the specified <see cref="ChromeDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="ChromeDriverService"/> to use.</param>
 /// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
 {
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the ChromeDriver class using the specified <see cref="ChromeDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="ChromeDriverService"/> to use.</param>
 /// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public ChromeDriver(DriverService service, ChromeOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
 {
 }
Exemple #7
0
        private static ICapabilities ConvertOptionsToCapabilities(ChromeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "options must not be null");
            }

            return options.ToCapabilities();
        }
        public static void CrawlPage(Uri startUrl)
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
            chromeOptions.AddArgument("user-data-dir=C:/Debug/" + startUrl.AbsolutePath);
            var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
            
            try
            {
                ConcurrentDictionary<Uri, Uri> pageToVisit = new ConcurrentDictionary<Uri, Uri>();
                ConcurrentDictionary<Uri, Uri> PartThreading;
                pageToVisit.TryAdd(startUrl, null);
                
                while (true && pageToVisit.Count > 0)
                {
                    PartThreading = new ConcurrentDictionary<Uri, Uri>();
                    logger.Info(_options.Name + " Thread : " + startUrl.PathAndQuery + " Page To Visit Size :{0}", pageToVisit.Count + " SessionId" + _driver.SessionId );
                    foreach (var pTV in pageToVisit)
                    {

                        PartThreading.TryAdd(pTV.Key, pTV.Value);
                        Uri value;
                        pageToVisit.TryRemove(pTV.Key, out value);
                    }
                    foreach (var Key in PartThreading.Keys)
                    {
                        _driver.Navigate().GoToUrl(Key);
                        
                        SaveHtmlAndScreenShot(Key, _driver);
                        pageToVisit = GetUnvisitedLinks(_driver, Key, _driver.Url, PartThreading, pageToVisit, startUrl);
                        pageVisitedURLMapping.TryAdd(Key, PartThreading[Key]);
                        
                        ValidatePage(_driver, Key, PartThreading[Key]);

                    }

                    logger.Info(" Thread : " + startUrl.PathAndQuery + " Page Finish Visit Size :{0}",   pageVisitedURLMapping.Count);

                }
                _driver.Close();
                _driver.Quit();
            }
            catch (Exception ex)
            {
                logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
                _driver.Close();
                _driver.Quit();
            }


        }
        public static RemoteWebDriver InitializeChromeDriver(Uri serviceUrl)
        {
            ChromeOptions options = new ChromeOptions();
            var perfLoggingPrefs = new Dictionary<string, object> { { "enableNetwork", true }, { "enablePage", true }, { "enableTimeline", false } };
            try
            {
                string perf = ConfigurationManager.AppSettings["ChromeDriver.PerfLogging"];
                if ("false" != perf.ToLower())
                {
                    options.AddAdditionalCapability("perfLoggingPrefs", perfLoggingPrefs);
                }
                            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                // Swallow non-existent Configurations
            }

            try
            {
                string mobile = ConfigurationManager.AppSettings["ChromeDriver.MobileEmulationDevice"];
                if ("false" != mobile.ToLower())
                {
                    options.AddAdditionalCapability("mobileEmulation",
                        new Dictionary<string, object> {{"deviceName", mobile}});
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                // Swallow non-existent Configurations
            }

            try
            {
                options.AddArgument("--lang=" + ConfigurationManager.AppSettings["ChromeDriver.language"]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                // Swallow non-existent Configurations
            }

            DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
            var loggingPrefs = new Dictionary<string, object> { { "performance", "ALL" }, { "browser", "ALL" } };
            try
            {
                string perf = ConfigurationManager.AppSettings["ChromeDriver.PerfLogging"];
                if ("false" != perf.ToLower())
                {
                    capabilities.SetCapability("loggingPrefs", loggingPrefs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                // Swallow non-existent Configurations
            }

            return new RemoteWebDriver(serviceUrl, capabilities);
        }