/// <summary>
        /// Defines that the name of the test should be taken from the NUnit test.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder UseNUnitTestName(this AtataContextBuilder builder)
        {
            dynamic testContext = GetNUnitTestContext();
            string  testName    = testContext.Test.Name;

            return(builder.UseTestName(testName));
        }
예제 #2
0
        /// <summary>
        /// Applies JSON configuration from the file. By default reads "Atata.json" file.
        /// </summary>
        /// <typeparam name="TConfig">The type of the configuration class.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="environmentAlias">The environment alias.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder ApplyJsonConfig <TConfig>(this AtataContextBuilder builder, string filePath = null, string environmentAlias = null)
            where TConfig : JsonConfig <TConfig>, new()
        {
            string jsonContent = JsonConfigFile.ReadText(filePath, environmentAlias);

            TConfig config = JsonConvert.DeserializeObject <TConfig>(jsonContent);

            AtataContextBuilder resultBuilder = JsonConfigMapper.Map(config, builder);

            if (builder.BuildingContext == AtataContext.GlobalConfiguration.BuildingContext)
            {
                JsonConfigManager <TConfig> .UpdateGlobalValue(jsonContent, config);

                EnsureInitConfigEventHandlerIsSubscribed <TConfig>(resultBuilder);
            }
            else
            {
                JsonConfigManager <TConfig> .InitCurrentValue();

                JsonConfigManager <TConfig> .UpdateCurrentValue(jsonContent, config);
            }

            EnsureResetConfigEventHandlerIsSubscribed <TConfig>(resultBuilder);

            resultBuilder.EventSubscriptions.Add(
                new LogJsonConfigPathEventHandler(JsonConfigFile.GetRelativePath(filePath, environmentAlias)));

            return(resultBuilder);
        }
예제 #3
0
        /// <summary>
        /// Specifies the minimum level of the log event to write to the log.
        /// </summary>
        /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="level">The level.</param>
        /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
        public static AtataContextBuilder <TLogConsumer> WithMinLevel <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder, LogLevel level)
            where TLogConsumer : ILogConsumer
        {
            LogConsumerInfo consumerInfo = builder.BuildingContext.LogConsumers.Single(x => Equals(x.Consumer, builder.Context));

            consumerInfo.MinLevel = level;
            return(builder);
        }
예제 #4
0
        private static void EnsureResetConfigEventHandlerIsSubscribed <TConfig>(AtataContextBuilder builder)
            where TConfig : JsonConfig <TConfig>
        {
            bool isResetConfigSubscribed = builder.BuildingContext.EventSubscriptions
                                           .Any(x => x.EventType == typeof(AtataContextCleanUpEvent) && x.EventHandler is ResetCurrentJsonConfigEventHandler <TConfig>);

            if (!isResetConfigSubscribed)
            {
                builder.EventSubscriptions.Add(new ResetCurrentJsonConfigEventHandler <TConfig>());
            }
        }
예제 #5
0
        /// <summary>
        /// Defines that an error occurred during the NUnit test execution should be added to the log during the cleanup.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder LogNUnitError(this AtataContextBuilder builder)
        {
            return(builder.OnCleanUp(() =>
            {
                dynamic testResult = GetNUnitTestResult();

                if (IsNUnitTestResultFailed(testResult))
                {
                    AtataContext.Current.Log.Error((string)testResult.Message, (string)testResult.StackTrace);
                }
            }));
        }
예제 #6
0
        /// <summary>
        /// Defines that an error occurred during the NUnit test execution should be captured by a screenshot during the cleanup.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="title">The screenshot title.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder TakeScreenshotOnNUnitError(this AtataContextBuilder builder, string title = "Failed")
        {
            return(builder.OnCleanUp(() =>
            {
                dynamic testResult = GetNUnitTestResult();

                if (IsNUnitTestResultFailed(testResult))
                {
                    AtataContext.Current.Log.Screenshot(title);
                }
            }));
        }
        /// <summary>
        /// Defines that an error occured during the NUnit test execution should be added to the log upon the clean up.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder LogNUnitError(this AtataContextBuilder builder)
        {
            return(builder.OnCleanUp(() =>
            {
                dynamic testContext = GetNUnitTestContext();
                var testResult = testContext.Result;

                if ((bool)testResult.Outcome.Status.ToString().Contains("Fail"))
                {
                    AtataContext.Current.Log.Error((string)testResult.Message, (string)testResult.StackTrace);
                }
            }));
        }
예제 #8
0
 /// <summary>
 /// Specifies the layout of log event.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="layout">The layout of log event.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <NLogFileConsumer> WithLayout(this AtataContextBuilder <NLogFileConsumer> builder, string layout)
 {
     builder.Context.Layout = layout;
     return(builder);
 }
