Example #1
0
        public void Initialize_should_be_able_to_start_new_browser()
        {
            WebDriverOptions options = new WebDriverOptions()
            {
                BrowserName = WebDriverOptions.browser_HtmlUnitWithJavaScript,
                RemoteUrl   = "http://localhost:4444/wd/hub/",
            };

            bool isSeleniumServerAvailable = true;

            try
            {
                SwdBrowser.TestRemoteHub(options.RemoteUrl);
            }
            catch (Exception e)
            {
                isSeleniumServerAvailable = false;
                Console.WriteLine("FAILED: " + e.Message);
            }

            if (!isSeleniumServerAvailable)
            {
                SwdBrowser.RunStandaloneServer("start_selenium_server.bat");
            }

            SwdBrowser.Initialize(options);

            var rempteDriver = (RemoteWebDriver)SwdBrowser.GetDriver();

            rempteDriver.Capabilities.BrowserName.Should().Be("htmlunit");

            SwdBrowser.CloseDriver();
        }
        public void StartDriver(WebDriverOptions browserOptions)
        {
            wasBrowserStarted = false;
            bool startFailure = false;

            view.DisableDriverStartButton();
            try
            {
                SwdBrowser.Initialize(browserOptions);
                wasBrowserStarted = true;
            }
            catch
            {
                startFailure = true;
                throw;
            }
            finally
            {
                if (!startFailure)
                {
                    SetDesiredCapabilities(browserOptions);
                    view.DriverWasStarted();
                }
                view.EnableDriverStartButton();
            }
        }
Example #3
0
        public void CloseDriver_should_close_the_opened_browser_instance()
        {
            WebDriverOptions options = new WebDriverOptions()
            {
                BrowserName = WebDriverOptions.browser_Firefox,
            };

            string specialTitle = "SwdBrowser.CloseDriver TEST TEST";

            string[] specialWindows = new string[] { };

            specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle);
            specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> at the beginning", specialTitle);

            SwdBrowser.Initialize(options);

            string changeTitleScript = string.Format("document.title = '{0}'", specialTitle);

            SwdBrowser.ExecuteJavaScript(changeTitleScript);

            specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle);
            specialWindows.Length.Should().Be(1, "Expected only 1 window with title <{0}> after new driver was created", specialTitle);

            SwdBrowser.CloseDriver();

            specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle);
            specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> after the driver was closed", specialTitle);
        }
Example #4
0
        public DriverContainer(WebDriverOptions webDriverOptions)
        {
            _webDriverOptions = webDriverOptions;
            Logger.Information($"Inited Fixture Driver: {_webDriverOptions.DriverType}, host: {_webDriverOptions.SeleniumServer}");

            InitializeDriver();
        }
Example #5
0
        private static IWebDriver ConnetctToRemoteWebDriver(WebDriverOptions browserOptions)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(browserOptions.RemoteUrl);

            switch (browserOptions.BrowserName)
            {
            case WebDriverOptions.browser_Firefox:
                caps = DesiredCapabilities.Firefox();
                break;

            case WebDriverOptions.browser_Chrome:
                caps = DesiredCapabilities.Chrome();
                break;

            case WebDriverOptions.browser_InternetExplorer:
                caps = DesiredCapabilities.InternetExplorer();
                break;

            case WebDriverOptions.browser_PhantomJS:
                caps = DesiredCapabilities.PhantomJS();
                break;

            case WebDriverOptions.browser_HtmlUnit:
                caps = DesiredCapabilities.HtmlUnit();
                break;

            case WebDriverOptions.browser_HtmlUnitWithJavaScript:
                caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case WebDriverOptions.browser_Opera:
                caps = DesiredCapabilities.Opera();
                break;

            case WebDriverOptions.browser_Safari:
                caps = DesiredCapabilities.Safari();
                break;

            case WebDriverOptions.browser_IPhone:
                caps = DesiredCapabilities.IPhone();
                break;

            case WebDriverOptions.browser_IPad:
                caps = DesiredCapabilities.IPad();
                break;

            case WebDriverOptions.browser_Android:
                caps = DesiredCapabilities.Android();
                break;

            default:
                throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                            "WebDriverOptions.BrowserName");
            }
            RemoteWebDriver newDriver = new RemoteWebDriver(hubUri, caps);

            return(newDriver);
        }
Example #6
0
        public static void RunDefaultBrowser()
        {
            WebDriverOptions options = new WebDriverOptions()
            {
                BrowserName = WebDriverOptions.browser_Firefox
                              //BrowserName = WebDriverOptions.browser_PhantomJS,
            };

            SwdBrowser.Initialize(options);
        }
