コード例 #1
0
        /// <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
            };

            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);
        }
コード例 #2
0
ファイル: AtataContextBuilder.cs プロジェクト: Bendram/atata
        /// <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);
        }