public IWebBrowser Create(BrowserType browserType, BrowserStartOptions startOptions, IEnumerable <IBusyCondition> busyConditions) { IWebDriver webDriver = null; string driversPath = Path.Combine(Environment.CurrentDirectory, "Drivers"); switch (browserType) { case BrowserType.Chrome: webDriver = ChromeDriverFactory.Create(driversPath, startOptions); break; case BrowserType.InternetExplorer: webDriver = InternetExplorerDriverFactory.Create(driversPath, startOptions); break; default: throw new NotSupportedException(); } SeleniumWebBrowser browser = new SeleniumWebBrowser( webDriver: webDriver, browserType: browserType, busyConditions: busyConditions ?? new List <IBusyCondition>()); return(browser); }
/// <summary> /// Creates a web driver. /// </summary> /// <param name="driversPath">Path to the folder containg the web driver.</param> /// <param name="startOptions">Null allowed. Providing null falls back to default BrowserStartOptions.</param> /// <returns>An instance of Internet Explorer Driver.</returns> public static IWebDriver Create(string driversPath, BrowserStartOptions startOptions) { var options = CreateOptions(startOptions); var driver = new InternetExplorerDriver(driversPath, options); if (startOptions.StartMaximized) { driver.Manage().Window.Maximize(); } return(driver); }
/// <summary> /// Creates a web driver. /// </summary> /// <param name="driverPath">Path to the folder containg the web driver.</param> /// <param name="startOptions">Null allowed. Providing null falls back to default BrowserStartOptions.</param> /// <returns>An instance of Chrome Driver.</returns> public static IWebDriver Create(string driverPath, BrowserStartOptions startOptions) { ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath); service.Port = 5555; // Some port value. service.Start(); var chromeOptions = CreateOptions(startOptions); IWebDriver webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:5555"), chromeOptions); return(webDriver); }
private static InternetExplorerOptions CreateOptions(BrowserStartOptions startOptions) { // Initialize default. startOptions = startOptions ?? new BrowserStartOptions(); var options = new InternetExplorerOptions(); if (startOptions.RunHeadless) { // Internet explorer does not support Headless. throw new InvalidConfigurationException($"InternetExplorerDriver does not support {nameof(BrowserStartOptions.RunHeadless)} options."); } return(options); }
private static ChromeOptions CreateOptions(BrowserStartOptions startOptions) { // Initialize default. startOptions = startOptions ?? new BrowserStartOptions(); var chromeOptions = new ChromeOptions(); if (startOptions.RunHeadless) { chromeOptions.AddArguments("--headless"); } if (startOptions.StartMaximized) { chromeOptions.AddArgument("--start-maximized"); } return(chromeOptions); }
public IWebBrowser Create(BrowserType browserType, BrowserStartOptions startOptions) { return(this.Create(browserType, startOptions, null)); }