internal FirefoxDriverServiceEx(string executablePath, string executableFileName, int port) : base(executablePath, port, executableFileName, FirefoxDriverDownloadUrl) { this.browserCommunicationPort = -1; this.browserBinaryPath = string.Empty; this.host = string.Empty; this.loggingLevel = FirefoxDriverLogLevel.Default; }
/// <summary> /// Sets the Firefox Options from the app.config file /// </summary> private void SetOptions() { try { FirefoxDriverLogLevel logLevel = FirefoxDriverLogLevel.Default; Enum.TryParse(Firefox.LogLevel, out logLevel); bool.TryParse(Firefox.CleanProfile, out bool cleanProfile); bool.TryParse(Firefox.UseLegacyImplementation, out bool legacy); string executable = BaseSettings.FirefoxLocation; string profile = Firefox.ProfileDirectory; FirefoxOptions options = new FirefoxOptions { BrowserExecutableLocation = executable, LogLevel = logLevel }; if (profile.Contains(@"\")) { options.Profile = new FirefoxProfile(profile, cleanProfile); } options.UseLegacyImplementation = legacy; Options = options; } catch (Exception ex) { switch (BaseSettings.DebugLevel) { case EnumConsoleDebugLevel.Human: Console.Out.WriteLine("Could not set the Firefox option settings."); break; case EnumConsoleDebugLevel.NotSpecified: case EnumConsoleDebugLevel.Message: Console.Out.WriteLine(ex.Message); break; case EnumConsoleDebugLevel.StackTrace: Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(ex.StackTrace); break; } Options = null; } }
/// <summary> /// Gets the capabilities for FIREFOX /// </summary> /// <param name="_logLevel"></param> /// <param name="_alertBehaviour"></param> /// <param name="acceptSlefSignedSSL"></param> /// <param name="_loadStrategy"></param> /// <returns></returns> private FirefoxOptions GetFirefoxBrowserOptions(FirefoxDriverLogLevel _logLevel = FirefoxDriverLogLevel.Default, UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default, bool acceptSlefSignedSSL = true, PageLoadStrategy _loadStrategy = PageLoadStrategy.Default) { FirefoxService = FirefoxDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"geckodriver.exe"); FirefoxService.HideCommandPromptWindow = true; FirefoxService.Start(); return(new FirefoxOptions() { LogLevel = _logLevel, UnhandledPromptBehavior = _alertBehaviour, PageLoadStrategy = _loadStrategy, AcceptInsecureCertificates = acceptSlefSignedSSL, UseLegacyImplementation = true }); }
private void ImportCapabilities(DesiredCapabilities capabilities) { foreach (KeyValuePair <string, object> pair in capabilities.CapabilitiesDictionary) { if (pair.Key == CapabilityType.BrowserName) { } else if (pair.Key == CapabilityType.BrowserVersion) { this.BrowserVersion = pair.Value.ToString(); } else if (pair.Key == CapabilityType.PlatformName) { this.PlatformName = pair.Value.ToString(); } else if (pair.Key == CapabilityType.Proxy) { this.Proxy = new Proxy(pair.Value as Dictionary <string, object>); } else if (pair.Key == CapabilityType.UnhandledPromptBehavior) { this.UnhandledPromptBehavior = (UnhandledPromptBehavior)Enum.Parse(typeof(UnhandledPromptBehavior), pair.Value.ToString(), true); } else if (pair.Key == CapabilityType.PageLoadStrategy) { this.PageLoadStrategy = (PageLoadStrategy)Enum.Parse(typeof(PageLoadStrategy), pair.Value.ToString(), true); } else if (pair.Key == FirefoxOptionsCapability) { Dictionary <string, object> mozFirefoxOptions = pair.Value as Dictionary <string, object>; foreach (KeyValuePair <string, object> option in mozFirefoxOptions) { if (option.Key == FirefoxArgumentsCapability) { object[] args = option.Value as object[]; for (int i = 0; i < args.Length; i++) { this.firefoxArguments.Add(args[i].ToString()); } } else if (option.Key == FirefoxPrefsCapability) { this.profilePreferences = option.Value as Dictionary <string, object>; } else if (option.Key == FirefoxLogCapability) { Dictionary <string, object> logDictionary = option.Value as Dictionary <string, object>; if (logDictionary.ContainsKey("level")) { this.logLevel = (FirefoxDriverLogLevel)Enum.Parse(typeof(FirefoxDriverLogLevel), logDictionary["level"].ToString(), true); } } else if (option.Key == FirefoxBinaryCapability) { this.browserBinaryLocation = option.Value.ToString(); } else if (option.Key == FirefoxProfileCapability) { this.profile = FirefoxProfile.FromBase64String(option.Value.ToString()); } else { this.AddAdditionalCapability(option.Key, option.Value); } } } else { this.AddAdditionalCapability(pair.Key, pair.Value, true); } } }