예제 #1
0
        public void CanOverrideWebDriver()
        {
            IWebDriver tempDriver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome);
            this.WebDriver = tempDriver;

            Assert.AreEqual(this.TestObject.WebDriver.GetLowLevelDriver(), tempDriver.GetLowLevelDriver());
        }
예제 #2
0
        public void CanUseMultiple()
        {
            SeleniumDriverManager newDriver = new SeleniumDriverManager(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome), this.TestObject);
            this.ManagerStore.Add("test", newDriver);

            Assert.AreNotEqual(this.TestObject.WebDriver.GetLowLevelDriver(), ((SeleniumDriverManager)this.ManagerStore["test"]).GetWebDriver().GetLowLevelDriver());
        }
예제 #3
0
        public void RemoteCapabilitySectionRespected()
        {
            var        checkedAssertion = false;
            IWebDriver driver           = null;
            var        username         = Config.GetValueForSection(ConfigSection.RemoteSeleniumCapsMaqs, "username");

            try
            {
                Config.AddTestSettingValues(new Dictionary <string, string> {
                    ["username"] = "******"
                }, ConfigSection.RemoteSeleniumCapsMaqs, true);
                driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Remote);
                driver.Navigate().GoToUrl("https://magenic.com/");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.InnerException.Message.Contains("Sauce_Labs_Username"), "Did not see 'Sauce_Labs_Username' in error message: " + e.Message + " -- " + e.InnerException.Message);
                checkedAssertion = true;
            }
            finally
            {
                // Cleanup if we need to
                if (driver != null)
                {
                    driver.Quit();
                }
                Config.AddTestSettingValues(new Dictionary <string, string> {
                    ["username"] = username
                }, ConfigSection.RemoteSeleniumCapsMaqs, true);
            }
            Assert.IsTrue(checkedAssertion, "Did not receive the error message on inner exception");
        }
예제 #4
0
        public void GetBrowserRemoteThrowException()
        {
            string hubUrl        = Config.GetGeneralValue("HubUrl");
            string remoteBrowser = Config.GetGeneralValue("RemoteBrowser");

            try
            {
                Config.AddTestSettingValues(
                    new Dictionary <string, string>
                {
                    { "HubUrl", "http://localhost:4444/wd/hub" },
                    { "RemoteBrowser", "NoBrowser" }
                },
                    "SeleniumMaqs",
                    true);

                WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Remote);
            }
            finally
            {
                Config.AddTestSettingValues(
                    new Dictionary <string, string>
                {
                    { "HubUrl", hubUrl },
                    { "RemoteBrowser", remoteBrowser }
                },
                    "SeleniumMaqs",
                    true);
            }
        }
예제 #5
0
        /// <summary>
        /// Override the web driver we user for these tests
        /// </summary>
        /// <returns>The web driver we want to use - Web driver override</returns>
        protected override IWebDriver GetBrowser()
        {
            IWebDriver driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Firefox);

            driver.Manage().Window.Size = new Size(701, 199);

            return(driver);
        }
예제 #6
0
        public void CanOverrideWithFunc()
        {
            int oldHash = this.WebDriver.GetLowLevelDriver().GetHashCode();

            this.TestObject.OverrideWebDriver(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome));

            Assert.AreNotEqual(oldHash, this.WebDriver.GetLowLevelDriver().GetHashCode());
        }
예제 #7
0
        public void SeparateInteractions()
        {
            SeleniumDriverManager newDriver = new SeleniumDriverManager(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome), this.TestObject);
            newDriver.GetWebDriver().Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/");

            this.ManagerStore.Add("test", newDriver);

            this.TestObject.WebDriver.Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/Automation");

            Assert.AreNotEqual(this.TestObject.WebDriver.Url, ((SeleniumDriverManager)this.ManagerStore["test"]).GetWebDriver().Url);
        }
예제 #8
0
        public void SeparateInteractions()
        {
            SeleniumDriverManager newDriver = new SeleniumDriverManager(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome), this.TestObject);

            newDriver.GetWebDriver().Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase());

            this.ManagerStore.Add("test", newDriver);

            this.TestObject.WebDriver.Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase() + "/Automation");

            Assert.AreNotEqual(this.TestObject.WebDriver.Url, this.ManagerStore.GetManager <SeleniumDriverManager>("test").GetWebDriver().Url);
        }
