private static IWebDriver CreateEdgeDriver() { try { string browserLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; // Please adjust the path if needed EdgeOptions options = new EdgeOptions(); options.UseChromium = true; //options.AddArgument("headless"); options.BinaryLocation = browserLocation; EdgeDriver edgeDriver = new EdgeDriver(options); if (edgeDriver != null) { edgeDriver.Manage().Window.Maximize(); edgeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2); } return(edgeDriver); } catch (Exception exc) { Console.WriteLine(exc.ToString()); return(null); } }
public void TestEdgeExecutionTime() { Profile ( "TestEdgeExecutionTime", 10, () => { var edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(); var edgeOptions = new Microsoft.Edge.SeleniumTools.EdgeOptions(); edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal; edgeOptions.UseChromium = true; using (IWebDriver driver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions)) { PerformTestOperations(driver); } }); }
private static IWebDriver InitializeDriverRegularMode(BrowserConfiguration executionConfiguration, OpenQA.Selenium.Proxy webDriverProxy) { IWebDriver wrappedWebDriver; switch (executionConfiguration.BrowserType) { case BrowserType.Chrome: new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser); var chromeDriverService = ChromeDriverService.CreateDefaultService(); chromeDriverService.SuppressInitialDiagnosticInformation = true; chromeDriverService.EnableVerboseLogging = false; var chromeOptions = executionConfiguration.DriverOptions; chromeOptions.AddArguments("--log-level=3"); Port = GetFreeTcpPort(); chromeDriverService.Port = Port; DebuggerPort = GetFreeTcpPort(); if (executionConfiguration.IsLighthouseEnabled) { chromeOptions.AddArgument("--remote-debugging-address=0.0.0.0"); chromeOptions.AddArgument($"--remote-debugging-port={DebuggerPort}"); ////ProcessProvider.StartCLIProcess($"chrome-debug --port={Port}"); ////chromeOptions.DebuggerAddress = $"127.0.0.1:{Port}"; } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); chromeOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}"); chromeOptions.AddArguments($"load-extension={unpackedExtensionPath}"); } if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled && !executionConfiguration.IsLighthouseEnabled) { chromeOptions.Proxy = webDriverProxy; } chromeOptions.AddArgument("hide-scrollbars"); chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All); chromeOptions.SetLoggingPreference("performance", LogLevel.All); wrappedWebDriver = new ChromeDriver(chromeDriverService, chromeOptions); break; case BrowserType.ChromeHeadless: new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser); var chromeHeadlessDriverService = ChromeDriverService.CreateDefaultService(); chromeHeadlessDriverService.SuppressInitialDiagnosticInformation = true; Port = GetFreeTcpPort(); chromeHeadlessDriverService.Port = Port; var chromeHeadlessOptions = executionConfiguration.DriverOptions; chromeHeadlessOptions.AddArguments("--headless"); chromeHeadlessOptions.AddArguments("--log-level=3"); chromeHeadlessOptions.AddArguments("--test-type"); chromeHeadlessOptions.AddArguments("--disable-infobars"); chromeHeadlessOptions.AddArguments("--allow-no-sandbox-job"); chromeHeadlessOptions.AddArguments("--ignore-certificate-errors"); chromeHeadlessOptions.AddArguments("--disable-gpu"); chromeHeadlessOptions.AddArguments("--no-sandbox"); chromeHeadlessOptions.AddUserProfilePreference("credentials_enable_service", false); chromeHeadlessOptions.AddUserProfilePreference("profile.password_manager_enabled", false); chromeHeadlessOptions.AddArgument("hide-scrollbars"); chromeHeadlessOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss; Port = GetFreeTcpPort(); chromeHeadlessDriverService.Port = Port; DebuggerPort = GetFreeTcpPort(); if (executionConfiguration.IsLighthouseEnabled) { chromeHeadlessOptions.AddArgument("--remote-debugging-address=0.0.0.0"); chromeHeadlessOptions.AddArgument($"--remote-debugging-port={DebuggerPort}"); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); chromeHeadlessOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}"); chromeHeadlessOptions.AddArguments($"load-extension={unpackedExtensionPath}"); } if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { chromeHeadlessOptions.Proxy = webDriverProxy; } chromeHeadlessOptions.SetLoggingPreference(LogType.Browser, LogLevel.All); chromeHeadlessOptions.SetLoggingPreference("performance", LogLevel.All); wrappedWebDriver = new ChromeDriver(chromeHeadlessDriverService, chromeHeadlessOptions); break; case BrowserType.Firefox: new DriverManager().SetUpDriver(new FirefoxConfig(), VersionResolveStrategy.Latest); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var firefoxOptions = executionConfiguration.DriverOptions; firefoxOptions.AddAdditionalOption("acceptInsecureCerts", true); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { firefoxOptions.Proxy = webDriverProxy; } var firefoxService = FirefoxDriverService.CreateDefaultService(); firefoxService.SuppressInitialDiagnosticInformation = true; firefoxService.Port = GetFreeTcpPort(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe")) { firefoxService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; } else { firefoxService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"; } // TODO: Anton(15.12.2019): Add option to set the path via environment variable. } var firefoxProfile = ServicesCollection.Current.Resolve <FirefoxProfile>(executionConfiguration.ClassFullName); if (firefoxProfile == null) { firefoxOptions.Profile = new FirefoxProfile(_driverExecutablePath); ServicesCollection.Current.RegisterInstance(firefoxOptions.Profile, executionConfiguration.ClassFullName); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { Logger.LogError($"Packed Extension loading not supported in Firefox!"); // 05-Nov-2020 navramov: Extension loading does not work ////string packedExtensionPath = ConfigurationService.GetSection<WebSettings>().Firefox.PackedExtensionPath.NormalizeAppPath(); ////Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); ////firefoxOptions.Profile.AddExtension(ConfigurationService.GetSection<WebSettings>().Firefox.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { Logger.LogError($"Unpacked Extension loading not supported in Firefox!"); } var firefoxTimeout = TimeSpan.FromSeconds(180); wrappedWebDriver = new FirefoxDriver(firefoxService, firefoxOptions, firefoxTimeout); break; case BrowserType.FirefoxHeadless: new DriverManager().SetUpDriver(new FirefoxConfig()); var firefoxHeadlessOptions = executionConfiguration.DriverOptions; firefoxHeadlessOptions.AddArguments("--headless"); firefoxHeadlessOptions.AddAdditionalOption("acceptInsecureCerts", true); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { firefoxHeadlessOptions.Proxy = webDriverProxy; } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); firefoxHeadlessOptions.Profile.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { Logger.LogError($"Unpacked Extension loading not supported in Firefox!"); } var service = FirefoxDriverService.CreateDefaultService(); service.SuppressInitialDiagnosticInformation = true; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe")) { service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; } else { service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"; } // TODO: Anton(15.12.2019): Add option to set the path via environment variable. } service.Port = GetFreeTcpPort(); wrappedWebDriver = new FirefoxDriver(service, firefoxHeadlessOptions); break; case BrowserType.Edge: new DriverManager().SetUpDriver(new EdgeConfig()); var edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(); edgeDriverService.SuppressInitialDiagnosticInformation = true; var edgeOptions = executionConfiguration.DriverOptions; edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal; edgeOptions.UseChromium = true; edgeOptions.AddArguments("--log-level=3"); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { edgeOptions.Proxy = webDriverProxy; } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); edgeOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}"); edgeOptions.AddArguments($"load-extension={unpackedExtensionPath}"); } edgeOptions.SetLoggingPreference(LogType.Browser, LogLevel.Severe); edgeOptions.SetLoggingPreference("performance", LogLevel.All); wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions); break; case BrowserType.EdgeHeadless: new DriverManager().SetUpDriver(new EdgeConfig()); var edgeHeadlessDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(); edgeHeadlessDriverService.SuppressInitialDiagnosticInformation = true; var edgeHeadlessOptions = executionConfiguration.DriverOptions; edgeHeadlessOptions.AddArguments("--headless"); edgeHeadlessOptions.AddArguments("--log-level=3"); edgeHeadlessOptions.AddArguments("--test-type"); edgeHeadlessOptions.AddArguments("--disable-infobars"); edgeHeadlessOptions.AddArguments("--allow-no-sandbox-job"); edgeHeadlessOptions.AddArguments("--ignore-certificate-errors"); edgeHeadlessOptions.AddArguments("--disable-gpu"); edgeHeadlessOptions.AddArguments("--no-sandbox"); edgeHeadlessOptions.AddUserProfilePreference("credentials_enable_service", false); edgeHeadlessOptions.AddUserProfilePreference("profile.password_manager_enabled", false); edgeHeadlessOptions.AddArgument("hide-scrollbars"); edgeHeadlessOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss; edgeHeadlessOptions.PageLoadStrategy = PageLoadStrategy.Normal; edgeHeadlessOptions.UseChromium = true; if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { edgeHeadlessOptions.Proxy = webDriverProxy; } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null) { string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}"); edgeHeadlessOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath); } if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null) { string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath(); Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}"); edgeHeadlessOptions.AddExtensionPath(unpackedExtensionPath); } edgeHeadlessOptions.SetLoggingPreference(LogType.Browser, LogLevel.Severe); edgeHeadlessOptions.SetLoggingPreference("performance", LogLevel.All); wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeHeadlessDriverService, edgeHeadlessOptions); break; case BrowserType.Opera: new DriverManager().SetUpDriver(new OperaConfig()); // the driver will be different for different OS. // Check for different releases- https://github.com/operasoftware/operachromiumdriver/releases var operaOptions = executionConfiguration.DriverOptions; if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { operaOptions.Proxy = webDriverProxy; } var operaService = OperaDriverService.CreateDefaultService(); operaService.SuppressInitialDiagnosticInformation = true; operaService.Port = GetFreeTcpPort(); try { wrappedWebDriver = new OperaDriver(operaService, operaOptions); } catch (WebDriverException ex) when(ex.Message.Contains("DevToolsActivePort file doesn't exist")) { throw new Exception("This is a known issue in the latest versions of Opera driver. It is reported to the Opera team. As soon it is fixed we will update BELLATRIX.", ex); } break; case BrowserType.InternetExplorer: new DriverManager().SetUpDriver(new InternetExplorerConfig()); // Steps to configure IE to always allow blocked content: // From Internet Explorer, select the Tools menu, then the Options... // In the Internet Options dialog, select the Advanced tab... // Scroll down until you see the Security options. Enable the checkbox "Allow active content to run in files on My Computer" // Also, check https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration // in case of OpenQA.Selenium.NoSuchWindowException: Unable to get browser --> Uncheck IE Options --> Security Tab -> Uncheck "Enable Protected Mode" var ieOptions = executionConfiguration.DriverOptions; ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true; ieOptions.IgnoreZoomLevel = true; ieOptions.EnableNativeEvents = false; ieOptions.EnsureCleanSession = true; ieOptions.PageLoadStrategy = PageLoadStrategy.Eager; ieOptions.ForceShellWindowsApi = true; ieOptions.AddAdditionalCapability("disable-popup-blocking", true); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { ieOptions.Proxy = webDriverProxy; } wrappedWebDriver = new InternetExplorerDriver(_driverExecutablePath, ieOptions); break; case BrowserType.Safari: var safariOptions = executionConfiguration.DriverOptions; if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { safariOptions.Proxy = webDriverProxy; } wrappedWebDriver = new SafariDriver(safariOptions); break; default: throw new NotSupportedException($"Not supported browser {executionConfiguration.BrowserType}"); } return(wrappedWebDriver); }
private static IWebDriver InitializeDriverRegularMode(BrowserConfiguration executionConfiguration, OpenQA.Selenium.Proxy webDriverProxy) { IWebDriver wrappedWebDriver; switch (executionConfiguration.BrowserType) { case BrowserType.Chrome: new DriverManager().SetUpDriver(new ChromeConfig()); var chromeDriverService = ChromeDriverService.CreateDefaultService(_driverExecutablePath); chromeDriverService.SuppressInitialDiagnosticInformation = true; chromeDriverService.EnableVerboseLogging = false; chromeDriverService.Port = GetFreeTcpPort(); var chromeOptions = GetChromeOptions(executionConfiguration.ClassFullName); chromeOptions.AddArguments("--log-level=3"); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { chromeOptions.Proxy = webDriverProxy; } wrappedWebDriver = new ChromeDriver(chromeDriverService, chromeOptions); var chromePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Chrome.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(chromePageLoadTimeout); var chromeScriptTimeout = ConfigurationService.GetSection <WebSettings>().Chrome.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(chromeScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Chrome; break; case BrowserType.ChromeHeadless: new DriverManager().SetUpDriver(new ChromeConfig()); var chromeHeadlessDriverService = ChromeDriverService.CreateDefaultService(_driverExecutablePath); chromeHeadlessDriverService.SuppressInitialDiagnosticInformation = true; chromeHeadlessDriverService.Port = GetFreeTcpPort(); var chromeHeadlessOptions = GetChromeOptions(executionConfiguration.ClassFullName); chromeHeadlessOptions.AddArguments("--headless"); chromeHeadlessOptions.AddArguments("--log-level=3"); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { chromeHeadlessOptions.Proxy = webDriverProxy; } wrappedWebDriver = new ChromeDriver(chromeHeadlessDriverService, chromeHeadlessOptions); var chromeHeadlessPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().ChromeHeadless.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(chromeHeadlessPageLoadTimeout); var chromeHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().ChromeHeadless.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(chromeHeadlessScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().ChromeHeadless; break; case BrowserType.Firefox: new DriverManager().SetUpDriver(new FirefoxConfig()); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var firefoxOptions = GetFirefoxOptions(executionConfiguration.ClassFullName); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { firefoxOptions.Proxy = webDriverProxy; } var firefoxService = FirefoxDriverService.CreateDefaultService(_driverExecutablePath); firefoxService.SuppressInitialDiagnosticInformation = true; firefoxService.Port = GetFreeTcpPort(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe")) { firefoxService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; } else { firefoxService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"; } // TODO: Anton(15.12.2019): Add option to set the path via environment variable. } var firefoxProfile = ServicesCollection.Current.Resolve <FirefoxProfile>(executionConfiguration.ClassFullName); if (firefoxProfile != null) { firefoxOptions.Profile = firefoxProfile; } var firefoxTimeout = TimeSpan.FromSeconds(180); wrappedWebDriver = new FirefoxDriver(firefoxService, firefoxOptions, firefoxTimeout); var firefoxPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Firefox.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(firefoxPageLoadTimeout); var firefoxScriptTimeout = ConfigurationService.GetSection <WebSettings>().Firefox.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(firefoxScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Firefox; break; case BrowserType.FirefoxHeadless: new DriverManager().SetUpDriver(new FirefoxConfig()); var firefoxHeadlessOptions = GetFirefoxOptions(executionConfiguration.ClassFullName); firefoxHeadlessOptions.AddArguments("--headless"); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { firefoxHeadlessOptions.Proxy = webDriverProxy; } var service = FirefoxDriverService.CreateDefaultService(_driverExecutablePath); service.SuppressInitialDiagnosticInformation = true; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe")) { service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; } else { service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"; } // TODO: Anton(15.12.2019): Add option to set the path via environment variable. } service.Port = GetFreeTcpPort(); wrappedWebDriver = new FirefoxDriver(service, firefoxHeadlessOptions); var firefoxHeadlessPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(firefoxHeadlessPageLoadTimeout); var firefoxHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(firefoxHeadlessScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless; break; case BrowserType.Edge: new DriverManager().SetUpDriver(new EdgeConfig()); var edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(_driverExecutablePath); edgeDriverService.SuppressInitialDiagnosticInformation = true; var edgeOptions = GetEdgeOptions(executionConfiguration.ClassFullName); edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal; edgeOptions.UseChromium = true; edgeOptions.AddArguments("--log-level=3"); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { edgeOptions.Proxy = webDriverProxy; } wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions); var edgePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Edge.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(edgePageLoadTimeout); var edgeScriptTimeout = ConfigurationService.GetSection <WebSettings>().Edge.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(edgeScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Edge; break; case BrowserType.EdgeHeadless: new DriverManager().SetUpDriver(new EdgeConfig()); var edgeHeadlessDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(_driverExecutablePath); edgeHeadlessDriverService.SuppressInitialDiagnosticInformation = true; var edgeHeadlessOptions = GetEdgeOptions(executionConfiguration.ClassFullName); edgeHeadlessOptions.AddArguments("--headless"); edgeHeadlessOptions.AddArguments("--log-level=3"); edgeHeadlessOptions.PageLoadStrategy = PageLoadStrategy.Normal; edgeHeadlessOptions.UseChromium = true; if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { edgeHeadlessOptions.Proxy = webDriverProxy; } wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeHeadlessDriverService, edgeHeadlessOptions); var edgeHeadlessPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Edge.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(edgeHeadlessPageLoadTimeout); var edgeHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().Edge.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(edgeHeadlessScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Edge; break; case BrowserType.Opera: new DriverManager().SetUpDriver(new OperaConfig()); // the driver will be different for different OS. // Check for different releases- https://github.com/operasoftware/operachromiumdriver/releases var operaOptions = GetOperaOptions(executionConfiguration.ClassFullName); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { operaOptions.Proxy = webDriverProxy; } var operaService = OperaDriverService.CreateDefaultService(_driverExecutablePath); operaService.SuppressInitialDiagnosticInformation = true; operaService.Port = GetFreeTcpPort(); try { wrappedWebDriver = new OperaDriver(operaService, operaOptions); } catch (WebDriverException ex) when(ex.Message.Contains("DevToolsActivePort file doesn't exist")) { throw new Exception("This is a known issue in the latest versions of Opera driver. It is reported to the Opera team. As soon it is fixed we will update BELLATRIX.", ex); } var operaPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Opera.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(operaPageLoadTimeout); var operaScriptTimeout = ConfigurationService.GetSection <WebSettings>().Opera.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(operaScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Opera; break; case BrowserType.InternetExplorer: new DriverManager().SetUpDriver(new InternetExplorerConfig()); // Steps to configure IE to always allow blocked content: // From Internet Explorer, select the Tools menu, then the Options... // In the Internet Options dialog, select the Advanced tab... // Scroll down until you see the Security options. Enable the checkbox "Allow active content to run in files on My Computer" // Also, check https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration // in case of OpenQA.Selenium.NoSuchWindowException: Unable to get browser --> Uncheck IE Options --> Security Tab -> Uncheck "Enable Protected Mode" var ieOptions = GetInternetExplorerOptions(executionConfiguration.ClassFullName); ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true; ieOptions.IgnoreZoomLevel = true; ieOptions.EnableNativeEvents = false; ieOptions.EnsureCleanSession = true; ieOptions.PageLoadStrategy = PageLoadStrategy.Eager; ieOptions.ForceShellWindowsApi = true; ieOptions.AddAdditionalCapability("disable-popup-blocking", true); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { ieOptions.Proxy = webDriverProxy; } wrappedWebDriver = new InternetExplorerDriver(_driverExecutablePath, ieOptions); var iePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().InternetExplorer.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(iePageLoadTimeout); var ieScriptTimeout = ConfigurationService.GetSection <WebSettings>().InternetExplorer.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ieScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().InternetExplorer; break; case BrowserType.Safari: var safariOptions = GetSafariOptions(executionConfiguration.ClassFullName); if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled) { safariOptions.Proxy = webDriverProxy; } wrappedWebDriver = new SafariDriver(safariOptions); var safariPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Safari.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(safariPageLoadTimeout); var safariScriptTimeout = ConfigurationService.GetSection <WebSettings>().Safari.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(safariScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Safari; break; default: throw new NotSupportedException($"Not supported browser {executionConfiguration.BrowserType}"); } return(wrappedWebDriver); }