public void CanOverrideWebDriver() { IWebDriver tempDriver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome); this.WebDriver = tempDriver; Assert.AreEqual(this.TestObject.WebDriver.GetLowLevelDriver(), tempDriver.GetLowLevelDriver()); }
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()); }
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"); }
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); } }
/// <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); }
public void CanOverrideWithFunc() { int oldHash = this.WebDriver.GetLowLevelDriver().GetHashCode(); this.TestObject.OverrideWebDriver(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome)); Assert.AreNotEqual(oldHash, this.WebDriver.GetLowLevelDriver().GetHashCode()); }
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); }
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); }
public void GetBrowserWithString() { IWebDriver driver = WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome); try { Assert.IsNotNull(driver); } finally { driver?.KillDriver(); } }
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); }
/// <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(); } }
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(); } }
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(); } } }
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(); } }