Example #7
0
        private void btnStartWebDriver_Click(object sender, EventArgs e)
        {
            var browserOptions = new WebDriverOptions()
            {
                BrowserName = ddlBrowserToStart.SelectedItem as string,
                IsRemote    = chkUseRemoteHub.Checked,
                RemoteUrl   = txtRemoteHubUrl.Text,
            };

            Presenter.StartNewBrowser(browserOptions);
        }
 public void StartNewBrowser(WebDriverOptions browserOptions)
 {
     if (wasBrowserStarted)
     {
         StopDriver();
     }
     else
     {
         StartDriver(browserOptions);
     }
 }
Example #9
0
        private void StartDriver()
        {
            var browserOptions = new WebDriverOptions()
            {
                BrowserName = WebDriverOptions.browser_Firefox,
                IsRemote    = false,
                RemoteUrl   = "",
            };


            MainForm.browserSettingsTab1.Presenter.StartNewBrowser(browserOptions);
        }
Example #10
0
        public static void RunDefaultBrowser()
        {
            var browserProfile = new Profile();

            browserProfile.ProfileConfig.activation.browserName = "Firefox";

            WebDriverOptions options = new WebDriverOptions()
            {
                BrowserProfile = browserProfile,
            };

            WebSpyBrowser.Initialize(options);
        }
Example #11
0
        public override IWebDriver CreateWebDriver(WebDriverOptions options)
        {
            new DriverManager().SetUpDriver(new EdgeConfig());

            EdgeOptions edgeOptions = new EdgeOptions();

            if (options.RunHeadless)
            {
                // Edge Does Not Support Headless
            }

            return(new EdgeDriver(edgeOptions));
        }
Example #12
0
        private void btnStartWebDriver_Click(object sender, EventArgs e)
        {
            var shouldMaximizeBrowserWindow = chkMaximizeBrowserWindow.Checked;

            var browserOptions = new WebDriverOptions()
            {
                BrowserName = ddlBrowserToStart.SelectedItem as string,
                RemoteUrl   = txtRemoteHubUrl.Text,
            };


            Presenter.StartNewBrowser(browserOptions, shouldMaximizeBrowserWindow);
        }
Example #13
0
 public static IWebDriver Initialize(WebDriverOptions browserOptions, out bool isRemote)
 {
     IWebDriver driver = null;
     if (browserOptions.IsRemote)
     {
         driver = ConnetctToRemoteWebDriver(browserOptions);
         isRemote = true;
     }
     else
     {
         driver = StartEmbededWebDriver(browserOptions);
         isRemote = false;
     }
     return driver;
 }
Example #14
0
        private static IWebDriver ConnetctToRemoteWebDriver(WebDriverOptions browserOptions)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(browserOptions.RemoteUrl);

            switch (browserOptions.BrowserName)
            {

                case WebDriverOptions.browser_Firefox:
                    caps = DesiredCapabilities.Firefox();
                    break;
                case WebDriverOptions.browser_Chrome:
                    caps = DesiredCapabilities.Chrome();
                    break;
                case WebDriverOptions.browser_InternetExplorer:
                    caps = DesiredCapabilities.InternetExplorer();
                    break;
                case WebDriverOptions.browser_PhantomJS:
                    caps = DesiredCapabilities.PhantomJS();
                    break;
                case WebDriverOptions.browser_HtmlUnit:
                    caps = DesiredCapabilities.HtmlUnit();
                    break;
                case WebDriverOptions.browser_HtmlUnitWithJavaScript:
                    caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                    break;
                case WebDriverOptions.browser_Opera:
                    caps = DesiredCapabilities.Opera();
                    break;
                case WebDriverOptions.browser_Safari:
                    caps = DesiredCapabilities.Safari();
                    break;
                case WebDriverOptions.browser_IPhone:
                    caps = DesiredCapabilities.IPhone();
                    break;
                case WebDriverOptions.browser_IPad:
                    caps = DesiredCapabilities.IPad();
                    break;
                case WebDriverOptions.browser_Android:
                    caps = DesiredCapabilities.Android();
                    break;
                default:
                    throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                                "WebDriverOptions.BrowserName");
            }
            RemoteWebDriver newDriver = new RemoteWebDriver(hubUri, caps);
            return newDriver;
        }
