protected override void PreTestsArrange(object sender, Bellatrix.Plugins.PluginEventArgs e) { if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.IsCloudRun) { e.Container.RegisterInstance(false, "_isBrowserStartedDuringPreTestsArrange"); return; } // Resolve required data for decision making var currentBrowserConfiguration = GetCurrentBrowserConfiguration(e); if (currentBrowserConfiguration != null) { ResolvePreviousBrowserType(e.Container); // Decide whether the browser needs to be restarted bool shouldRestartBrowser = ShouldRestartBrowser(e.Container); if (shouldRestartBrowser) { RestartBrowser(e.Container); e.Container.RegisterInstance(true, "_isBrowserStartedDuringPreTestsArrange"); } } else { e.Container.RegisterInstance(false, "_isBrowserStartedDuringPreTestsArrange"); } base.PreTestsArrange(sender, e); }
protected override void PostTestCleanup(object sender, Bellatrix.Plugins.PluginEventArgs e) { var currentBrowserConfiguration = GetCurrentBrowserConfiguration(e); if (currentBrowserConfiguration != null) { if (currentBrowserConfiguration.ShouldCaptureHttpTraffic) { var proxyService = e.Container.Resolve <ProxyService>(); if (proxyService != null) { proxyService.RequestsHistory.Clear(); proxyService.ResponsesHistory.Clear(); } } if (currentBrowserConfiguration.BrowserBehavior == Lifecycle.RestartEveryTime || (currentBrowserConfiguration.BrowserBehavior == Lifecycle.RestartOnFail && !e.TestOutcome.Equals(TestOutcome.Passed))) { ShutdownBrowser(e.Container); e.Container.RegisterInstance(false, "_isAppStartedDuringPreTestsArrange"); } } }
private BrowserConfiguration GetCurrentBrowserConfiguration(Bellatrix.Plugins.PluginEventArgs e) { var browserAttribute = GetBrowserAttribute(e.TestMethodMemberInfo, e.TestClassType); string fullClassName = e.TestClassType.FullName; if (browserAttribute != null) { BrowserType currentBrowserType = browserAttribute.Browser; Lifecycle currentLifecycle = browserAttribute.Lifecycle; bool shouldCaptureHttpTraffic = browserAttribute.ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = browserAttribute.ShouldAutomaticallyScrollToVisible; Size currentBrowserSize = browserAttribute.Size; ExecutionType executionType = browserAttribute.ExecutionType; var options = (browserAttribute as IDriverOptionsAttribute)?.CreateOptions(e.TestMethodMemberInfo, e.TestClassType) ?? GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } else { BrowserType currentBrowserType = Parse <BrowserType>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultBrowser); if (e.Arguments != null & e.Arguments.Any()) { if (e.Arguments[0] is BrowserType) { currentBrowserType = (BrowserType)e.Arguments[0]; } } Lifecycle currentLifecycle = Parse <Lifecycle>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultLifeCycle); Size currentBrowserSize = default; if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution)) { currentBrowserSize = WindowsSizeResolver.GetWindowSize(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution); } ExecutionType executionType = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.ExecutionType.ToLower() == "regular" ? ExecutionType.Regular : ExecutionType.Grid; bool shouldCaptureHttpTraffic = ConfigurationService.GetSection <WebSettings>().ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var options = GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion)) { options.BrowserVersion = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion; } if (e.Arguments != null & e.Arguments.Count >= 2) { if (e.Arguments[0] is BrowserType && e.Arguments[1] is int) { options.BrowserVersion = e.Arguments[1].ToString(); } } string testName = e.TestFullName != null?e.TestFullName.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty).Replace("\"", string.Empty) : e.TestClassType.FullName; InitializeGridOptionsFromConfiguration(options, e.TestClassType, testName); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } }