public static IWebDriver GetDriver(TestContext context) { IWebDriver webdriver; var preferedbrowser = TestSettings.Default.Browser; if (TestSettings.Default.Location.ToLower() == "local") { //run locally switch (preferedbrowser.ToLower()) { case "chrome": { var options = GetChromeOptions(context); webdriver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(5)); break; } default: { FirefoxOptions options = new FirefoxOptions(); options.AddArgument("-private"); webdriver = new FirefoxDriver(options); break; } } } else { //run in browserStack webdriver = RemoteBrowserHelper.GetDriver(preferedbrowser, context); } return(webdriver); }
public static IWebDriver GetDriver(string preferedbrowser, TestContext context) { string browserVersion = TestSettings.Default.BrowserVersion; var caps = new DesiredCapabilities(); var remoteCapabilities = new RemoteBrowserHelper(); switch (preferedbrowser) { case "Chrome": { var options = remoteCapabilities.GetChromeOptions(); var capabilities = (DesiredCapabilities)options.ToCapabilities(); caps = remoteCapabilities.SetCapabilities(capabilities, preferedbrowser, browserVersion, context); break; } case "Safari": { var capabilities = new DesiredCapabilities(); capabilities.SetCapability("browserstack.safari.enablePopups", "true"); caps = remoteCapabilities.SetCapabilities(capabilities, preferedbrowser, browserVersion, context); break; } case "IE": { var capabilities = new DesiredCapabilities(); capabilities.SetCapability("browserstack.ie.enablePopups", "true"); capabilities.SetCapability("browserstack.ie.noFlash", "true"); caps = remoteCapabilities.SetCapabilities(capabilities, preferedbrowser, browserVersion, context); break; } case "Firefox": { var capabilities = new DesiredCapabilities(); caps = remoteCapabilities.SetCapabilities(capabilities, preferedbrowser, browserVersion, context); break; } default: { var options = remoteCapabilities.GetChromeOptions(); var capabilities = (DesiredCapabilities)options.ToCapabilities(); caps = remoteCapabilities.SetCapabilities(capabilities, preferedbrowser, browserVersion, context); break; } } var url = new Uri("https://hub-cloud.browserstack.com/wd/hub/"); return(new RemoteWebDriver(url, caps)); }