Example #15
0
        public static IWebDriver Initialize(WebDriverOptions browserOptions, out bool isRemote)
        {
            IWebDriver driver = null;

            if (browserOptions.IsRemote)
            {
                driver   = ConnetctToRemoteWebDriver(browserOptions);
                isRemote = true;
            }
            else
            {
                driver   = StartEmbededWebDriver(browserOptions);
                isRemote = false;
            }
            return(driver);
        }
Example #16
0
        private void btnStartWebDriver_Click(object sender, EventArgs e)
        {
            var isRemoteDriver = chkUseRemoteHub.Checked;
            var startSeleniumServerIfNotStarted = chkAutomaticallyStartServer.Checked;
            var shouldMaximizeBrowserWindow     = chkMaximizeBrowserWindow.Checked;

            var browserOptions = new WebDriverOptions()
            {
                BrowserName = ddlBrowserToStart.SelectedItem as string,
                IsRemote    = isRemoteDriver,
                RemoteUrl   = txtRemoteHubUrl.Text,
            };


            Presenter.StartNewBrowser(browserOptions, startSeleniumServerIfNotStarted, shouldMaximizeBrowserWindow);
        }
        private void SetDesiredCapabilities(WebDriverOptions browserOptions)
        {
            switch (browserOptions.BrowserProfile.ActivationBrowserName)
            {
            case WebDriverOptions.browser_Chrome:
                _desiredCapabilitiesdata = new ChromeDesiredCapabilitiesData();
                break;

            case WebDriverOptions.browser_InternetExplorer:
                _desiredCapabilitiesdata = new IEDesiredCapabilitiesData();
                break;

            default:
                _desiredCapabilitiesdata = new DesiredCapabilitiesData();
                break;
            }
        }
Example #18
0
        internal void SetBrowserStartupSettings(WebDriverOptions browserOptions)
        {
            Action action = new Action(() =>
            {
                var index = ddlBrowserToStart.Items.IndexOf(browserOptions.BrowserName);

                ddlBrowserToStart.SelectedIndex = index;

                txtRemoteHubUrl.Text = browserOptions.RemoteUrl;
            });

            if (this.InvokeRequired)
            {
                this.Invoke(action);
            }
            else
            {
                action();
            }
        }
        public void StartDriver(WebDriverOptions browserOptions, bool shouldMaximizeBrowserWindow)
        {
            MyLog.Write("StartDriver - Entered");

            wasBrowserStarted = false;

            view.DisableDriverStartButton();

            Exception threadException;

            bool isSuccessful = UIActions.PerformSlowOperation(
                "Operation: Start new WebDriver instance",
                () =>
            {
                SwdBrowser.Initialize(browserOptions);
                wasBrowserStarted = true;

                if (shouldMaximizeBrowserWindow)
                {
                    SwdBrowser.Maximize();
                }
            },
                out threadException,
                null,
                TimeSpan.FromMinutes(10)
                );

            view.EnableDriverStartButton();

            if (isSuccessful)
            {
                SetDesiredCapabilities(browserOptions);
                view.DriverWasStarted();
            }
            else if (threadException != null)
            {
                throw threadException;
            }

            MyLog.Write("StartDriver - Exited");
        }
        public void StartNewBrowser(WebDriverOptions browserOptions, bool startSeleniumServerIfNotStarted, bool shouldMaximizeBrowserWindow)
        {
            if (wasBrowserStarted)
            {
                StopDriver();
            }
            else
            {
                if (startSeleniumServerIfNotStarted &&
                    !SeleniumServerProcess.IsRunning(browserOptions.RemoteUrl))
                {
                    Exception outException;
                    bool      isOk = UIActions.PerformSlowOperation(
                        "Operation: Start local RemoteWebDriver Server",
                        () =>
                    {
                        SeleniumServerProcess.Launch("start_selenium_server.bat");
                        TestRemoteHub(browserOptions.RemoteUrl);
                    },
                        out outException,
                        null,
                        TimeSpan.FromMinutes(2)
                        );

                    if (!isOk)
                    {
                        MyLog.Error("Failed to start local Selenium Server");
                        if (outException != null)
                        {
                            throw outException;
                        }
                    }
                }

                StartDriver(browserOptions, shouldMaximizeBrowserWindow);
            }
        }
