//Creates an instance of a webdriver internal static IWebDriver CreateDriver(BrowserConfig config) { //create local or remote IWebDriver result = null; switch (config.Browserlocation) { case BrowserLocations.Local: result = CreateLocalDriver(config); break; case BrowserLocations.Remote: result = CreateRemoteDriver(config); break; default: throw new Exception("Unsupported browser location"); } //set common settings //timeouts result.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 0, config.Pageloadtimeout)); result.Manage().Timeouts().SetScriptTimeout(new TimeSpan(0, 0, config.Pageloadtimeout)); result.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500)); return(result); }
//Constructor internal BrowserApp(BrowserConfig config) { this.Status = BrowserStatuses.Closed; this.Config = config; this.CommandTimeout = config.Commandtimeout; this.OpenBrowser(); this.Identifier = BrowserManager.Instance.AddBrowserInstance(this); Trace.WriteLine(string.Format("Browser opened with ID, {0}", this.Identifier)); }
//Creates a local webdriver private static IWebDriver CreateLocalDriver(BrowserConfig config) { switch (config.Browsername) { case BrowserNames.Firefox: return(new FirefoxDriver()); case BrowserNames.Chrome: return(new ChromeDriver()); case BrowserNames.IE11: return(new InternetExplorerDriver(GetLocalIeOptions())); case BrowserNames.Edge: return(new EdgeDriver()); default: throw new Exception("Unsupported browser type"); } }
//Creates a remote webdriver private static IWebDriver CreateRemoteDriver(BrowserConfig config) { Uri huburl = new Uri(config.Huburl); switch (config.Browsername) { case BrowserNames.Firefox: return(new RemoteWebDriver(huburl, DesiredCapabilities.Firefox())); case BrowserNames.Chrome: return(new RemoteWebDriver(huburl, DesiredCapabilities.Chrome())); case BrowserNames.IE11: return(new RemoteWebDriver(huburl, GetRemoteIe11Capabilities())); case BrowserNames.Edge: return(new RemoteWebDriver(huburl, DesiredCapabilities.Edge())); default: throw new Exception("Unsupported browser type"); } }