/// <summary> /// Construct a driver appropriate for the current configuration. /// </summary> /// <returns> /// The relevantly configured IWebDriver implementation. /// </returns> public static IWebDriver Get() { IWebDriver driver; CurrentBrowserType = (BrowserType)Enum.Parse(typeof(BrowserType), Configuration.Configuration.BrowserName, true); var browserVersion = Configuration.Configuration.BrowserVersion; WebDriverEventLog.Add(String.Format("Specifying browser type: '{0}'", CurrentBrowserType)); WebDriverEventLog.Add(String.Format("Specifying browser version: '{0}'", browserVersion)); switch (GetTestExecutionEnvironment()) { case TestExecutionEnvironment.Local: driver = GetDriverForLocalEnvironment(CurrentBrowserType); break; case TestExecutionEnvironment.SauceLabs: driver = GetDriverForSauceLabs(CurrentBrowserType, browserVersion); break; case TestExecutionEnvironment.Grid: driver = GetDriverForGrid(CurrentBrowserType); break; default: throw new ArgumentException("Test execution environment not recognised."); } if (Configuration.Configuration.EnableLogging) { driver = AttachEventFiringWebDriver(driver); } if (GetTestExecutionEnvironment() != TestExecutionEnvironment.SauceLabs && BrowserSupportsResizing(CurrentBrowserType)) { driver.Manage().Window.Maximize(); } // If we're on Sauce, there's no need to delete cookies (and it causes iOS failures) if (GetTestExecutionEnvironment() != TestExecutionEnvironment.SauceLabs) { try { driver.Manage().Cookies.DeleteAllCookies(); } catch (Exception) { WebDriverEventLog.Add( "Could not delete all cookies! Are you testing on iOS? If you see this message please contact TAS."); } } driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); return(driver); }
private static IWebDriver GetDriverForGrid(BrowserType browserType) { DesiredCapabilities capabilities; switch (browserType) { case BrowserType.Firefox: capabilities = DesiredCapabilities.Firefox(); break; case BrowserType.IE: capabilities = DesiredCapabilities.InternetExplorer(); capabilities.SetCapability("ie.ensureCleanSession", "true"); break; case BrowserType.Chrome: capabilities = DesiredCapabilities.Chrome(); break; case BrowserType.Safari: capabilities = DesiredCapabilities.Safari(); break; default: throw new ArgumentException("Unrecognised browser choice '" + browserType + "' when initialising driver for Grid."); } var platform = browserType.Equals(BrowserType.Safari) ? PlatformType.Mac : PlatformType.Vista; capabilities.SetCapability(CapabilityType.Platform, new Platform(platform)); // So we know who's using it capabilities.SetCapability("environment", String.Format("{0} ({1})", Configuration.Configuration.GridIdentifier, Environment.MachineName)); IWebDriver driver; try { driver = new SeleniumGridDriver( new Uri(Configuration.Configuration.GridHubUrl), capabilities, TimeSpan.FromSeconds(900)); } catch (Exception) { WebDriverEventLog.Add(String.Format("Failed when attempting to initialise a {0} browser on the Selenium Grid.{1}", capabilities.BrowserName, Environment.NewLine)); throw; } WebDriverEventLog.Add(String.Format("Grid Node: '{0}'{1}", ((SeleniumGridDriver)driver).RemoteHost, Environment.NewLine)); return(driver); }
protected internal static void webdriver_ElementValueChangingHandler(object sender, WebElementEventArgs e) { WebDriverEventLog.Add("Changing element "); }
protected internal static void webdriver_NavigatingHandler(object sender, WebDriverNavigationEventArgs e) { WebDriverEventLog.Add("Navigating to: " + e.Url); }
protected internal static void webdriver_FindingElementHandler(object sender, FindElementEventArgs e) { WebDriverEventLog.Add("Finding element: " + e.FindMethod); }