/// <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, 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.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); }
/// <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, OnDriverCreatedActions = BuildingContext.OnDriverCreatedActions?.ToList() ?? new List <Action <RemoteWebDriver> >(), CleanUpActions = BuildingContext.CleanUpActions?.ToList() ?? new List <Action>(), 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() }; AtataContext.Current = context; OnBuilding(context); if (context.BaseUrl != null) { context.Log.Trace($"Set: BaseUrl={context.BaseUrl}"); } LogRetrySettings(context); if (BuildingContext.Culture != null) { ApplyCulture(context, BuildingContext.Culture); } context.DriverFactory = BuildingContext.DriverFactoryToUse; context.DriverAlias = BuildingContext.DriverFactoryToUse.Alias; context.InitDriver(); context.Log.Trace($"Set: Driver={context.Driver.GetType().Name}{BuildingContext.DriverFactoryToUse?.Alias?.ToFormattedString(" (alias={0})")}"); OnBuilt(context); 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); } 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); }