/// <summary> /// Gets the web driver. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public IWebDriver GetWebDriver(SeleniumWebDriverType type) { if (!_webDrivers.TryGetValue(type, out var webDriver)) { webDriver = CreateWebDriver(type); _webDrivers.Add(type, webDriver); } return(webDriver); }
private static IWebDriver CreateWebDriver(SeleniumWebDriverType type) { IWebDriver webDriver; switch (type) { case SeleniumWebDriverType.Edge: var edgeOptions = new EdgeOptions(); edgeOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true); var edgeDriverService = EdgeDriverService.CreateDefaultService(AppContext.BaseDirectory); webDriver = new ThreadLocal <IWebDriver>(() => new EdgeDriver(edgeDriverService, edgeOptions)).Value; break; case SeleniumWebDriverType.Firefox: var firefoxProfile = new FirefoxProfile { AcceptUntrustedCertificates = true }; var firefoxOptions = new FirefoxOptions { Profile = firefoxProfile }; var firefoxDriverService = FirefoxDriverService.CreateDefaultService(AppContext.BaseDirectory); webDriver = new ThreadLocal <IWebDriver>(() => new FirefoxDriver(firefoxDriverService, firefoxOptions, TimeSpan.FromSeconds(60))).Value; break; case SeleniumWebDriverType.GoogleChrome: var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--ignore-certificate-errors"); var chromeDriverService = ChromeDriverService.CreateDefaultService(AppContext.BaseDirectory); webDriver = new ThreadLocal <IWebDriver>(() => new ChromeDriver(chromeDriverService, chromeOptions)).Value; break; case SeleniumWebDriverType.InternetExplorer: var internetExplorerOptions = new InternetExplorerOptions(); internetExplorerOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true); var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService(AppContext.BaseDirectory); webDriver = new ThreadLocal <IWebDriver>(() => new InternetExplorerDriver(internetExplorerDriverService, internetExplorerOptions)).Value; break; default: throw new NullReferenceException("WebDriver is null."); } webDriver.Manage().Window.Maximize(); return(webDriver); }
public void Should_find_search_box(SeleniumWebDriverType type) { // Arrange var driver = _fixture.GetWebDriver(type); // Act driver.Navigate().GoToUrl(_fixture.GetUrl()); // Assert var p = driver.FindElement(By.TagName("p")); Assert.Equal("p", p.TagName); }