Example #1
0
 internal static void AddBrowserCapabilities <T>(this T options, BrowserType browser, string testDetails)
 {
     if (browser == BrowserType.Chrome)
     {
         ChromeOptions chromeOptions = BaseUtil.ConvertToType <ChromeOptions>(options);
         chromeOptions.PageLoadStrategy = PageLoadStrategy.None;
         chromeOptions.AddArgument("no-sandbox");
         chromeOptions.AddAdditionalCapability("zal:tz", "America/Chicago", true);
         chromeOptions.AddAdditionalCapability("zal:name", testDetails, true);
         chromeOptions.AddAdditionalCapability("zal:screenResolution", "1600x900", true);
     }
     else if (browser == BrowserType.Firefox)
     {
         FirefoxOptions firefoxOptions = BaseUtil.ConvertToType <FirefoxOptions>(options);
         firefoxOptions.PageLoadStrategy = PageLoadStrategy.None;
         firefoxOptions.AddAdditionalCapability("zal:tz", "America/Chicago", true);
         firefoxOptions.AddAdditionalCapability("zal:name", testDetails, true);
         firefoxOptions.AddAdditionalCapability("zal:screenResolution", "1600x900", true);
     }
     else
     {
         DriverOptions _options = BaseUtil.ConvertToType <DriverOptions>(options);
         _options.PageLoadStrategy = PageLoadStrategy.None;
         _options.AddAdditionalCapability("zal:tz", "America/Chicago");
         _options.AddAdditionalCapability("zal:name", testDetails);
         _options.AddAdditionalCapability("zal:screenResolution", "1600x900");
     }
 }
 public static DriverOptions AddCredentials(DriverOptions opts, string username, string accessKey)
 {
     // May need to be overridden for BrowserStackBrowser
     opts.AddAdditionalCapability("username", username);
     opts.AddAdditionalCapability("accessKey", accessKey);
     return(opts);
 }
        public dynamic SetCapabilities(WebBrowserConfiguration webBrowserConfiguration)
        {
            DriverOptions option = DriverFactory.DriverFactoryList.Find(item => item.Name == webBrowserConfiguration.BrowserName).SetCapabilities(webBrowserConfiguration);

            option.AddAdditionalCapability("enableVNC", true);
            option.AddAdditionalCapability("enableVideo", false);



            return(option);
        }
