/// <summary> /// Add additional capabilities to the driver options /// </summary> /// <param name="driverOptions">The driver option you want to add capabilities to</param> /// <param name="additionalCapabilities">Capabilities to add</param> public static void SetDriverOptions(this DriverOptions driverOptions, Dictionary <string, object> additionalCapabilities) { // If there are no additional capabilities just return if (additionalCapabilities == null) { return; } foreach (KeyValuePair <string, object> keyValue in additionalCapabilities) { // Make sure there is a value if (keyValue.Value != null && (!(keyValue.Value is string) || !string.IsNullOrEmpty(keyValue.Value as string))) { // Handle W3C complient keys if (keyValue.Key.Contains(":")) { try { // Check if this is a Json string var jsonDictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(keyValue.Value as string); driverOptions.AddAdditionalOption(keyValue.Key, jsonDictionary); } catch { // Not Json string so add as a normal string driverOptions.AddAdditionalOption(keyValue.Key, keyValue.Value); } } else { switch (driverOptions) { case ChromeOptions chromeOptions: chromeOptions.AddAdditionalChromeOption(keyValue.Key, keyValue.Value); break; case FirefoxOptions firefoxOptions: firefoxOptions.AddAdditionalFirefoxOption(keyValue.Key, keyValue.Value); break; case InternetExplorerOptions ieOptions: ieOptions.AddAdditionalInternetExplorerOption(keyValue.Key, keyValue.Value); break; case EdgeOptions ieOptions: ieOptions.AddAdditionalEdgeOption(keyValue.Key, keyValue.Value); break; default: // Not one of our 4 main types driverOptions.AddAdditionalOption(keyValue.Key, keyValue.Value); break; } } } } }
private static DriverOptions SetDriverOptions(DriverOptions options, string browser) { var tunnel = Config.Settings.BrowserStackSettings.BsTunnel; var build = Config.Settings.BrowserStackSettings.BsBuildVersion; var os = Config.Settings.BrowserStackSettings.BsOs; var osVersion = Config.Settings.BrowserStackSettings.BsOsVersion; var browserVersion = Config.Settings.BrowserStackSettings.BsBrowserVersion; var browserStackDebug = Config.Settings.BrowserStackSettings.BsDebug; var acceptSslCerts = Config.Settings.BrowserStackSettings.BsAcceptSslCerts; var resolution = Config.Settings.BrowserStackSettings.BsResolution; var platform = Config.Settings.BrowserStackSettings.BsPlatform; var browserName = Config.Settings.BrowserStackSettings.BsBrowserName; var device = Config.Settings.BrowserStackSettings.BsDevice; var autoAcceptAlerts = Config.Settings.AppiumSettings.AutoAcceptAlerts; options.AddAdditionalOption("browserstack.user", Config.Settings.BrowserStackSettings.BsUser); options.AddAdditionalOption("browserstack.key", Config.Settings.BrowserStackSettings.BsKey); options.AddAdditionalOption("project", Config.Settings.BrowserStackSettings.BsProjectName); options.AddAdditionalOption("browser", "Chrome"); if (browser != "android" || browser != "iPad" || browser != "iPhone") //Not applicable for mobile { options.AddAdditionalOption("browser", browser); } if (tunnel) { options.AddAdditionalOption("browserstack.tunnel", "true"); } if (build != null) { options.AddAdditionalOption("build", build); } if (os != null) { options.AddAdditionalOption("os", os); } if (osVersion != null) { options.AddAdditionalOption("os_version", osVersion); } if (browserVersion != null) { options.AddAdditionalOption("browser_version", browserVersion); } if (browserStackDebug != null) { options.AddAdditionalOption("browserstack.debug", browserStackDebug); } if (acceptSslCerts != null) { options.AddAdditionalOption("acceptSslCerts", acceptSslCerts); } if (resolution != null) { options.AddAdditionalOption("resolution", resolution); } if (browser == "android" || browser == "iPad" || browser == "iPhone") //Only for mobile { options.AddAdditionalOption("browser", browserName); options.AddAdditionalOption("device", device); options.AddAdditionalOption("realMobile", "true"); } if (autoAcceptAlerts != null) { options.AddAdditionalOption("autoAcceptAlerts", autoAcceptAlerts); } return(options); }