/// <summary>
        /// Checks to see if settings for the remote driver exists.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="remoteWebDriver">The created remote web driver.</param>
        /// <returns><c>true</c> if the settings exist; otherwise <c>false</c>.</returns>
        private static bool RemoteDriverExists(NameValueConfigurationCollection settings, BrowserType browserType, out IWebDriver remoteWebDriver)
        {
            var remoteUri = GetRemoteDriverUri(settings);

            if (remoteUri == null)
            {
                remoteWebDriver = null;
                return(false);
            }

            DesiredCapabilities capability;

            switch (browserType)
            {
            case BrowserType.IE:
                capability = DesiredCapabilities.InternetExplorer();
                break;

            case BrowserType.FireFox:
                capability = DesiredCapabilities.Firefox();
                break;

            case BrowserType.Chrome:
                capability = DesiredCapabilities.Chrome();
                break;

            case BrowserType.Safari:
                capability = DesiredCapabilities.Safari();
                break;

            case BrowserType.Opera:
                capability = DesiredCapabilities.Opera();
                break;

            case BrowserType.Android:
                capability = DesiredCapabilities.Android();
                break;

            case BrowserType.iPhone:
                capability = DesiredCapabilities.IPhone();
                break;

            case BrowserType.iPad:
                capability = DesiredCapabilities.IPad();
                break;

            case BrowserType.PhantomJS:
                capability = DesiredCapabilities.PhantomJS();
                break;

            default:
                throw new InvalidOperationException(string.Format("Browser Type '{0}' is not supported as a remote driver.", browserType));
            }

            // Add any additional settings that are not reserved
            var reservedSettings = new[] { RemoteUrlSetting };

            foreach (var setting in settings.OfType <NameValueConfigurationElement>()
                     .Where(s => reservedSettings.All(r => !string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))))
            {
                capability.SetCapability(setting.Name, setting.Value);
            }

            remoteWebDriver = new RemoteScreenshotWebDriver(remoteUri, capability);
            return(true);
        }
        /// <summary>
        /// Checks to see if settings for the remote driver exists.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="remoteWebDriver">The created remote web driver.</param>
        /// <returns><c>true</c> if the settings exist; otherwise <c>false</c>.</returns>
        private static bool RemoteDriverExists(NameValueConfigurationCollection settings, BrowserType browserType, out IWebDriver remoteWebDriver)
        {
            var remoteUri = GetRemoteDriverUri(settings);

            if (remoteUri == null)
            {
                remoteWebDriver = null;
                return false;
            }

            DesiredCapabilities capability;
            switch (browserType)
            {
                case BrowserType.IE:
                    capability = DesiredCapabilities.InternetExplorer();
                    break;
                case BrowserType.FireFox:
                    capability = DesiredCapabilities.Firefox();
                    break;
                case BrowserType.Chrome:
                    capability = DesiredCapabilities.Chrome();
                    break;
                case BrowserType.Safari:
                    capability = DesiredCapabilities.Safari();
                    break;
                case BrowserType.Opera:
                    capability = DesiredCapabilities.Opera();
                    break;
                case BrowserType.Android:
                    capability = DesiredCapabilities.Android();
                    break;
                case BrowserType.iPhone:
                    capability = DesiredCapabilities.IPhone();
                    break;
                case BrowserType.iPad:
                    capability = DesiredCapabilities.IPad();
                    break;
                case BrowserType.PhantomJS:
                    capability = DesiredCapabilities.PhantomJS();
                    break;
				case BrowserType.Edge:
					capability = DesiredCapabilities.Edge();
					break;
                default:
                    throw new InvalidOperationException(string.Format("Browser Type '{0}' is not supported as a remote driver.", browserType));
            }

            // Add any additional settings that are not reserved
            var envRegex = new System.Text.RegularExpressions.Regex("\\$\\{(.+)\\}");
            var reservedSettings = new[] { RemoteUrlSetting };
            foreach (var setting in 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);
                }

                capability.SetCapability(setting.Name, value);
            }

            remoteWebDriver = new RemoteScreenshotWebDriver(remoteUri, capability);
            return true;
        }
Exemple #3
0
        /// <summary>
        /// Checks to see if settings for the remote driver exists.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="remoteWebDriver">The created remote web driver.</param>
        /// <returns><c>true</c> if the settings exist; otherwise <c>false</c>.</returns>
        private static bool RemoteDriverExists(NameValueConfigurationCollection settings, BrowserType browserType, out IWebDriver remoteWebDriver)
        {
            var remoteUri = GetRemoteDriverUri(settings);

            if (remoteUri == null)
            {
                remoteWebDriver = null;
                return(false);
            }

            DriverOptions driverOptions;

            switch (browserType)
            {
            case BrowserType.IE:
                driverOptions = new InternetExplorerOptions();
                break;

            case BrowserType.FireFox:
                driverOptions = new FirefoxOptions();
                break;

            case BrowserType.Chrome:
                driverOptions = new ChromeOptions();
                break;

            case BrowserType.Safari:
                driverOptions = new SafariOptions();
                break;

            case BrowserType.Opera:
                driverOptions = new OperaOptions();
                break;

            case BrowserType.PhantomJS:
                driverOptions = new PhantomJSOptions();
                break;

            case BrowserType.Edge:
                driverOptions = new EdgeOptions();
                break;

            default:
                throw new InvalidOperationException(
                          $"Browser Type '{browserType}' is not supported as a remote driver.");
            }

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

            foreach (var setting in 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);
            }

            remoteWebDriver = new RemoteScreenshotWebDriver(remoteUri, driverOptions.ToCapabilities());
            return(true);
        }