Example #21
0
        private static IWebDriver StartEmbededWebDriver(WebDriverOptions browserOptions)
        {
            switch (browserOptions.BrowserName)
            {
            case WebDriverOptions.browser_Firefox:
                return(new FirefoxDriver());

            case WebDriverOptions.browser_Chrome:
                return(new ChromeDriver());

            case WebDriverOptions.browser_InternetExplorer:
                return(new InternetExplorerDriver());

            case WebDriverOptions.browser_PhantomJS:
                return(new PhantomJSDriver());

            case WebDriverOptions.browser_Safari:
                return(new SafariDriver());

            default:
                throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                            "WebDriverOptions.BrowserName");
            }
        }
        public override IWebDriver CreateWebDriver(WebDriverOptions options)
        {
            new DriverManager().SetUpDriver(new FirefoxConfig(), version: "Latest", architecture: Architecture.X64);

            FirefoxOptions firefoxOptions = new FirefoxOptions();

            if (options.RunHeadless)
            {
                firefoxOptions.AddArguments("-headless", "--screenshots");
            }

            IWebDriver webDriver = new FirefoxDriver(firefoxOptions);

            if (options.Desktop)
            {
                webDriver.Manage().Window.Maximize();
            }
            else
            {
                webDriver.Manage().Window.Size = new Size(420, 600);
            }

            return(webDriver);
        }
 public void SetBrowserStartupSettings(WebDriverOptions browserOptions)
 {
     view.SetBrowserStartupSettings(browserOptions);
 }
 protected LoggerFixture()
 {
     WebDriverOptions = ConfigBuilder <WebDriverOptions> .GetConfig("driver");
 }
 public static IWebDriver Initialize(WebDriverOptions browserOptions)
 {
     IWebDriver driver = null;
     driver = ConnetctToRemoteWebDriver(browserOptions);
     return driver;
 }
Example #26
0
        private static IWebDriver StartEmbededWebDriver(WebDriverOptions browserOptions)
        {
            switch (browserOptions.BrowserName)
            {

                case WebDriverOptions.browser_Firefox:
                    return new FirefoxDriver();
                case WebDriverOptions.browser_Chrome:
                    return new ChromeDriver();
                case WebDriverOptions.browser_InternetExplorer:
                    return new InternetExplorerDriver();
                case WebDriverOptions.browser_PhantomJS:
                    return new PhantomJSDriver();
                case WebDriverOptions.browser_Safari:
                    return new SafariDriver();
                default:
                    throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                                "WebDriverOptions.BrowserName");
            }
        }
Example #27
0
        private static IWebDriver ConnetctToRemoteWebDriver(WebDriverOptions browserOptions)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(browserOptions.RemoteUrl);

            switch (browserOptions.BrowserName)
            {
            /*
             * http://stackoverflow.com/questions/17398896/how-to-use-different-version-of-firefox-using-webdriver
             * https://code.google.com/p/selenium/wiki/FirefoxDriver
             * https://code.google.com/p/selenium/wiki/InternetExplorerDriver
             * https://code.google.com/p/selenium/wiki/ChromeDriver#Overriding_the_Chrome_binary_location
             *
             */

            case WebDriverOptions.browser_Firefox:
                path_to_binary      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                binary_path_propery = "webdriver.firefox.bin";
                caps = DesiredCapabilities.Firefox();
                break;

            case WebDriverOptions.browser_Chrome:
                path_to_driver      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                driver_path_propery = "webdriver.chrome.driver";
                caps = DesiredCapabilities.Chrome();
                break;

            case WebDriverOptions.browser_InternetExplorer:
                caps                = DesiredCapabilities.InternetExplorer();
                path_to_driver      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                driver_path_propery = "webdriver.ie.driver";
                break;

            case WebDriverOptions.browser_PhantomJS:
                caps = DesiredCapabilities.PhantomJS();
                break;

            case WebDriverOptions.browser_HtmlUnit:
                caps = DesiredCapabilities.HtmlUnit();
                break;

            case WebDriverOptions.browser_HtmlUnitWithJavaScript:
                caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case WebDriverOptions.browser_Opera:
                caps = DesiredCapabilities.Opera();
                break;

            case WebDriverOptions.browser_Safari:
                caps = DesiredCapabilities.Safari();
                break;

            case WebDriverOptions.browser_IPhone:
                caps = DesiredCapabilities.IPhone();
                break;

            case WebDriverOptions.browser_IPad:
                caps = DesiredCapabilities.IPad();
                break;

            case WebDriverOptions.browser_Android:
                caps = DesiredCapabilities.Android();
                break;

            default:
                throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                            "WebDriverOptions.BrowserName");
            }
            RemoteWebDriver newDriver = new RemoteWebDriver(hubUri, caps);

            return(newDriver);
        }