private static Func <IWebDriver> GenerateBrowserSpecificDriver(Browser browser) { string driverPath = string.Empty; switch (browser) { case Browser.InternetExplorer: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer32.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath)))); case Browser.InternetExplorer64: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer64.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath)))); case Browser.Firefox: return(new Func <IWebDriver>(() => new OpenQA.Selenium.Firefox.FirefoxDriver())); case Browser.Chrome: driverPath = EmbeddedResources.UnpackFromAssembly("chromedriver.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new OpenQA.Selenium.Chrome.ChromeDriver(Path.GetDirectoryName(driverPath)))); case Browser.PhantomJs: driverPath = EmbeddedResources.UnpackFromAssembly("phantomjs.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new OpenQA.Selenium.PhantomJS.PhantomJSDriver(Path.GetDirectoryName(driverPath)))); } throw new NotImplementedException("Selected browser " + browser.ToString() + " is not supported yet."); }
/// <summary> /// Bootstrap Selenium provider and utilize the specified <paramref name="browser"/>. /// </summary> /// <param name="browser"></param> public static void Bootstrap(Browser browser) { SeleniumWebDriver.SelectedBrowser = browser; FluentAutomation.Settings.Registration = (container) => { container.Register <ICommandProvider, CommandProvider>(); container.Register <IExpectProvider, ExpectProvider>(); container.Register <IFileStoreProvider, LocalFileStoreProvider>(); switch (SeleniumWebDriver.SelectedBrowser) { case Browser.InternetExplorer: EmbeddedResources.UnpackFromAssembly("IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); container.Register <IWebDriver, Wrappers.IEDriverWrapper>().AsMultiInstance(); break; case Browser.Firefox: container.Register <IWebDriver, OpenQA.Selenium.Firefox.FirefoxDriver>().AsMultiInstance(); break; case Browser.Chrome: EmbeddedResources.UnpackFromAssembly("chromedriver.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); container.Register <IWebDriver, OpenQA.Selenium.Chrome.ChromeDriver>().AsMultiInstance(); break; } }; }
private static string UnpackResources() { var containerAssembly = Assembly.GetAssembly(typeof(PhantomJS)); EmbeddedResources.UnpackFromAssembly("phantomjs.exe", containerAssembly); EmbeddedResources.UnpackFromAssembly("PhantomDriver.coffee", containerAssembly); return(containerAssembly.CodeBase); }
private static Func <IWebDriver> GenerateBrowserSpecificDriver(Browser browser, TimeSpan commandTimeout) { string driverPath = string.Empty; switch (browser) { case Browser.InternetExplorer: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer32.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout))); case Browser.InternetExplorer64: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer64.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout))); case Browser.Firefox: return(new Func <IWebDriver>(() => { var firefoxBinary = new OpenQA.Selenium.Firefox.FirefoxBinary(); return new OpenQA.Selenium.Firefox.FirefoxDriver(firefoxBinary, new OpenQA.Selenium.Firefox.FirefoxProfile { EnableNativeEvents = false, AcceptUntrustedCertificates = true, AlwaysLoadNoFocusLibrary = true }, commandTimeout); })); case Browser.Chrome: driverPath = EmbeddedResources.UnpackFromAssembly("chromedriver.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); var chromeService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath)); chromeService.SuppressInitialDiagnosticInformation = true; var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--log-level=3"); return(new Func <IWebDriver>(() => new OpenQA.Selenium.Chrome.ChromeDriver(chromeService, chromeOptions, commandTimeout))); case Browser.PhantomJs: driverPath = EmbeddedResources.UnpackFromAssembly("phantomjs.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); var phantomOptions = new OpenQA.Selenium.PhantomJS.PhantomJSOptions(); return(new Func <IWebDriver>(() => new OpenQA.Selenium.PhantomJS.PhantomJSDriver(Path.GetDirectoryName(driverPath), phantomOptions, commandTimeout))); } throw new NotImplementedException("Selected browser " + browser.ToString() + " is not supported yet."); }
private static Func <IWebDriver> GenerateBrowserSpecificDriver(Browser browser, TimeSpan commandTimeout) { string driverPath = string.Empty; switch (browser) { case Browser.InternetExplorer: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer32.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout))); case Browser.InternetExplorer64: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer64.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout))); case Browser.Firefox: return(new Func <IWebDriver>(() => { var firefoxBinary = new OpenQA.Selenium.Firefox.FirefoxBinary(); return new OpenQA.Selenium.Firefox.FirefoxDriver(firefoxBinary, new OpenQA.Selenium.Firefox.FirefoxProfile { EnableNativeEvents = false, AcceptUntrustedCertificates = true, AlwaysLoadNoFocusLibrary = true }, commandTimeout); })); case Browser.Chrome: //Providing an unique name for the chromedriver makes it possible to run multiple instances var uniqueName = string.Format("chromedriver_{0}.exe", Guid.NewGuid()); driverPath = EmbeddedResources.UnpackFromAssembly("chromedriver.exe", uniqueName, Assembly.GetAssembly(typeof(SeleniumWebDriver))); var chromeService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), uniqueName); chromeService.SuppressInitialDiagnosticInformation = true; var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--log-level=3"); return(new Func <IWebDriver>(() => new OpenQA.Selenium.Chrome.ChromeDriver(chromeService, chromeOptions, commandTimeout))); case Browser.PhantomJs: var uniqueNamePhantom = string.Format("phantomjs_{0}.exe", Guid.NewGuid()); driverPath = EmbeddedResources.UnpackFromAssembly("phantomjs.exe", uniqueNamePhantom, Assembly.GetAssembly(typeof(SeleniumWebDriver))); var phantomService = PhantomJSDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), uniqueNamePhantom); IWbTstr config = WbTstr.Configure(); string proxyHost = config.GetPhantomProxyHost(); if (!string.IsNullOrWhiteSpace(proxyHost)) { phantomService.Proxy = proxyHost; phantomService.ProxyType = "http"; string proxyAuthentication = config.GetPhantomProxyAuthentication(); if (!string.IsNullOrWhiteSpace(proxyAuthentication)) { phantomService.ProxyAuthentication = proxyAuthentication; } } return(new Func <IWebDriver>(() => new PhantomJSDriver(phantomService, new PhantomJSOptions(), commandTimeout))); } throw new NotImplementedException("Selected browser " + browser.ToString() + " is not supported yet."); }