예제 #9
0
 /// <summary>
 /// Specifies the minimum level of the log event to write to the log.
 /// The default value is <see cref="LogLevel.Trace"/>.
 /// </summary>
 /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="level">The level.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <TLogConsumer> WithMinLevel <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder, LogLevel level)
     where TLogConsumer : ILogConsumer
 {
     GetCurrentLogConsumerInfo(builder).MinLevel = level;
     return(builder);
 }
예제 #10
0
        /// <summary>
        /// Specifies the file name of the log file.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="fileName">The file path.</param>
        /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
        public static AtataContextBuilder <NLogFileConsumer> WithFileName(this AtataContextBuilder <NLogFileConsumer> builder, string fileName)
        {
            fileName.CheckNotNullOrWhitespace(nameof(fileName));

            return(builder.WithFileName(_ => fileName));
        }
예제 #11
0
 /// <summary>
 /// Specifies the file name builder for the log file.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="fileNameBuilder">The file path builder function.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <NLogFileConsumer> WithFileName(this AtataContextBuilder <NLogFileConsumer> builder, Func <AtataContext, string> fileNameBuilder)
 {
     builder.Context.FileNameBuilder = fileNameBuilder;
     return(builder);
 }
예제 #12
0
 /// <summary>
 /// Applies JSON configuration from the file. By default reads "Atata.json" file.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="filePath">The file path.</param>
 /// <param name="environmentAlias">The environment alias.</param>
 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
 public static AtataContextBuilder ApplyJsonConfig(this AtataContextBuilder builder, string filePath = null, string environmentAlias = null)
 {
     return(builder.ApplyJsonConfig <JsonConfig>(filePath, environmentAlias));
 }
예제 #13
0
 /// <summary>
 /// Use the <see cref="EdgeDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="EdgeAtataContextBuilder"/> instance.</returns>
 public static EdgeAtataContextBuilder UseEdge(this AtataContextBuilder builder)
 {
     return(new EdgeAtataContextBuilder(builder.BuildingContext));
 }
예제 #14
0
 /// <summary>
 /// Defines that the logging should not use section-like pair messages (not <c>"Starting: {action}"</c> and <c>"Finished: {action}"</c>, but just <c>"{action}"</c>).
 /// </summary>
 /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <TLogConsumer> WithoutSectionFinish <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder)
     where TLogConsumer : ILogConsumer
 {
     GetCurrentLogConsumerInfo(builder).LogSectionFinish = false;
     return(builder);
 }
예제 #15
0
 private static LogConsumerInfo GetCurrentLogConsumerInfo <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder)
     where TLogConsumer : ILogConsumer
 {
     return(builder.BuildingContext.LogConsumers.Single(x => Equals(x.Consumer, builder.Context)));
 }
예제 #16
0
 /// <summary>
 /// Specifies the name of the logger repository.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="repositoryName">The name of the logger repository.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <Log4NetConsumer> WithRepositoryName(this AtataContextBuilder <Log4NetConsumer> builder, string repositoryName)
 {
     builder.Context.RepositoryName = repositoryName;
     return(builder);
 }
예제 #17
0
 /// <summary>
 /// Specifies the assembly to use to lookup the logger repository.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="repositoryAssembly">The name of the assembly to use to lookup the repository.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <Log4NetConsumer> WithRepositoryAssembly(this AtataContextBuilder <Log4NetConsumer> builder, Assembly repositoryAssembly)
 {
     builder.Context.RepositoryAssembly = repositoryAssembly;
     return(builder);
 }
예제 #18
0
 /// <summary>
 /// Use the <see cref="SafariDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="SafariAtataContextBuilder"/> instance.</returns>
 public static SafariAtataContextBuilder UseSafari(this AtataContextBuilder builder)
 {
     return(new SafariAtataContextBuilder(builder.BuildingContext));
 }
예제 #19
0
 /// <summary>
 /// Use the <see cref="PhantomJSDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="PhantomJSAtataContextBuilder"/> instance.</returns>
 public static PhantomJSAtataContextBuilder UsePhantomJS(this AtataContextBuilder builder)
 {
     return(new PhantomJSAtataContextBuilder(builder.BuildingContext));
 }
예제 #20
0
 /// <summary>
 /// Use the <see cref="OperaDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="OperaAtataContextBuilder"/> instance.</returns>
 public static OperaAtataContextBuilder UseOpera(this AtataContextBuilder builder)
 {
     return(new OperaAtataContextBuilder(builder.BuildingContext));
 }
예제 #21
0
 /// <summary>
 /// Specifies the nesting level indent of the log message.
 /// The default value is <c>"- "</c>.
 /// </summary>
 /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="messageNestingLevelIndent">The message nesting level indent.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <TLogConsumer> WithMessageNestingLevelIndent <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder, string messageNestingLevelIndent)
     where TLogConsumer : ILogConsumer
 {
     GetCurrentLogConsumerInfo(builder).MessageNestingLevelIndent = messageNestingLevelIndent;
     return(builder);
 }
