public static IWebDriver Create(BrowserConfiguration executionConfiguration) { ProcessCleanupService.KillAllDriversAndChildProcessesWindows(); DisposeDriverService.TestRunStartTime = DateTime.Now; BrowserConfiguration = executionConfiguration; var wrappedWebDriver = default(IWebDriver); _proxyService = ServicesCollection.Current.Resolve <ProxyService>(); var webDriverProxy = new OpenQA.Selenium.Proxy { HttpProxy = $"http://127.0.0.1:{_proxyService.Port}", SslProxy = $"http://127.0.0.1:{_proxyService.Port}", }; switch (executionConfiguration.ExecutionType) { case ExecutionType.Regular: wrappedWebDriver = InitializeDriverRegularMode(executionConfiguration, webDriverProxy); break; case ExecutionType.Grid: var gridUrl = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Url; if (gridUrl == null || !Uri.IsWellFormedUriString(gridUrl.ToString(), UriKind.Absolute)) { throw new ArgumentException("To execute your tests in WebDriver Grid mode you need to set the gridUri in the browserSettings file."); } DebuggerPort = GetFreeTcpPort(); if (executionConfiguration.IsLighthouseEnabled && (executionConfiguration.BrowserType.Equals(BrowserType.Chrome) || executionConfiguration.BrowserType.Equals(BrowserType.ChromeHeadless))) { executionConfiguration.DriverOptions.AddArgument("--remote-debugging-address=0.0.0.0"); executionConfiguration.DriverOptions.AddArgument($"--remote-debugging-port={DebuggerPort}"); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); wrappedWebDriver = new RemoteWebDriver(new Uri(gridUrl), executionConfiguration.DriverOptions); break; } var gridPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().TimeoutSettings.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(gridPageLoadTimeout); var gridScriptTimeout = ConfigurationService.GetSection <WebSettings>().TimeoutSettings.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(gridScriptTimeout); if (executionConfiguration.BrowserType != BrowserType.Edge) { FixDriverCommandExecutionDelay((WebDriver)wrappedWebDriver); } ChangeWindowSize(executionConfiguration.Size, wrappedWebDriver); return(wrappedWebDriver); }
public static void Dispose(IWebDriver webDriver, ServicesCollection container) { try { webDriver?.Quit(); webDriver?.Dispose(); container?.UnregisterSingleInstance <IWebDriver>(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } ProcessCleanupService.KillPreviousDriversAndBrowsersOsAgnostic(TestRunStartTime); }
public static void Dispose() { try { var driver = ServicesCollection.Current.Resolve <IWebDriver>(); driver?.Quit(); driver?.Dispose(); ServicesCollection.Current?.UnregisterSingleInstance <IWebDriver>(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } ProcessCleanupService.KillPreviousDriversAndBrowsersOsAgnostic(TestRunStartTime); }
public static void Dispose(IWebDriver webDriver, ServicesCollection container) { try { webDriver?.Close(); webDriver?.Quit(); webDriver?.Dispose(); container?.UnregisterSingleInstance <IWebDriver>(); } catch (Exception ex) { DebugInformation.PrintStackTrace(ex); } ProcessCleanupService.KillPreviousDriversAndBrowsersOsAgnostic(TestRunStartTime); }
public static IWebDriver Create(BrowserConfiguration executionConfiguration) { ProcessCleanupService.KillAllDriversAndChildProcessesWindows(); DisposeDriverService.TestRunStartTime = DateTime.Now; BrowserConfiguration = executionConfiguration; var wrappedWebDriver = default(IWebDriver); _proxyService = ServicesCollection.Current.Resolve <ProxyService>(); var webDriverProxy = new OpenQA.Selenium.Proxy { HttpProxy = $"http://127.0.0.1:{_proxyService.Port}", SslProxy = $"http://127.0.0.1:{_proxyService.Port}", }; switch (executionConfiguration.ExecutionType) { case ExecutionType.Regular: wrappedWebDriver = InitializeDriverRegularMode(executionConfiguration, webDriverProxy); break; case ExecutionType.Grid: var gridUri = ConfigurationService.GetSection <WebSettings>().Remote.GridUri; if (gridUri == null || !Uri.IsWellFormedUriString(gridUri.ToString(), UriKind.Absolute)) { throw new ArgumentException("To execute your tests in WebDriver Grid mode you need to set the gridUri in the browserSettings file."); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); wrappedWebDriver = new RemoteWebDriver(gridUri, executionConfiguration.DriverOptions); var gridPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Remote.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(gridPageLoadTimeout); var gridScriptTimeout = ConfigurationService.GetSection <WebSettings>().Remote.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(gridScriptTimeout); BrowserSettings = ConfigurationService.GetSection <WebSettings>().Remote; ChangeWindowSize(executionConfiguration.BrowserType, executionConfiguration.Size, wrappedWebDriver); break; case ExecutionType.BrowserStack: var browserStackUri = ConfigurationService.GetSection <WebSettings>().BrowserStack.GridUri; BrowserSettings = ConfigurationService.GetSection <WebSettings>().BrowserStack; if (browserStackUri == null || !Uri.IsWellFormedUriString(browserStackUri.ToString(), UriKind.Absolute)) { throw new ArgumentException("To execute your tests in BrowserStack you need to set the gridUri in the browserSettings file."); } wrappedWebDriver = new RemoteWebDriver(browserStackUri, executionConfiguration.DriverOptions); var browserStackPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().BrowserStack.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(browserStackPageLoadTimeout); var browserStackScriptTimeout = ConfigurationService.GetSection <WebSettings>().BrowserStack.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(browserStackScriptTimeout); break; case ExecutionType.CrossBrowserTesting: var crossBrowserTestingUri = ConfigurationService.GetSection <WebSettings>().CrossBrowserTesting.GridUri; BrowserSettings = ConfigurationService.GetSection <WebSettings>().CrossBrowserTesting; if (crossBrowserTestingUri == null || !Uri.IsWellFormedUriString(crossBrowserTestingUri.ToString(), UriKind.Absolute)) { throw new ArgumentException("To execute your tests in CrossBrowserTesting you need to set the gridUri in the browserSettings file."); } wrappedWebDriver = new RemoteWebDriver(crossBrowserTestingUri, executionConfiguration.DriverOptions); var crossBrowserTestingPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().CrossBrowserTesting.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(crossBrowserTestingPageLoadTimeout); var crossBrowserTestingScriptTimeout = ConfigurationService.GetSection <WebSettings>().CrossBrowserTesting.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(crossBrowserTestingScriptTimeout); break; case ExecutionType.SauceLabs: var sauceLabsSettings = ConfigurationService.GetSection <WebSettings>().SauceLabs; var sauceLabsUri = sauceLabsSettings.GridUri; if (sauceLabsUri == null || !Uri.IsWellFormedUriString(sauceLabsUri.ToString(), UriKind.Absolute)) { throw new ArgumentException("To execute your tests in SauceLabs you need to set the gridUri in the browserSettings file."); } wrappedWebDriver = new RemoteWebDriver(sauceLabsUri, executionConfiguration.DriverOptions); var sauceLabsPageLoadTimeout = sauceLabsSettings.PageLoadTimeout; wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(sauceLabsPageLoadTimeout); var sauceLabsScriptTimeout = sauceLabsSettings.ScriptTimeout; wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(sauceLabsScriptTimeout); BrowserSettings = sauceLabsSettings; break; } if (executionConfiguration.BrowserType != BrowserType.Edge) { FixDriverCommandExecutionDelay((RemoteWebDriver)wrappedWebDriver); } ChangeWindowSize(executionConfiguration.BrowserType, executionConfiguration.Size, wrappedWebDriver); return(wrappedWebDriver); }