Example #4
0
        /// <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)))
                {
                    switch (driverOptions)
                    {
                    case ChromeOptions chromeOptions:
                        chromeOptions.AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                        break;

                    case FirefoxOptions firefoxOptions:
                        firefoxOptions.AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                        break;

                    case InternetExplorerOptions ieOptions:
                        ieOptions.AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                        break;

                    default:
                        // Edge and Safari do not support marking capabilites as global  - AKA the third prameter
                        driverOptions.AddAdditionalCapability(keyValue.Key, keyValue.Value);
                        break;
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Instead of creating elegant and small method I have to develop this because AddAdditionalCapability does not set isGlobalCapability == true
        /// implicitly for some browsers. So for Chrome, IE, Firefox you should do it manually, for Safari, Edge - not (AddAdditionalCapability does not
        /// even have such parameter, same as base DriverOptions).
        /// </summary>
        /// <param name="options">Driver options.</param>
        /// <returns>DriverOptions.</returns>
        private static DriverOptions GetRemoteDesktopDriverOptions(DriverOptions options)
        {
            var capabilities = GetRemoteDesktopCapabilitiesSet();

            if (options.GetType() == typeof(ChromeOptions))
            {
                var chromeOptions = (ChromeOptions)options;
                chromeOptions.AddArgument(BrowserArguments.DisableWebSecurity);
                chromeOptions.AddArgument(BrowserArguments.DisableSiteIsolationTrials);
                capabilities.ToList().ForEach(pair => chromeOptions.AddAdditionalCapability(pair.Key, pair.Value, true));

                return(options);
            }

            if (options.GetType() == typeof(FirefoxOptions))
            {
                var firefoxOptions = (FirefoxOptions)options;
                capabilities.ToList().ForEach(pair => firefoxOptions.AddAdditionalCapability(pair.Key, pair.Value, true));

                return(options);
            }

            if (options.GetType() == typeof(InternetExplorerOptions))
            {
                var internetExplorerOptions = (InternetExplorerOptions)options;
                capabilities.ToList().ForEach(pair => internetExplorerOptions.AddAdditionalCapability(pair.Key, pair.Value, true));

                return(options);
            }

            capabilities.ToList().ForEach(pair => options.AddAdditionalCapability(pair.Key, pair.Value));

            return(options);
        }
Example #6
0
        /// <summary>
        /// Creates the remote driver.
        /// </summary>
        /// <returns>The created remote web driver.</returns>
        public IWebDriver Create()
        {
            var remoteUri = this.GetRemoteDriverUri();

            if (remoteUri == null)
            {
                return(this.CreateLocalDriver());
            }

            DriverOptions driverOptions = this.CreateRemoteDriverOptions();

            // Add any additional settings that are not reserved
            var envRegex         = new System.Text.RegularExpressions.Regex("\\$\\{(.+)\\}");
            var reservedSettings = new[] { RemoteUrlSetting };

            foreach (var setting in this.Settings
                     .OfType <NameValueConfigurationElement>()
                     .Where(s => reservedSettings
                            .All(r => !string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))))
            {
                // Support environment variables
                var value = setting.Value;
                var match = envRegex.Match(value);
                if (match.Success)
                {
                    value = SettingHelper.GetEnvironmentVariable(match.Groups[1].Value);
                }

                driverOptions.AddAdditionalCapability(setting.Name, value);
            }

            return(new RemoteScreenshotWebDriver(remoteUri, driverOptions.ToCapabilities()));
        }
Example #7
0
        /// <summary>
        /// Reads the RemoteSeleniumCapsMaqs section and appends to the driver options
        /// </summary>
        /// <param name="driverOptions">The driver options to make this an extension method</param>
        /// <returns>The altered <see cref="DriverOptions"/> driver options</returns>
        private static DriverOptions SetDriverOptions(this DriverOptions driverOptions)
        {
            Dictionary <string, string> remoteCapabilitySection = Config.GetSection(ConfigSection.RemoteSeleniumCapsMaqs);

            if (remoteCapabilitySection == null)
            {
                return(driverOptions);
            }

            foreach (KeyValuePair <string, string> keyValue in remoteCapabilitySection)
            {
                if (remoteCapabilitySection[keyValue.Key].Length > 0)
                {
                    if (driverOptions is ChromeOptions)
                    {
                        ((ChromeOptions)driverOptions).AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                    }
                    else if (driverOptions is FirefoxOptions)
                    {
                        ((FirefoxOptions)driverOptions).AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                    }
                    else if (driverOptions is InternetExplorerOptions)
                    {
                        ((InternetExplorerOptions)driverOptions).AddAdditionalCapability(keyValue.Key, keyValue.Value, true);
                    }
                    else
                    {
                        driverOptions.AddAdditionalCapability(keyValue.Key, keyValue.Value);
                    }
                }
            }

            return(driverOptions);
        }
 private static void AddAdditionalCapabilies(this DriverOptions options, WebDriverConfig config)
 {
     if (config.AdditionalCapabilities != null)
     {
         foreach (var capability in config.AdditionalCapabilities)
         {
             options.AddAdditionalCapability(capability.Key, capability.Value);
         }
     }
 }
Example #9
0
        private DriverOptions GetDesiredCapabilities(IAutomationConfiguration config)
        {
            DriverOptions result = config.SauceLabsBrowser switch
            {
                "IE" => new InternetExplorerOptions(),
                "Chrome" => new ChromeOptions(),
                _ => new FirefoxOptions(),
            };

            string[] usernameKey = config.SauceLabsKey.Split(':');

            if (usernameKey.Length != 2)
            {
                throw new Exception(string.Format("SauceLabsKey found in config file is not as expected.  Expected username:key in the value attribute"));
            }

            result.AddAdditionalCapability("username", usernameKey[0]);
            result.AddAdditionalCapability("accessKey", usernameKey[1]);
            result.AddAdditionalCapability("platform", config.SauceLabsPlatform);
            return(result);
        }
Example #10
0
 public static void AddAdditionalCapabilities(this DriverOptions options,
                                              Dictionary <string, object> capabilities)
 {
     if (capabilities == null)
     {
         return;
     }
     foreach (var entry in capabilities.Keys)
     {
         options.AddAdditionalCapability(entry, capabilities[entry]);
     }
 }
        /// <summary>
        ///  If the design mode is chosen then the driver will use NeoLoad as Proxy.
        /// </summary>
        /// <param name="options">driver options to modify</param>
        /// <returns>modified driver options</returns>
        public static void AddProxyCapabilitiesIfNecessary(DriverOptions options)
        {
            if (!Mode.DESIGN.Equals(ModeHelper.getMode()))
            {
                return;
            }

            DesignConfiguration conf = ConfigurationHelper.newDesignConfiguration(null, null);
            string host = getDomainName(conf.DesignAPIUrl);
            int    port;

            try
            {
                port = DesignManager.newDesignAPIClientFromConfig(conf).GetRecorderSettings().ProxySettings.Port;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw e;
            }
            string proxyString = host + ":" + port;

            Proxy proxy = new Proxy();

            proxy.HttpProxy = proxyString;
            proxy.SslProxy  = proxyString;

            if (options is ChromeOptions)
            {
                (options as ChromeOptions).Proxy = proxy;
            }
            else
            {
                options.AddAdditionalCapability(CapabilityType.Proxy, proxy);
                options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
            }
            return;
        }
Example #12
0
        public void SetAdditionalCapability(DriverOptions options)
        {
            if (AdditionalCapability == null)
            {
                return;
            }

            foreach (var additionalCapability in AdditionalCapability)
            {
                options.AddAdditionalCapability(
                    additionalCapability.Key,
                    additionalCapability.Value);
            }
        }
 /// <summary>
 /// Set additional capabilities on driver
 /// </summary>
 /// <param name="additionalCapability">key value pair for additional capabilities.</param>
 internal void SetAdditionalOptions(Dictionary <string, object> additionalCapability = null)
 {
     if (additionalCapability != null && additionalCapability.Count > 0)
     {
         ICapabilities existingCaps = this.options.ToCapabilities();
         //Log Section
         TestLogs.WriteLogSection("Test Specific Capabilities",
                                  () => {
             foreach (KeyValuePair <string, object> capability in additionalCapability)
             {
                 LogOverrideSetCapability(capability, existingCaps);
                 options.AddAdditionalCapability(capability.Key, capability.Value);
             }
         });
     }
 }
        private static DriverOptions AddRemoteCapibilitiesFromConfig(DriverOptions options)
        {
            var caps = WebConfig.RemoteCapabilities.Split(';');

            if (caps[0] == "")
            {
                return(options);
            }
            foreach (var cap in caps)
            {
                var capsSplit       = cap.Split(',');
                var capibilityName  = capsSplit[0];
                var capibilityValue = capsSplit[1];
                options.AddAdditionalCapability(capibilityName, capibilityValue);
            }
            return(options);
        }
        // load option: capabilities
        private void LoadCapabilities(DriverOptions driverOptions)
        {
            // exit conditions
            if (AdditionalCapabilities == null || AdditionalCapabilities.Count == 0)
            {
                return;
            }

            // append capabilities
            foreach (var capability in AdditionalCapabilities)
            {
                try
                {
                    driverOptions.AddAdditionalCapability(capability.Key, capability.Value);
                }
                catch (Exception e)
                {
                    Trace.TraceWarning(e.Message);
                }
            }
        }
        internal static IWebDriver InitializeDriver(string browserType)
        {
            string hubIpAddress = JsonConfig.GetJsonValue("HubIpAddress");

            remoteWebDriverWaitTime = JsonConfig.GetJsonValue("RemoteWebdriverWait");
            elementLoadWaitTime     = JsonConfig.GetJsonValue("ElementWaitTime");
            pageLoadWaitTime        = JsonConfig.GetJsonValue("PageLoad");

            IWebDriver _driver = null;

            var browser = browserType.ToLower();

            try
            {
                switch (browser)
                {
                case "ie":
                    option = new InternetExplorerOptions();
                    option.AddAdditionalCapability("--window-size=1920,1080", true);
                    option.AddAdditionalCapability("--start-maximized", true);
                    option.AddAdditionalCapability("", true);
                    break;

                case "chrome":
                    chromeOptions = new ChromeOptions();
                    //chromeOptions.PlatformName = "LINUX";
                    chromeOptions.AddArgument("no-sandbox");
                    chromeOptions.AddArgument("--headless");
                    //chromeOptions.AddArgument("--start-maximized");
                    break;

                case "firefox":
                    option = new FirefoxOptions();
                    //option.PlatformName = "LINUX";
                    break;

                case "edge":
                    option = new EdgeOptions();
                    option.AddAdditionalCapability("--window-size=1920,1080", true);
                    option.AddAdditionalCapability("--start-maximized", true);
                    break;

                case "localhost":
                    _driver = new FirefoxDriver();
                    _driver.Manage().Window.Size = new Size(1920, 1080);
                    _driver.Manage().Window.Maximize();
                    break;
                }


                if (browser.Equals("chrome"))
                {
                    _driver = new RemoteWebDriver(new Uri($"{hubIpAddress}"), chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(int.Parse(remoteWebDriverWaitTime)));
                    _driver.Manage().Window.Size = new Size(1920, 1080);
                    _driver.Manage().Window.Maximize();
                }
                else if (browser.Equals("firefox"))
                {
                    _driver = new RemoteWebDriver(new Uri($"{hubIpAddress}"), option.ToCapabilities(), TimeSpan.FromSeconds(int.Parse(remoteWebDriverWaitTime)));
                    _driver.Manage().Window.Size = new Size(1920, 1080);
                    _driver.Manage().Window.Maximize();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(int.Parse(elementLoadWaitTime));
            _driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(int.Parse(pageLoadWaitTime));
            _driver.Manage().Cookies.DeleteAllCookies();
            var allowsDetection = (OpenQA.Selenium.IAllowsFileDetection)_driver;

            allowsDetection.FileDetector = new LocalFileDetector();
            return(_driver);
        }
Example #17
0
 internal static ICapabilities SetPlatformToCapabilities(DriverOptions dc, string desiredPlatform)
 {
     dc.AddAdditionalCapability(MobileCapabilityType.PlatformName, desiredPlatform);
     return(dc.ToCapabilities());
 }
 public static DriverOptions AddTestName(DriverOptions opts, string name)
 {
     opts.AddAdditionalCapability("name", name);
     return(opts);
 }