/// <summary> /// Builds the <see cref="AtataContext" /> instance and sets it to <see cref="AtataContext.Current" /> property. /// </summary> /// <returns>The created <see cref="AtataContext"/> instance.</returns> public AtataContext Build() { AtataContext.InitGlobalVariables(); LogManager logManager = new LogManager(); foreach (var logConsumerItem in BuildingContext.LogConsumers) { logManager.Use(logConsumerItem.Consumer, logConsumerItem.MinLevel, logConsumerItem.LogSectionFinish); } foreach (var screenshotConsumer in BuildingContext.ScreenshotConsumers) { logManager.Use(screenshotConsumer); } AtataContext context = new AtataContext { TestName = BuildingContext.TestNameFactory?.Invoke(), BaseUrl = BuildingContext.BaseUrl, Log = logManager, CleanUpActions = BuildingContext.CleanUpActions, RetryTimeout = BuildingContext.RetryTimeout, RetryInterval = BuildingContext.RetryInterval, AssertionExceptionType = BuildingContext.AssertionExceptionType }; AtataContext.Current = context; context.LogTestStart(); context.Log.Start("Set up AtataContext", LogLevel.Trace); if (context.BaseUrl != null) { context.Log.Trace($"Set: BaseUrl={context.BaseUrl}"); } context.Log.Trace($"Set: RetryTimeout={context.RetryTimeout.ToIntervalString()}; RetryInterval={context.RetryInterval.ToIntervalString()}"); context.Driver = BuildingContext.DriverFactoryToUse?.Create() ?? new FirefoxDriver(); context.DriverAlias = BuildingContext.DriverFactoryToUse?.Alias ?? DriverAliases.Firefox; context.Log.Trace($"Set: Driver={context.Driver.GetType().Name}{BuildingContext.DriverFactoryToUse?.Alias?.ToFormattedString(" (alias={0})")}"); context.Driver.Manage().Timeouts().SetRetryTimeout(BuildingContext.RetryTimeout, BuildingContext.RetryInterval); context.Log.EndSection(); context.CleanExecutionStartDateTime = DateTime.Now; return(context); }
private void OnBuilding(AtataContext context) { context.LogTestStart(); context.Log.Start("Set up AtataContext", LogLevel.Trace); if (BuildingContext.OnBuildingActions != null) { foreach (Action action in BuildingContext.OnBuildingActions) { try { action(); } catch (Exception e) { context.Log.Error($"On {nameof(AtataContext)} building action failure.", e); } } } }
/// <summary> /// Sets up the context. /// </summary> public void SetUp() { AtataContext.InitGlobalVariables(); LogManager logManager = new LogManager(); foreach (var logConsumerItem in BuildingContext.LogConsumers) { logManager.Use(logConsumerItem.Consumer, logConsumerItem.MinLevel, logConsumerItem.LogSectionFinish); } foreach (var screenshotConsumer in BuildingContext.ScreenshotConsumers) { logManager.Use(screenshotConsumer); } AtataContext context = new AtataContext { TestName = BuildingContext.TestName, BaseUrl = BuildingContext.BaseUrl, Log = logManager, CleanUpActions = BuildingContext.CleanUpActions, RetryTimeout = BuildingContext.RetryTimeout, RetryInterval = BuildingContext.RetryInterval }; AtataContext.Current = context; context.LogTestStart(); context.Log.Start("Init WebDriver"); context.Driver = BuildingContext.DriverCreator?.Invoke() ?? new FirefoxDriver(); context.Driver.Manage().Timeouts().SetRetryTimeout(BuildingContext.RetryTimeout, BuildingContext.RetryInterval); context.Log.EndSection(); context.CleanExecutionStartDateTime = DateTime.Now; }
/// <summary> /// Builds the <see cref="AtataContext" /> instance and sets it to <see cref="AtataContext.Current" /> property. /// </summary> /// <returns>The created <see cref="AtataContext"/> instance.</returns> public AtataContext Build() { AtataContext.InitGlobalVariables(); ValidateBuildingContextBeforeBuild(); LogManager logManager = new LogManager(); foreach (var logConsumerItem in BuildingContext.LogConsumers) { logManager.Use(logConsumerItem); } foreach (var screenshotConsumer in BuildingContext.ScreenshotConsumers) { logManager.Use(screenshotConsumer); } IObjectConverter objectConverter = new ObjectConverter { AssemblyNamePatternToFindTypes = BuildingContext.DefaultAssemblyNamePatternToFindTypes }; IObjectMapper objectMapper = new ObjectMapper(objectConverter); IObjectCreator objectCreator = new ObjectCreator(objectConverter, objectMapper); AtataContext context = new AtataContext { TestName = BuildingContext.TestNameFactory?.Invoke(), BaseUrl = BuildingContext.BaseUrl, Log = logManager, OnDriverCreatedActions = BuildingContext.OnDriverCreatedActions?.ToList() ?? new List <Action <RemoteWebDriver> >(), CleanUpActions = BuildingContext.CleanUpActions?.ToList() ?? new List <Action>(), Attributes = BuildingContext.Attributes.Clone(), BaseRetryTimeout = BuildingContext.BaseRetryTimeout, BaseRetryInterval = BuildingContext.BaseRetryInterval, ElementFindTimeout = BuildingContext.ElementFindTimeout, ElementFindRetryInterval = BuildingContext.ElementFindRetryInterval, WaitingTimeout = BuildingContext.WaitingTimeout, WaitingRetryInterval = BuildingContext.WaitingRetryInterval, VerificationTimeout = BuildingContext.VerificationTimeout, VerificationRetryInterval = BuildingContext.VerificationRetryInterval, Culture = BuildingContext.Culture ?? CultureInfo.CurrentCulture, AssertionExceptionType = BuildingContext.AssertionExceptionType, AggregateAssertionExceptionType = BuildingContext.AggregateAssertionExceptionType, AggregateAssertionStrategy = BuildingContext.AggregateAssertionStrategy ?? new AtataAggregateAssertionStrategy(), WarningReportStrategy = BuildingContext.WarningReportStrategy ?? new AtataWarningReportStrategy(), ObjectConverter = objectConverter, ObjectMapper = objectMapper, ObjectCreator = objectCreator }; AtataContext.Current = context; context.LogTestStart(); context.Log.ExecuteSection( new LogSection("Set up AtataContext", LogLevel.Trace), () => SetUp(context)); context.PureExecutionStopwatch.Start(); return(context); }
/// <summary> /// Builds the <see cref="AtataContext" /> instance and sets it to <see cref="AtataContext.Current" /> property. /// </summary> /// <returns>The created <see cref="AtataContext"/> instance.</returns> public AtataContext Build() { AtataContext.InitGlobalVariables(); ValidateBuildingContextBeforeBuild(); LogManager logManager = new LogManager(); foreach (var logConsumerItem in BuildingContext.LogConsumers) { logManager.Use(logConsumerItem.Consumer, logConsumerItem.MinLevel, logConsumerItem.LogSectionFinish); } foreach (var screenshotConsumer in BuildingContext.ScreenshotConsumers) { logManager.Use(screenshotConsumer); } AtataContext context = new AtataContext { TestName = BuildingContext.TestNameFactory?.Invoke(), BaseUrl = BuildingContext.BaseUrl, Log = logManager, CleanUpActions = BuildingContext.CleanUpActions, RetryTimeout = BuildingContext.RetryTimeout, RetryInterval = BuildingContext.RetryInterval, Culture = BuildingContext.Culture ?? CultureInfo.CurrentCulture, AssertionExceptionType = BuildingContext.AssertionExceptionType }; AtataContext.Current = context; context.LogTestStart(); context.Log.Start("Set up AtataContext", LogLevel.Trace); if (context.BaseUrl != null) { context.Log.Trace($"Set: BaseUrl={context.BaseUrl}"); } context.Log.Trace($"Set: RetryTimeout={context.RetryTimeout.ToIntervalString()}; RetryInterval={context.RetryInterval.ToIntervalString()}"); if (BuildingContext.Culture != null) { if (AtataContext.IsThreadStatic) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = BuildingContext.Culture; } else { #if NET40 Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = BuildingContext.Culture; #else CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = BuildingContext.Culture; #endif } context.Log.Trace($"Set: Culture={BuildingContext.Culture.Name}"); } context.DriverFactory = BuildingContext.DriverFactoryToUse; context.Driver = BuildingContext.DriverFactoryToUse.Create(); if (context.Driver == null) { throw new InvalidOperationException($"Failed to build {nameof(AtataContext)} as driver factory returned 'null' as a driver."); } context.DriverAlias = BuildingContext.DriverFactoryToUse.Alias; context.Log.Trace($"Set: Driver={context.Driver.GetType().Name}{BuildingContext.DriverFactoryToUse?.Alias?.ToFormattedString(" (alias={0})")}"); context.Driver.Manage().Timeouts().SetRetryTimeout(BuildingContext.RetryTimeout, BuildingContext.RetryInterval); context.Log.EndSection(); context.CleanExecutionStartDateTime = DateTime.Now; return(context); }