Ejemplo n.º 1
0
        /// <summary>
        /// Get the remote driver options
        /// </summary>
        /// <param name="remoteBrowser">The remote browser type</param>
        /// <param name="remotePlatform">The remote platform</param>
        /// <param name="remoteBrowserVersion">The remote browser version</param>
        /// <param name="remoteCapabilities">Additional remote capabilities</param>
        /// <returns>The remote driver options</returns>
        public static DriverOptions GetRemoteOptions(RemoteBrowserType remoteBrowser, string remotePlatform, string remoteBrowserVersion, Dictionary <string, object> remoteCapabilities)
        {
            DriverOptions options = null;

            switch (remoteBrowser)
            {
            case RemoteBrowserType.IE:
                options = new InternetExplorerOptions();
                break;

            case RemoteBrowserType.Firefox:
                options = new FirefoxOptions();
                break;

            case RemoteBrowserType.Chrome:
                options = new ChromeOptions();
                break;

            case RemoteBrowserType.Edge:
                options = new EdgeOptions();
                break;

            case RemoteBrowserType.Safari:
                options = new SafariOptions();
                break;

            default:
                throw new ArgumentException(StringProcessor.SafeFormatter("Remote browser type '{0}' is not supported", remoteBrowser));
            }

            // Make sure the remote capabilities dictonary exists
            if (remoteCapabilities == null)
            {
                remoteCapabilities = new Dictionary <string, object>();
            }

            // Add a platform setting if one was provided
            if (!string.IsNullOrEmpty(remotePlatform) && !remoteCapabilities.ContainsKey("platform"))
            {
                remoteCapabilities.Add("platform", remotePlatform);
            }

            // Add a remote browser setting if one was provided
            if (!string.IsNullOrEmpty(remoteBrowserVersion) && !remoteCapabilities.ContainsKey("version"))
            {
                remoteCapabilities.Add("version", remoteBrowserVersion);
            }

            // Add additional capabilities to the driver options
            options.SetDriverOptions(remoteCapabilities);

            return(options);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the remote desired capability
        /// </summary>
        /// <returns>The remote desired capability</returns>
        private static ICapabilities GetRemoteCapabilities()
        {
            DriverOptions options              = null;
            string        remoteBrowser        = GetRemoteBrowserName();
            string        remotePlatform       = GetRemotePlatform();
            string        remoteBrowserVersion = GetRemoteBrowserVersion();

            switch (remoteBrowser.ToUpper())
            {
            case "INTERNET EXPLORER":
            case "INTERNETEXPLORER":
            case "IE":
                options = new InternetExplorerOptions();
                break;

            case "FIREFOX":
                options = new FirefoxOptions();
                break;

            case "CHROME":
                options = new ChromeOptions();
                break;

            case "EDGE":
                options = new EdgeOptions();
                break;

            case "SAFARI":
                options = new SafariOptions();
                break;

            default:
                throw new ArgumentException(StringProcessor.SafeFormatter("Remote browser type '{0}' is not supported", remoteBrowser));
            }

            // Add a platform setting if one was provided
            if (remotePlatform.Length > 0)
            {
                options.AddAdditionalCapability("platform", remotePlatform);
            }

            // Add a remote browser setting if one was provided
            if (remoteBrowserVersion.Length > 0)
            {
                options.AddAdditionalCapability("version", remoteBrowserVersion);
            }

            // Add RemoteCapabilites section if it exists
            options.SetDriverOptions();

            return(options.ToCapabilities());
        }