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(SeleniumDriver))); return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout))); case Browser.InternetExplorer64: driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer64.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumDriver))); 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(SeleniumDriver))); 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(SeleniumDriver))); 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."); }
public TournamentScraper(string firefoxPath, string firefoxProfilePath) { binary = new OpenQA.Selenium.Firefox.FirefoxBinary(firefoxPath); profile = new OpenQA.Selenium.Firefox.FirefoxProfile(firefoxProfilePath); driver = new OpenQA.Selenium.Firefox.FirefoxDriver(this.binary, this.profile); }
public TournamentScraper() { binary = new OpenQA.Selenium.Firefox.FirefoxBinary(); profile = new OpenQA.Selenium.Firefox.FirefoxProfile(); driver = new OpenQA.Selenium.Firefox.FirefoxDriver(this.binary, this.profile); }
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."); }