예제 #9
0
        public void GetBrowserWithString()
        {
            IWebDriver driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome);

            try
            {
                Assert.IsNotNull(driver);
            }
            finally
            {
                driver?.KillDriver();
            }
        }
예제 #10
0
        public void SeparateLazyElementInteractions()
        {
            SeleniumDriverManager newDriver = new SeleniumDriverManager(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome), this.TestObject);

            newDriver.GetWebDriver().Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/");
            this.ManagerStore.Add("test", newDriver);

            this.TestObject.WebDriver.Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/Automation");

            LazyElement topNew     = new LazyElement(this.TestObject, newDriver.GetWebDriver(), By.CssSelector("*"));
            LazyElement topDefault = new LazyElement(this.TestObject, By.CssSelector("*"));

            Assert.AreNotEqual(topNew.Text, topDefault.Text);
        }
예제 #11
0
        /// <summary>
        /// Test that we can create a web driver with the default configuration
        /// </summary>
        /// <param name="browserType">Type of browser</param>
        /// <param name="navigate">Should we make sure we can navigate</param>
        private void OpenBrowserWithDefaultTest(BrowserType browserType, bool navigate = true)
        {
            IWebDriver driver = null;

            try
            {
                driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(browserType);
                if (navigate)
                {
                    driver.Navigate().GoToUrl(Config.GetValueForSection(ConfigSection.SeleniumMaqs, "WebSiteBase"));
                }
            }
            finally
            {
                driver?.KillDriver();
            }
        }
예제 #12
0
        public void ResizeBrowserWindowMaximize()
        {
            /*
             * Create driver at whatever size
             * Manually maximize the window
             * Override the Config BrowserSize value to MAXIMIZE
             * Verify new and old driver size values are the same
             */

            // Using FireFox because headless Chrome does not respect Maximize as of 8/24/2018
            IWebDriver driverManualSize = null;

            try
            {
                driverManualSize = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Chrome);
                driverManualSize.Manage().Window.Maximize();

                var manuallyMaximizedWidth = driverManualSize.Manage().Window.Size.Width;
                var manuallyMaximizedHidth = driverManualSize.Manage().Window.Size.Height;

                Config.AddTestSettingValues(
                    new Dictionary <string, string>
                {
                    { "BrowserSize", "MAXIMIZE" }
                },
                    "SeleniumMaqs");

                IWebDriver driverConfigSize = null;

                try
                {
                    driverConfigSize = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Firefox);
                    Assert.AreEqual(manuallyMaximizedWidth, driverConfigSize.Manage().Window.Size.Width);
                    Assert.AreEqual(manuallyMaximizedHidth, driverConfigSize.Manage().Window.Size.Height);
                }
                finally
                {
                    driverConfigSize?.KillDriver();
                }
            }
            finally
            {
                driverManualSize?.KillDriver();
            }
        }
예제 #13
0
        public void RemoteCapabilitySectionRespected()
        {
            IWebDriver driver = null;

            try
            {
                driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Remote);
                driver.Navigate().GoToUrl("https://magenic.com/");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.InnerException.Message.Contains("Sauce_Labs_Username"), "Did not see 'Sauce_Labs_Username' in error message: " + e.Message + " -- " + e.InnerException.Message);
            }
            finally
            {
                // Cleanup if we need to
                if (driver != null)
                {
                    driver.Quit();
                }
            }
        }
예제 #14
0
        public void OpenEdgeBrowser()
        {
            IWebDriver driver = null;

            try
            {
                driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.Edge);
                driver.Navigate().GoToUrl(Config.GetValueForSection(ConfigSection.SeleniumMaqs, "WebSiteBase"));
            }
            catch
            {
                // May need to run headless on some systems
                var headlessEdgeOptions = WebDriverFactory.GetDefaultEdgeOptions();
                headlessEdgeOptions.AddArgument("--no-sandbox");
                headlessEdgeOptions.AddArguments("--headless");

                driver = WebDriverFactory.GetEdgeDriver(SeleniumConfig.GetCommandTimeout(), headlessEdgeOptions);
                driver.Navigate().GoToUrl(Config.GetValueForSection(ConfigSection.SeleniumMaqs, "WebSiteBase"));
            }
            finally
            {
                driver?.KillDriver();
            }
        }