/// <summary> /// Initialize a new headless Chrome driver /// </summary> /// <param name="commandTimeout">Browser command timeout</param> /// <param name="headlessChromeOptions">Browser options</param> /// <returns>A new headless Chrome driver</returns> public static IWebDriver GetHeadlessChromeDriver(TimeSpan commandTimeout, ChromeOptions headlessChromeOptions) { return(CreateDriver(() => { LazyInitializer.EnsureInitialized(ref ChromeDriverPath, () => new DriverManager().SetUpDriver(new ChromeConfig(), SeleniumConfig.GetChromeVersion())); return new ChromeDriver(ChromeDriverService.CreateDefaultService(), headlessChromeOptions, commandTimeout); }, SeleniumConfig.GetRetryRefused())); }
/// <summary> /// Initialize a new Edge driver /// </summary> /// <param name="commandTimeout">Browser command timeout</param> /// <param name="edgeOptions">Browser options</param> /// <param name="size">Browser size in the following format: MAXIMIZE, DEFAULT, or #x# (such as 1920x1080)</param> /// <returns>A new Edge driver</returns> public static IWebDriver GetEdgeDriver(TimeSpan commandTimeout, EdgeOptions edgeOptions, string size = "MAXIMIZE") { return(CreateDriver(() => { LazyInitializer.EnsureInitialized(ref EdgeDriverPath, () => new DriverManager().SetUpDriver(new EdgeConfig(), SeleniumConfig.GetEdgeVersion())); var driver = new EdgeDriver(Path.GetDirectoryName(EdgeDriverPath), edgeOptions, commandTimeout); SetBrowserSize(driver, size); return driver; }, SeleniumConfig.GetRetryRefused())); }
/// <summary> /// Initialize a new Chrome driver /// </summary> /// <param name="commandTimeout">Browser command timeout</param> /// <param name="chromeOptions">Browser options</param> /// <param name="size">Browser size in the following format: MAXIMIZE, DEFAULT, or #x# (such as 1920x1080)</param> /// <returns>A new Chrome driver</returns> public static IWebDriver GetChromeDriver(TimeSpan commandTimeout, ChromeOptions chromeOptions, string size = "MAXIMIZE") { return(CreateDriver(() => { LazyInitializer.EnsureInitialized(ref ChromeDriverPath, () => new DriverManager().SetUpDriver(new ChromeConfig(), SeleniumConfig.GetChromeVersion())); var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), chromeOptions, commandTimeout); SetBrowserSize(driver, size); return driver; }, SeleniumConfig.GetRetryRefused())); }
/// <summary> /// Initialize a new Firefox driver /// </summary> /// <param name="commandTimeout">Browser command timeout</param> /// <param name="firefoxOptions">Browser options</param> /// <param name="size">Browser size in the following format: MAXIMIZE, DEFAULT, or #x# (such as 1920x1080)</param> /// <returns>A new Firefox driver</returns> public static IWebDriver GetFirefoxDriver(TimeSpan commandTimeout, FirefoxOptions firefoxOptions, string size = "MAXIMIZE") { return(CreateDriver(() => { LazyInitializer.EnsureInitialized(ref FirefoxDriverPath, () => new DriverManager().SetUpDriver(new FirefoxConfig(), SeleniumConfig.GetFirefoxVersion())); // Add support for encoding 437 that was removed in .net core Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var driver = new FirefoxDriver(Path.GetDirectoryName(FirefoxDriverPath), firefoxOptions, commandTimeout); SetBrowserSize(driver, size); return driver; }, SeleniumConfig.GetRetryRefused())); }