예제 #22
0
 /// <summary>
 /// Use the <see cref="FirefoxDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="FirefoxAtataContextBuilder"/> instance.</returns>
 public static FirefoxAtataContextBuilder UseFirefox(this AtataContextBuilder builder)
 {
     return(new FirefoxAtataContextBuilder(builder.BuildingContext));
 }
예제 #23
0
 /// <summary>
 /// Specifies the end section prefix of the log message.
 /// The default value is <c>"&lt; "</c>.
 /// </summary>
 /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="messageEndSectionPrefix">The message end section prefix.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <TLogConsumer> WithMessageEndSectionPrefix <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder, string messageEndSectionPrefix)
     where TLogConsumer : ILogConsumer
 {
     GetCurrentLogConsumerInfo(builder).MessageEndSectionPrefix = messageEndSectionPrefix;
     return(builder);
 }
예제 #24
0
 /// <summary>
 /// Applies JSON configuration from <paramref name="config"/> parameter.
 /// </summary>
 /// <typeparam name="TConfig">The type of the configuration class.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="config">The configuration.</param>
 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
 public static AtataContextBuilder ApplyJsonConfig <TConfig>(this AtataContextBuilder builder, JsonConfig <TConfig> config)
     where TConfig : JsonConfig <TConfig>
 {
     return(JsonConfigMapper.Map((TConfig)config, builder));
 }
예제 #25
0
 /// <summary>
 /// Specifies the name of the logger.
 /// </summary>
 /// <typeparam name="TLogConsumer">The type of the log consumer.</typeparam>
 /// <param name="builder">The builder.</param>
 /// <param name="loggerName">The name of the logger.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <TLogConsumer> WithLoggerName <TLogConsumer>(this AtataContextBuilder <TLogConsumer> builder, string loggerName)
     where TLogConsumer : INamedLogConsumer
 {
     builder.Context.LoggerName = loggerName;
     return(builder);
 }
예제 #26
0
        /// <summary>
        /// Defines that the logging should not use section-like messages (not "Starting: {action}" and "Finished: {action}", but just "{action}").
        /// </summary>
        /// <typeparam name="TTLogConsumer">The type of the log consumer.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <returns>The <see cref="AtataContextBuilder{TTLogConsumer}"/> instance.</returns>
        public static AtataContextBuilder <TTLogConsumer> WithoutSectionFinish <TTLogConsumer>(this AtataContextBuilder <TTLogConsumer> builder)
            where TTLogConsumer : ILogConsumer
        {
            LogConsumerInfo consumerInfo = builder.BuildingContext.LogConsumers.Single(x => Equals(x.Consumer, builder.Context));

            consumerInfo.LogSectionFinish = false;
            return(builder);
        }
예제 #27
0
        /// <summary>
        /// Specifies the folder path of the log file.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="folderPath">The folder path.</param>
        /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
        public static AtataContextBuilder <NLogFileConsumer> WithFolderPath(this AtataContextBuilder <NLogFileConsumer> builder, string folderPath)
        {
            folderPath.CheckNotNullOrWhitespace(nameof(folderPath));

            return(builder.WithFolderPath(_ => folderPath));
        }
예제 #28
0
 /// <summary>
 /// Use the <see cref="InternetExplorerDriver"/>.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="InternetExplorerAtataContextBuilder"/> instance.</returns>
 public static InternetExplorerAtataContextBuilder UseInternetExplorer(this AtataContextBuilder builder)
 {
     return(new InternetExplorerAtataContextBuilder(builder.BuildingContext));
 }
예제 #29
0
 /// <summary>
 /// Sets the <see cref="AtataContext"/> Artifacts folder as the folder path of the file screenshot consumer.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The <see cref="AtataContextBuilder{FileScreenshotConsumer}"/> instance.</returns>
 public static AtataContextBuilder <NLogFileConsumer> WithArtifactsFolderPath(this AtataContextBuilder <NLogFileConsumer> builder) =>
 builder.WithFolderPath(x => x.Artifacts.FullName);
예제 #30
0
 /// <summary>
 /// Specifies the folder path builder for the log file.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="folderPathBuilder">The folder path builder function.</param>
 /// <returns>The <see cref="AtataContextBuilder{TContext}"/> instance.</returns>
 public static AtataContextBuilder <NLogFileConsumer> WithFolderPath(this AtataContextBuilder <NLogFileConsumer> builder, Func <AtataContext, string> folderPathBuilder)
 {
     builder.Context.FolderPathBuilder = folderPathBuilder;
     return(builder);
 }