/// <summary> /// Opens new browser window by browser type and sets web driver object up /// </summary> /// <param name="driver">Driver object. Will be setup at the end of the method.</param> /// <param name="browserType">Browser type (see <see cref="BrowserType"/>)</param> internal static void OpenBrowser(ref IWebDriver driver, BrowserType browserType) { if (driver != null) { CurrentDriver = driver; ActionManager.CloseAlert(); return; } switch (browserType) { case BrowserType.Chrome: case BrowserType.ChromeIncognito: var chromeOptions = new ChromeOptions(); chromeOptions.AddArguments("disable-infobars", "disable-geolocation", "disable-gpu", "no-sandbox"); chromeOptions.AddUserProfilePreference("download.default_directory", TestConfig.BrowserDownloadFolder); if (browserType == BrowserType.ChromeIncognito) { chromeOptions.AddArgument("incognito"); } driver = new ChromeDriver(chromeOptions); break; case BrowserType.Firefox: var ffOptions = new FirefoxOptions(); ffOptions.SetPreference("app.update.auto", false); ffOptions.SetPreference("app.update.enabled", false); ffOptions.SetPreference("app.update.silent", false); ffOptions.SetPreference("geo.enabled", false); ffOptions.SetPreference("geo.provider.use_corelocation", false); ffOptions.SetPreference("geo.prompt.testing", false); ffOptions.SetPreference("geo.prompt.testing.allow", false); ffOptions.SetPreference("browser.download.folderList", 2); ffOptions.SetPreference("browser.download.dir", TestConfig.BrowserDownloadFolder); ffOptions.SetPreference("browser.download.manager.showWhenStarting", false); ffOptions.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg"); ffOptions.SetPreference("layers.acceleration.disabled", true); driver = new FirefoxDriver(ffOptions); break; // Cannot be used due to browser GUI "open file" dialog calls from CX Manager. // AutoItX cannot control invisible dialogs. // //case BrowserType.ChromeHeadless: // chromeOptions.AddArguments("headless", "disable-gpu", "disable-infobars", "window-size=1920x1080"); // driver = new ChromeDriver(chromeOptions); // break; case BrowserType.InternetExplorer: driver = new InternetExplorerDriver(); break; case BrowserType.Edge: driver = new EdgeDriver(); break; case BrowserType.Safari: driver = new SafariDriver(); break; case BrowserType.Opera: driver = new OperaDriver(); break; default: throw new WebDriverException("Unsupported browser type is set in TestConfig.xlsx"); } driver.SwitchTo().DefaultContent(); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(TestConfig.ImplicitWaitTimeout); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(TestConfig.PageLoadWaitTimeout); CurrentDriver = driver; WindowHandles.Add(AutoIt.AutoItX.WinGetHandle()); }