Exemple #1
0
        /// <summary>
        /// Starts a new Selenium testing session
        /// </summary>
        /// <param name="browser">Name of the browser : firefox, ie, chrome, phantomjs</param>
        /// <param name="baseUrl">The base URL</param>
        /// <example>
        /// <code lang="vbs">
        ///     Dim driver As New WebDriver()
        ///     driver.Start "firefox", "http://www.google.com"
        ///     driver.Get "/"
        /// </code>
        /// </example>
        public void Start(string browser = null, string baseUrl = null)
        {
            try {
                browser = ExpendBrowserName(browser);
                switch (browser)
                {
                case "firefox":
                    _service = FirefoxDriver.StartService(this);
                    break;

                case "chrome":
                    _service = ChromeDriver.StartService(this);
                    break;

                case "phantomjs":
                    _service = PhantomJSDriver.StartService(this);
                    break;

                case "internet explorer":
                    _service = IEDriver.StartService(this);
                    break;

                case "MicrosoftEdge":
                    _service = EdgeDriver.StartService(this);
                    break;

                case "opera":
                    _service = OperaDriver.StartService(this);
                    break;

                default:
                    throw new Errors.ArgumentError("Invalid browser name: {0}", browser);
                }

                this.Capabilities.BrowserName = browser;

                RegisterRunningObject();

                _session = new RemoteSession(_service.Uri, true, this.timeouts);
                _session.Start(this.Capabilities);

                if (!string.IsNullOrEmpty(baseUrl))
                {
                    this.BaseUrl = baseUrl;
                }
            } catch (SeleniumException) {
                throw;
            } catch (Exception ex) {
                throw new SeleniumException(ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Starts remotely a new Selenium testing session
        /// </summary>
        /// <param name="executorUri">Remote executor address (ex : "http://localhost:4444/wd/hub")</param>
        /// <param name="browser">Name of the browser : firefox, ie, chrome, phantomjs, htmlunit, htmlunitwithjavascript, android, ipad, opera</param>
        /// <param name="version">Browser version</param>
        /// <param name="platform">Platform: WINDOWS, LINUX, MAC, ANDROID...</param>
        /// <example>
        /// <code lang="vbs">
        ///     Dim driver As New WebDriver()
        ///     driver.StartRemotely "http://localhost:4444/wd/hub", "ie", 11
        ///     driver.Get "/"
        /// </code>
        /// </example>
        public void StartRemotely(string executorUri, string browser = null, string version = null, string platform = null)
        {
            try {
                browser = ExpendBrowserName(browser);
                switch (browser)
                {
                case "firefox":
                    FirefoxDriver.ExtendCapabilities(this, true);
                    break;

                case "chrome":
                    ChromeDriver.ExtendCapabilities(this, true);
                    break;

                case "phantomjs":
                    PhantomJSDriver.ExtendCapabilities(this, true);
                    break;

                case "internet explorer":
                    IEDriver.ExtendCapabilities(this, true);
                    break;

                case "MicrosoftEdge":
                    EdgeDriver.ExtendCapabilities(this, true);
                    break;

                case "opera":
                    OperaDriver.ExtendCapabilities(this, true);
                    break;
                }

                this.Capabilities.Platform    = platform;
                this.Capabilities.BrowserName = browser;
                if (!string.IsNullOrEmpty(version))
                {
                    this.Capabilities.BrowserVersion = version;
                }

                _session = new RemoteSession(executorUri, false, this.timeouts);
                _session.Start(this.Capabilities);

                RegisterRunningObject();
            } catch (SeleniumException) {
                throw;
            } catch (Exception ex) {
                throw new SeleniumException(ex);
            }
        }