Best Atata code snippet using Atata.AtataAggregateAssertionStrategy.Assert
AtataContextBuilder.cs
Source:AtataContextBuilder.cs
...706 }707708 /// <summary>709 /// Sets the type of the assertion exception.710 /// The default value is a type of <see cref="AssertionException"/>.711 /// </summary>712 /// <typeparam name="TException">The type of the exception.</typeparam>713 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>714 public AtataContextBuilder UseAssertionExceptionType<TException>()715 where TException : Exception716 {717 return UseAssertionExceptionType(typeof(TException));718 }719720 /// <summary>721 /// Sets the type of the assertion exception.722 /// The default value is a type of <see cref="AssertionException"/>.723 /// </summary>724 /// <param name="exceptionType">The type of the exception.</param>725 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>726 public AtataContextBuilder UseAssertionExceptionType(Type exceptionType)727 {728 exceptionType.CheckIs<Exception>(nameof(exceptionType));729730 BuildingContext.AssertionExceptionType = exceptionType;731 return this;732 }733734 /// <summary>735 /// Sets the type of aggregate assertion exception.736 /// The default value is a type of <see cref="AggregateAssertionException"/>.737 /// The exception type should have public constructor with <c>IEnumerable<AssertionResult></c> argument.738 /// </summary>739 /// <typeparam name="TException">The type of the exception.</typeparam>740 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>741 public AtataContextBuilder UseAggregateAssertionExceptionType<TException>()742 where TException : Exception743 {744 return UseAggregateAssertionExceptionType(typeof(TException));745 }746747 /// <summary>748 /// Sets the type of aggregate assertion exception.749 /// The default value is a type of <see cref="AggregateAssertionException"/>.750 /// The exception type should have public constructor with <c>IEnumerable<AssertionResult></c> argument.751 /// </summary>752 /// <param name="exceptionType">The type of the exception.</param>753 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>754 public AtataContextBuilder UseAggregateAssertionExceptionType(Type exceptionType)755 {756 exceptionType.CheckIs<Exception>(nameof(exceptionType));757758 BuildingContext.AggregateAssertionExceptionType = exceptionType;759 return this;760 }761762 /// <summary>763 /// Sets the default assembly name pattern that is used to filter assemblies to find types in them.764 /// Modifies the <see cref="AtataBuildingContext.DefaultAssemblyNamePatternToFindTypes"/> property value of <see cref="BuildingContext"/>.765 /// </summary>766 /// <param name="pattern">The pattern.</param>767 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>768 public AtataContextBuilder UseDefaultAssemblyNamePatternToFindTypes(string pattern)769 {770 pattern.CheckNotNullOrWhitespace(nameof(pattern));771772 BuildingContext.DefaultAssemblyNamePatternToFindTypes = pattern;773 return this;774 }775776 /// <summary>777 /// Sets the assembly name pattern that is used to filter assemblies to find component types in them.778 /// Modifies the <see cref="AtataBuildingContext.AssemblyNamePatternToFindComponentTypes"/> property value of <see cref="BuildingContext"/>.779 /// </summary>780 /// <param name="pattern">The pattern.</param>781 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>782 public AtataContextBuilder UseAssemblyNamePatternToFindComponentTypes(string pattern)783 {784 pattern.CheckNotNullOrWhitespace(nameof(pattern));785786 BuildingContext.AssemblyNamePatternToFindComponentTypes = pattern;787 return this;788 }789790 /// <summary>791 /// Sets the assembly name pattern that is used to filter assemblies to find attribute types in them.792 /// Modifies the <see cref="AtataBuildingContext.AssemblyNamePatternToFindAttributeTypes"/> property value of <see cref="BuildingContext"/>.793 /// </summary>794 /// <param name="pattern">The pattern.</param>795 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>796 public AtataContextBuilder UseAssemblyNamePatternToFindAttributeTypes(string pattern)797 {798 pattern.CheckNotNullOrWhitespace(nameof(pattern));799800 BuildingContext.AssemblyNamePatternToFindAttributeTypes = pattern;801 return this;802 }803804 /// <summary>805 /// Sets the assembly name pattern that is used to filter assemblies to find event types in them.806 /// Modifies the <see cref="AtataBuildingContext.AssemblyNamePatternToFindEventTypes"/> property value of <see cref="BuildingContext"/>.807 /// </summary>808 /// <param name="pattern">The pattern.</param>809 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>810 public AtataContextBuilder UseAssemblyNamePatternToFindEventTypes(string pattern)811 {812 pattern.CheckNotNullOrWhitespace(nameof(pattern));813814 BuildingContext.AssemblyNamePatternToFindEventTypes = pattern;815 return this;816 }817818 /// <summary>819 /// Sets the assembly name pattern that is used to filter assemblies to find event handler types in them.820 /// Modifies the <see cref="AtataBuildingContext.AssemblyNamePatternToFindEventHandlerTypes"/> property value of <see cref="BuildingContext"/>.821 /// </summary>822 /// <param name="pattern">The pattern.</param>823 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>824 public AtataContextBuilder UseAssemblyNamePatternToFindEventHandlerTypes(string pattern)825 {826 pattern.CheckNotNullOrWhitespace(nameof(pattern));827828 BuildingContext.AssemblyNamePatternToFindEventHandlerTypes = pattern;829 return this;830 }831832 /// <summary>833 /// Sets the path to the Artifacts directory.834 /// </summary>835 /// <param name="directoryPath">The directory path.</param>836 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>837 public AtataContextBuilder UseArtifactsPath(string directoryPath)838 {839 directoryPath.CheckNotNullOrWhitespace(nameof(directoryPath));840841 return UseArtifactsPath(_ => directoryPath);842 }843844 /// <summary>845 /// Sets the builder of the path to the Artifacts directory.846 /// </summary>847 /// <param name="directoryPathBuilder">The directory path builder.</param>848 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>849 public AtataContextBuilder UseArtifactsPath(Func<AtataContext, string> directoryPathBuilder)850 {851 directoryPathBuilder.CheckNotNull(nameof(directoryPathBuilder));852853 BuildingContext.ArtifactsPathBuilder = directoryPathBuilder;854 return this;855 }856857 /// <summary>858 /// Sets the default Artifacts path with optionally including <c>"{build-start:yyyyMMddTHHmmss}"</c> folder in the path.859 /// </summary>860 /// <param name="include">Whether to include the <c>"{build-start:yyyyMMddTHHmmss}"</c> folder in the path.</param>861 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>862 public AtataContextBuilder UseDefaultArtifactsPathIncludingBuildStart(bool include) =>863 UseArtifactsPath(include864 ? AtataBuildingContext.DefaultArtifactsPath865 : AtataBuildingContext.DefaultArtifactsPathWithoutBuildStartFolder);866867 /// <summary>868 /// Defines that the name of the test should be taken from the NUnit test.869 /// </summary>870 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>871 public AtataContextBuilder UseNUnitTestName()872 {873 return UseTestName(NUnitAdapter.GetCurrentTestName);874 }875876 /// <summary>877 /// Defines that the name of the test suite should be taken from the NUnit test fixture.878 /// </summary>879 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>880 public AtataContextBuilder UseNUnitTestSuiteName()881 {882 return UseTestSuiteName(NUnitAdapter.GetCurrentTestFixtureName);883 }884885 /// <summary>886 /// Defines that the type of the test suite should be taken from the NUnit test fixture.887 /// </summary>888 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>889 public AtataContextBuilder UseNUnitTestSuiteType()890 {891 return UseTestSuiteType(NUnitAdapter.GetCurrentTestFixtureType);892 }893894 /// <summary>895 /// Sets <see cref="NUnitAggregateAssertionStrategy"/> as the aggregate assertion strategy.896 /// The <see cref="NUnitAggregateAssertionStrategy"/> uses NUnit's <c>Assert.Multiple</c> method for aggregate assertion.897 /// </summary>898 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>899 public AtataContextBuilder UseNUnitAggregateAssertionStrategy()900 {901 return UseAggregateAssertionStrategy(new NUnitAggregateAssertionStrategy());902 }903904 /// <summary>905 /// Sets the aggregate assertion strategy.906 /// </summary>907 /// <typeparam name="TAggregateAssertionStrategy">The type of the aggregate assertion strategy.</typeparam>908 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>909 public AtataContextBuilder UseAggregateAssertionStrategy<TAggregateAssertionStrategy>()910 where TAggregateAssertionStrategy : IAggregateAssertionStrategy, new()911 {912 IAggregateAssertionStrategy strategy = Activator.CreateInstance<TAggregateAssertionStrategy>();913914 return UseAggregateAssertionStrategy(strategy);915 }916917 /// <summary>918 /// Sets the aggregate assertion strategy.919 /// </summary>920 /// <param name="strategy">The aggregate assertion strategy.</param>921 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>922 public AtataContextBuilder UseAggregateAssertionStrategy(IAggregateAssertionStrategy strategy)923 {924 BuildingContext.AggregateAssertionStrategy = strategy;925926 return this;927 }928929 /// <summary>930 /// Sets <see cref="NUnitWarningReportStrategy"/> as the strategy for warning assertion reporting.931 /// </summary>932 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>933 public AtataContextBuilder UseNUnitWarningReportStrategy()934 {935 return UseWarningReportStrategy(new NUnitWarningReportStrategy());936 }937938 /// <summary>939 /// Sets the strategy for warning assertion reporting.940 /// </summary>941 /// <param name="strategy">The warning report strategy.</param>942 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>943 public AtataContextBuilder UseWarningReportStrategy(IWarningReportStrategy strategy)944 {945 BuildingContext.WarningReportStrategy = strategy;946947 return this;948 }949950 /// <summary>951 /// Defines that an error occurred during the NUnit test execution should be added to the log during the cleanup.952 /// </summary>953 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>954 public AtataContextBuilder LogNUnitError() =>955 EventSubscriptions.Add(new LogNUnitErrorOnCleanUpEventHandler());956957 /// <summary>958 /// Defines that an error occurred during the NUnit test execution should be captured by a screenshot during the cleanup.959 /// </summary>960 /// <param name="title">The screenshot title.</param>961 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>962 public AtataContextBuilder TakeScreenshotOnNUnitError(string title = "Failed") =>963 EventSubscriptions.Add(new TakeScreenshotOnNUnitErrorOnCleanUpEventHandler(title));964965 /// <summary>966 /// Defines that on <see cref="AtataContext"/> clean-up the files stored in Artifacts directory967 /// should be added to NUnit <c>TestContext</c>.968 /// </summary>969 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>970 public AtataContextBuilder OnCleanUpAddArtifactsToNUnitTestContext() =>971 EventSubscriptions.Add(new AddArtifactsToNUnitTestContextOnCleanUpEventHandler());972973 /// <summary>974 /// Defines that on <see cref="AtataContext" /> clean-up the files stored in the directory975 /// specified by <paramref name="directoryPath"/> should be added to NUnit <c>TestContext</c>.976 /// Directory path supports template variables.977 /// </summary>978 /// <param name="directoryPath">The directory path.</param>979 /// <returns>The <see cref="AtataContextBuilder" /> instance.</returns>980 public AtataContextBuilder OnCleanUpAddDirectoryFilesToNUnitTestContext(string directoryPath)981 {982 directoryPath.CheckNotNull(nameof(directoryPath));983 return OnCleanUpAddDirectoryFilesToNUnitTestContext(_ => directoryPath);984 }985986 /// <inheritdoc cref="OnCleanUpAddDirectoryFilesToNUnitTestContext(Func{AtataContext, string})"/>987 public AtataContextBuilder OnCleanUpAddDirectoryFilesToNUnitTestContext(Func<string> directoryPathBuilder)988 {989 directoryPathBuilder.CheckNotNull(nameof(directoryPathBuilder));990 return OnCleanUpAddDirectoryFilesToNUnitTestContext(_ => directoryPathBuilder.Invoke());991 }992993 /// <summary>994 /// Defines that on <see cref="AtataContext" /> clean-up the files stored in the directory995 /// specified by <paramref name="directoryPathBuilder"/> should be added to NUnit <c>TestContext</c>.996 /// Directory path supports template variables.997 /// </summary>998 /// <param name="directoryPathBuilder">The directory path builder.</param>999 /// <returns>The <see cref="AtataContextBuilder" /> instance.</returns>1000 public AtataContextBuilder OnCleanUpAddDirectoryFilesToNUnitTestContext(Func<AtataContext, string> directoryPathBuilder)1001 {1002 directoryPathBuilder.CheckNotNull(nameof(directoryPathBuilder));1003 return EventSubscriptions.Add(1004 new AddDirectoryFilesToNUnitTestContextOnCleanUpEventHandler(directoryPathBuilder));1005 }10061007 /// <summary>1008 /// Sets the type of <c>NUnit.Framework.AssertionException</c> as the assertion exception type.1009 /// The default value is a type of <see cref="AssertionException"/>.1010 /// </summary>1011 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>1012 public AtataContextBuilder UseNUnitAssertionExceptionType() =>1013 UseAssertionExceptionType(NUnitAdapter.AssertionExceptionType);10141015 /// <summary>1016 /// Enables all NUnit features for Atata.1017 /// Executes the following methods:1018 /// <list type="bullet">1019 /// <item><see cref="UseNUnitTestName"/>,</item>1020 /// <item><see cref="UseNUnitTestSuiteName"/>,</item>1021 /// <item><see cref="UseNUnitTestSuiteType"/>,</item>1022 /// <item><see cref="UseNUnitAssertionExceptionType"/>,</item>1023 /// <item><see cref="UseNUnitAggregateAssertionStrategy"/>,</item>1024 /// <item><see cref="UseNUnitWarningReportStrategy"/>,</item>1025 /// <item><see cref="LogConsumersAtataContextBuilder.AddNUnitTestContext"/>,</item>1026 /// <item><see cref="LogNUnitError"/>,</item>1027 /// <item><see cref="TakeScreenshotOnNUnitError(string)"/>,</item>1028 /// <item><see cref="OnCleanUpAddArtifactsToNUnitTestContext"/>.</item>1029 /// </list>1030 /// </summary>1031 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>1032 public AtataContextBuilder UseAllNUnitFeatures() =>1033 UseNUnitTestName()1034 .UseNUnitTestSuiteName()1035 .UseNUnitTestSuiteType()1036 .UseNUnitAssertionExceptionType()1037 .UseNUnitAggregateAssertionStrategy()1038 .UseNUnitWarningReportStrategy()1039 .LogConsumers.AddNUnitTestContext()1040 .LogNUnitError()1041 .TakeScreenshotOnNUnitError()1042 .OnCleanUpAddArtifactsToNUnitTestContext();10431044 private DirectorySubject CreateArtifactsDirectorySubject(AtataContext context)1045 {1046 string pathTemplate = BuildingContext.ArtifactsPathBuilder.Invoke(context);10471048 string path = context.FillTemplateString(pathTemplate);10491050 return new DirectorySubject(path, "Artifacts");1051 }10521053 /// <summary>1054 /// Clears the <see cref="BuildingContext"/>.1055 /// </summary>1056 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>1057 public AtataContextBuilder Clear()1058 {1059 BuildingContext = new AtataBuildingContext();1060 return this;1061 }10621063 /// <summary>1064 /// Builds the <see cref="AtataContext" /> instance and sets it to <see cref="AtataContext.Current" /> property.1065 /// </summary>1066 /// <returns>The created <see cref="AtataContext"/> instance.</returns>1067 public AtataContext Build()1068 {1069 ValidateBuildingContextBeforeBuild();10701071 AtataContext context = new AtataContext();1072 LogManager logManager = CreateLogManager(context);10731074 IObjectConverter objectConverter = new ObjectConverter1075 {1076 AssemblyNamePatternToFindTypes = BuildingContext.DefaultAssemblyNamePatternToFindTypes1077 };10781079 IObjectMapper objectMapper = new ObjectMapper(objectConverter);1080 IObjectCreator objectCreator = new ObjectCreator(objectConverter, objectMapper);10811082 context.TestName = BuildingContext.TestNameFactory?.Invoke();1083 context.TestSuiteName = BuildingContext.TestSuiteNameFactory?.Invoke();1084 context.TestSuiteType = BuildingContext.TestSuiteTypeFactory?.Invoke();1085 context.TimeZone = BuildingContext.TimeZone;1086 context.BaseUrl = BuildingContext.BaseUrl;1087 context.Log = logManager;1088 context.Attributes = BuildingContext.Attributes.Clone();1089 context.BaseRetryTimeout = BuildingContext.BaseRetryTimeout;1090 context.BaseRetryInterval = BuildingContext.BaseRetryInterval;1091 context.ElementFindTimeout = BuildingContext.ElementFindTimeout;1092 context.ElementFindRetryInterval = BuildingContext.ElementFindRetryInterval;1093 context.WaitingTimeout = BuildingContext.WaitingTimeout;1094 context.WaitingRetryInterval = BuildingContext.WaitingRetryInterval;1095 context.VerificationTimeout = BuildingContext.VerificationTimeout;1096 context.VerificationRetryInterval = BuildingContext.VerificationRetryInterval;1097 context.DefaultControlVisibility = BuildingContext.DefaultControlVisibility;1098 context.Culture = BuildingContext.Culture ?? CultureInfo.CurrentCulture;1099 context.AssertionExceptionType = BuildingContext.AssertionExceptionType;1100 context.AggregateAssertionExceptionType = BuildingContext.AggregateAssertionExceptionType;1101 context.AggregateAssertionStrategy = BuildingContext.AggregateAssertionStrategy ?? new AtataAggregateAssertionStrategy();1102 context.WarningReportStrategy = BuildingContext.WarningReportStrategy ?? new AtataWarningReportStrategy();1103 context.ObjectConverter = objectConverter;1104 context.ObjectMapper = objectMapper;1105 context.ObjectCreator = objectCreator;1106 context.EventBus = new EventBus(context, BuildingContext.EventSubscriptions);11071108 if (context.TestSuiteName is null && context.TestSuiteType != null)1109 context.TestSuiteName = context.TestSuiteType.Name;11101111 context.DriverFactory = BuildingContext.DriverFactoryToUse1112 ?? BuildingContext.DriverFactories.LastOrDefault();1113 context.DriverAlias = context.DriverFactory?.Alias;1114 context.DriverInitializationStage = BuildingContext.DriverInitializationStage;1115
...
AtataContext.cs
Source:AtataContext.cs
...277 public CultureInfo Culture { get; internal set; }278279 /// <summary>280 /// Gets the type of the assertion exception.281 /// The default value is a type of <see cref="AssertionException"/>.282 /// </summary>283 public Type AssertionExceptionType { get; internal set; }284285 /// <summary>286 /// Gets the type of the aggregate assertion exception.287 /// The default value is a type of <see cref="AggregateAssertionException"/>.288 /// The exception type should have public constructor with <c>IEnumerable<AssertionResult></c> argument.289 /// </summary>290 public Type AggregateAssertionExceptionType { get; internal set; }291292 /// <summary>293 /// Gets the aggregate assertion strategy.294 /// The default value is an instance of <see cref="AtataAggregateAssertionStrategy"/>.295 /// </summary>296 public IAggregateAssertionStrategy AggregateAssertionStrategy { get; internal set; }297298 /// <summary>299 /// Gets the aggregate assertion depth level.300 /// </summary>301 public int AggregateAssertionLevel { get; internal set; }302303 /// <summary>304 /// Gets the strategy for warning assertion reporting.305 /// The default value is an instance of <see cref="AtataWarningReportStrategy"/>.306 /// </summary>307 public IWarningReportStrategy WarningReportStrategy { get; internal set; }308309 /// <summary>310 /// Gets the list of all assertion results.311 /// </summary>312 public List<AssertionResult> AssertionResults { get; } = new List<AssertionResult>();313314 /// <summary>315 /// Gets the list of pending assertion results with <see cref="AssertionStatus.Failed"/> or <see cref="AssertionStatus.Warning"/> status.316 /// </summary>317 public List<AssertionResult> PendingFailureAssertionResults { get; } = new List<AssertionResult>();318319 /// <summary>320 /// Gets the context of the attributes.321 /// </summary>322 public AtataAttributesContext Attributes { get; internal set; }323324 /// <summary>325 /// Gets the <see cref="DirectorySubject"/> of Artifacts directory.326 /// Artifacts directory can contain any files produced during test execution, logs, screenshots, downloads, etc.327 /// The default Artifacts directory path is <c>"{basedir}/artifacts/{build-start:yyyyMMddTHHmmss}{test-suite-name-sanitized:/*}{test-name-sanitized:/*}"</c>.328 /// </summary>329 public DirectorySubject Artifacts { get; internal set; }330331 /// <summary>332 /// Gets the <see cref="AtataNavigator"/> instance,333 /// which provides the navigation functionality between pages and windows.334 /// </summary>335 public AtataNavigator Go { get; }336337 /// <summary>338 /// Gets the current page object.339 /// </summary>340 public UIComponent PageObject { get; internal set; }341342 internal List<UIComponent> TemporarilyPreservedPageObjectList { get; private set; } = new List<UIComponent>();343344 internal bool IsNavigated { get; set; }345346 internal Stopwatch ExecutionStopwatch { get; } = Stopwatch.StartNew();347348 internal Stopwatch PureExecutionStopwatch { get; } = new Stopwatch();349350 public ReadOnlyCollection<UIComponent> TemporarilyPreservedPageObjects351 {352 get { return TemporarilyPreservedPageObjectList.ToReadOnly(); }353 }354355 /// <summary>356 /// Gets the UI component access chain scope cache.357 /// </summary>358 public UIComponentAccessChainScopeCache UIComponentAccessChainScopeCache { get; } = new UIComponentAccessChainScopeCache();359360 /// <summary>361 /// Gets the object creator.362 /// </summary>363 public IObjectCreator ObjectCreator { get; internal set; }364365 /// <summary>366 /// Gets the object converter.367 /// </summary>368 public IObjectConverter ObjectConverter { get; internal set; }369370 /// <summary>371 /// Gets the object mapper.372 /// </summary>373 public IObjectMapper ObjectMapper { get; internal set; }374375 /// <summary>376 /// Gets the event bus, which can used to subscribe to and publish events.377 /// </summary>378 public IEventBus EventBus { get; internal set; }379380 /// <summary>381 /// Gets the variables dictionary.382 /// <para>383 /// The list of predefined variables:384 /// <list type="bullet">385 /// <item><c>build-start</c></item>386 /// <item><c>build-start-utc</c></item>387 /// <item><c>basedir</c></item>388 /// <item><c>artifacts</c></item>389 /// <item><c>test-name-sanitized</c></item>390 /// <item><c>test-name</c></item>391 /// <item><c>test-suite-name-sanitized</c></item>392 /// <item><c>test-suite-name</c></item>393 /// <item><c>test-start</c></item>394 /// <item><c>test-start-utc</c></item>395 /// <item><c>driver-alias</c></item>396 /// </list>397 /// </para>398 /// <para>399 /// Custom variables can be added as well.400 /// </para>401 /// </summary>402 public IDictionary<string, object> Variables { get; } = new Dictionary<string, object>();403404 /// <summary>405 /// Creates <see cref="AtataContextBuilder"/> instance for <see cref="AtataContext"/> configuration.406 /// Sets the value to <see cref="AtataContextBuilder.BuildingContext"/> copied from <see cref="GlobalConfiguration"/>.407 /// </summary>408 /// <returns>The created <see cref="AtataContextBuilder"/> instance.</returns>409 public static AtataContextBuilder Configure()410 {411 AtataBuildingContext buildingContext = GlobalConfiguration.BuildingContext.Clone();412 return new AtataContextBuilder(buildingContext);413 }414415 internal void InitDateTimeProperties()416 {417 StartedAtUtc = DateTime.UtcNow;418 StartedAt = TimeZoneInfo.ConvertTimeFromUtc(StartedAtUtc, TimeZone);419420 if (BuildStartUtc is null)421 {422 lock (s_buildStartSyncLock)423 {424 if (BuildStartUtc is null)425 {426 BuildStartUtc = StartedAtUtc;427 BuildStart = BuildStartUtc.Value.ToLocalTime();428 }429 }430 }431432 BuildStartInTimeZone = TimeZoneInfo.ConvertTimeFromUtc(BuildStartUtc.Value, TimeZone);433 }434435 internal void InitMainVariables()436 {437 var variables = Variables;438439 variables["build-start"] = BuildStartInTimeZone;440 variables["build-start-utc"] = BuildStartUtc;441442 variables["basedir"] = AppDomain.CurrentDomain.BaseDirectory;443444 variables["test-name-sanitized"] = TestNameSanitized;445 variables["test-name"] = TestName;446 variables["test-suite-name-sanitized"] = TestSuiteNameSanitized;447 variables["test-suite-name"] = TestSuiteName;448 variables["test-start"] = StartedAt;449 variables["test-start-utc"] = StartedAtUtc;450451 variables["driver-alias"] = DriverAlias;452 }453454 internal void InitCustomVariables(IDictionary<string, object> customVariables)455 {456 var variables = Variables;457458 foreach (var variable in customVariables)459 variables[variable.Key] = variable.Value;460 }461462 internal void InitArtifactsVariable() =>463 Variables["artifacts"] = Artifacts.FullName.Value;464465 internal void LogTestStart()466 {467 StringBuilder logMessageBuilder = new StringBuilder(468 $"Starting {GetTestUnitKindName()}");469470 string[] testFullNameParts = GetTestFullNameParts().ToArray();471472 if (testFullNameParts.Length > 0)473 {474 logMessageBuilder.Append(": ")475 .Append(string.Join(".", testFullNameParts));476 }477478 Log.Info(logMessageBuilder.ToString());479 }480481 private IEnumerable<string> GetTestFullNameParts()482 {483 if (TestSuiteType != null)484 yield return TestSuiteType.Namespace;485486 if (TestSuiteName != null)487 yield return TestSuiteName;488489 if (TestName != null)490 yield return TestName;491 }492493 private string GetTestUnitKindName()494 {495 return TestName != null496 ? "test"497 : TestSuiteType != null498 ? "test suite"499 : "test unit";500 }501502 /// <summary>503 /// Executes aggregate assertion using <see cref="AggregateAssertionStrategy" />.504 /// </summary>505 /// <param name="action">The action to execute in scope of aggregate assertion.</param>506 /// <param name="assertionScopeName">507 /// Name of the scope being asserted (page object, control, etc.).508 /// Is used to identify the assertion section in log.509 /// Can be null.510 /// </param>511 public void AggregateAssert(Action action, string assertionScopeName = null)512 {513 action.CheckNotNull(nameof(action));514515 AggregateAssertionStrategy.Assert(() =>516 {517 AggregateAssertionLevel++;518519 try520 {521 Log.ExecuteSection(522 new AggregateAssertionLogSection(assertionScopeName),523 action);524 }525 finally526 {527 AggregateAssertionLevel--;528 }529 });530 }531532 /// <summary>533 /// Cleans up the test context.534 /// </summary>535 /// <param name="quitDriver">if set to <see langword="true"/> quits WebDriver.</param>536 public void CleanUp(bool quitDriver = true)537 {538 if (_disposed)539 return;540541 PureExecutionStopwatch.Stop();542543 Log.ExecuteSection(544 new LogSection("Clean up AtataContext", LogLevel.Trace),545 () =>546 {547 EventBus.Publish(new AtataContextCleanUpEvent(this));548549 CleanUpTemporarilyPreservedPageObjectList();550551 if (PageObject != null)552 UIComponentResolver.CleanUpPageObject(PageObject);553554 UIComponentAccessChainScopeCache.Release();555556 if (quitDriver)557 _driver?.Dispose();558 });559560 ExecutionStopwatch.Stop();561562 string testUnitKindName = GetTestUnitKindName();563 Log.InfoWithExecutionTimeInBrackets($"Finished {testUnitKindName}", ExecutionStopwatch.Elapsed);564 Log.InfoWithExecutionTime($"Pure {testUnitKindName} execution time:", PureExecutionStopwatch.Elapsed);565566 Log = null;567568 if (Current == this)569 Current = null;570571 _disposed = true;572573 AssertionResults.Clear();574575 if (PendingFailureAssertionResults.Any())576 {577 var copyOfPendingFailureAssertionResults = PendingFailureAssertionResults.ToArray();578 PendingFailureAssertionResults.Clear();579580 throw VerificationUtils.CreateAggregateAssertionException(copyOfPendingFailureAssertionResults);581 }582 }583584 internal void InitDriver()585 {586 if (DriverFactory is null)587 throw new InvalidOperationException(588 $"Failed to create an instance of {typeof(IWebDriver).FullName} as driver factory is not specified.");589590 _driver = DriverFactory.Create()591 ?? throw new InvalidOperationException(592 $"Failed to create an instance of {typeof(IWebDriver).FullName} as driver factory returned null as a driver.");593594 _driver.Manage().Timeouts().SetRetryTimeout(ElementFindTimeout, ElementFindRetryInterval);
...
AtataAggregateAssertionStrategy.cs
Source:AtataAggregateAssertionStrategy.cs
...5{6 /// <summary>7 /// Represents native/default Atata aggregate assertion strategy.8 /// </summary>9 public class AtataAggregateAssertionStrategy : IAggregateAssertionStrategy10 {11 public void Assert(Action action)12 {13 AtataContext context = AtataContext.Current;14 IEnumerable<AssertionResult> assertionResultsBefore = AtataContext.Current.PendingFailureAssertionResults.ToArray();15 try16 {17 action();18 }19 catch (Exception exception)20 {21 var failedResults = ExtractAndRemoveExclusiveFailedAssertionResults(assertionResultsBefore).22 Concat(new[] { AssertionResult.ForException(exception) });23 throw VerificationUtils.CreateAggregateAssertionException(failedResults);24 }25 if (context.AggregateAssertionLevel == 0)26 {27 var failedResults = ExtractAndRemoveExclusiveFailedAssertionResults(assertionResultsBefore);28 if (failedResults.Any())29 throw VerificationUtils.CreateAggregateAssertionException(failedResults);30 }31 }32 private static IEnumerable<AssertionResult> ExtractAndRemoveExclusiveFailedAssertionResults(IEnumerable<AssertionResult> assertionResultsBefore)33 {34 var allAssertionResults = AtataContext.Current.PendingFailureAssertionResults;35 IEnumerable<AssertionResult> exclusiveAssertions = allAssertionResults.36 Where(x => !assertionResultsBefore.Contains(x)).37 Where(x => x.Status == AssertionStatus.Failed || x.Status == AssertionStatus.Warning).38 ToArray();39 if (exclusiveAssertions.Any())40 allAssertionResults.RemoveAll(x => exclusiveAssertions.Contains(x));41 return exclusiveAssertions;42 }43 public void ReportFailure(string message, string stackTrace)44 {45 AtataContext.Current.PendingFailureAssertionResults.Add(AssertionResult.ForFailure(message, stackTrace));46 }47 }48}...
Assert
Using AI Code Generation
1using NUnit.Framework;2using OpenQA.Selenium;3using OpenQA.Selenium.Chrome;4using OpenQA.Selenium.Support.UI;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10using Atata;11using NUnit.Framework;12using OpenQA.Selenium;13using OpenQA.Selenium.Chrome;14using OpenQA.Selenium.Support.UI;15using System;16using System.Collections.Generic;17using System.Linq;18using System.Text;19using System.Threading.Tasks;20using Atata;21{22 {23 public void Test()24 {25 Build();26 Go.To<GooglePage>();27 AtataContext.Current.LogScreenshot();28 AtataContext.Current.LogInfo("Test");29 Assert.Multiple(() =>30 {31 Assert.That(AtataContext.Current.PageTitle, Is.EqualTo("Google"));32 });33 }34 }35}36using NUnit.Framework;37using OpenQA.Selenium;38using OpenQA.Selenium.Chrome;39using OpenQA.Selenium.Support.UI;40using System;41using System.Collections.Generic;42using System.Linq;43using System.Text;44using System.Threading.Tasks;45using Atata;46using NUnit.Framework;47using OpenQA.Selenium;48using OpenQA.Selenium.Chrome;49using OpenQA.Selenium.Support.UI;50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55using Atata;56{57 {58 public void Test()59 {60 Build();61 Go.To<GooglePage>();
Assert
Using AI Code Generation
1using Atata;2using NUnit.Framework;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 public void _2()11 {12 Go.To<HomePage>()13 .Features.Click()14 .AssertThat(x => x15 .PageTitle.Should.Equal("Features | Atata")16 .PageSource.Should.Contain("Features")17 .PageSource.Should.Contain("Atata")18 .PageSource.Should.Contain("Automated Testing")19 .PageSource.Should.Contain("UI Testing")20 .PageSource.Should.Contain("UI Automation")21 .PageSource.Should.Contain("Test Automation")22 .PageSource.Should.Contain("Selenium")23 .PageSource.Should.Contain("NUnit")24 .PageSource.Should.Contain("xUnit")25 .PageSource.Should.Contain("SpecFlow")26 .PageSource.Should.Contain("MSTest")27 .PageSource.Should.Contain("MsTest")28 .PageSource.Should.Contain("Visual Studio")29 .PageSource.Should.Contain("Visual Studio 2019")30 .PageSource.Should.Contain("Visual Studio 2017")31 .PageSource.Should.Contain("Visual Studio 2015")32 .PageSource.Should.Contain("Visual Studio 2013")33 .PageSource.Should.Contain("Visual Studio 2012")34 .PageSource.Should.Contain("Visual Studio 2010")35 .PageSource.Should.Contain("Visual Studio 2008")36 .PageSource.Should.Contain("Visual Studio 2005")37 .PageSource.Should.Contain("Visual Studio 2003")38 .PageSource.Should.Contain("Visual Studio 2002")39 .PageSource.Should.Contain("Visual Studio 2000")40 .PageSource.Should.Contain("Visual Studio 6.0")41 .PageSource.Should.Contain("Visual Studio .NET")42 .PageSource.Should.Contain("Visual Studio .NET 2003")43 .PageSource.Should.Contain("Visual Studio .NET 2002")44 .PageSource.Should.Contain("Visual Studio .NET 2000")45 .PageSource.Should.Contain("Visual Studio .NET 98")46 .PageSource.Should.Contain("Visual Studio .NET 97")
Assert
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void Test1()6 {7 AtataContext.Configure()8 .UseChrome()9 .UseNUnit()10 .UseAssertionStrategy(new AtataAggregateAssertionStrategy())11 .Build();12 Go.To<GooglePage>();13 Assert.That(AtataContext.Current.Log.All, Has.Count.EqualTo(3));14 }15 }16}17using Atata;18{19 using _ = GooglePage;20 {21 [FindById("lst-ib")]22 public TextInput<_> Search { get; set; }23 [FindById("hplogo")]24 public Control<_> Logo { get; set; }25 [FindByClass("gb_P")]26 public Control<_> Gmail { get; set; }27 }28}29using Atata;30{31 using _ = GooglePage;32 {33 [FindById("lst-ib")]34 public TextInput<_> Search { get; set; }35 [FindById("hplogo")]36 public Control<_> Logo { get; set; }37 [FindByClass("gb_P")]38 public Control<_> Gmail { get; set; }39 }40}41I have tried to use AtataContext.Current.Log.All.Count() and it is returning 0
Assert
Using AI Code Generation
1public void TestMethod1()2{3 var page = Go.To<Page1>();4 AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();5 AtataContext.Current.AggregateAssertionStrategy.Assert(() =>6 {7 page.AssertThat(x => x.Title.Should.Equal("Page 1"));8 page.AssertThat(x => x.Title.Should.Equal("Page 2"));9 });10}11public void TestMethod1()12{13 var page = Go.To<Page1>();14 AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();15 AtataContext.Current.AggregateAssertionStrategy.AssertAll(() =>16 {17 page.AssertThat(x => x.Title.Should.Equal("Page 1"));18 page.AssertThat(x => x.Title.Should.Equal("Page 2"));19 });20}21public void TestMethod1()22{23 var page = Go.To<Page1>();24 AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();25 AtataContext.Current.AggregateAssertionStrategy.AssertAll(() =>26 {27 page.AssertThat(x => x.Title.Should.Equal("Page 1"));28 page.AssertThat(x => x.Title.Should.Equal("Page 2"));29 });30}31public void TestMethod1()32{33 var page = Go.To<Page1>();34 AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();35 AtataContext.Current.AggregateAssertionStrategy.AssertAll(() =>36 {37 page.AssertThat(x => x.Title.Should.Equal("Page 1"));38 page.AssertThat(x => x.Title.Should.Equal("Page 2"));39 });40}41public void TestMethod1()42{43 var page = Go.To<Page1>();44 AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();45 AtataContext.Current.AggregateAssertionStrategy.AssertAll(() =>46 {47 page.AssertThat(x => x.Title.Should.Equal("
Assert
Using AI Code Generation
1AtataContext.Current.AggregateAssertionStrategy = new AtataAggregateAssertionStrategy();2AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(1, Is.EqualTo(2)));3AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(2, Is.EqualTo(2)));4AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(3, Is.EqualTo(3)));5AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(4, Is.EqualTo(4)));6AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(5, Is.EqualTo(5)));7AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(6, Is.EqualTo(6)));8AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(7, Is.EqualTo(7)));9AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(8, Is.EqualTo(8)));10AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(9, Is.EqualTo(9)));11AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(10, Is.EqualTo(10)));12AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(11, Is.EqualTo(11)));13AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(12, Is.EqualTo(12)));14AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(13, Is.EqualTo(13)));15AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(14, Is.EqualTo(14)));16AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(15, Is.EqualTo(15)));17AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(16, Is.EqualTo(16)));18AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(17, Is.EqualTo(17)));19AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(18, Is.EqualTo(18)));20AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(19, Is.EqualTo(19)));21AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(20, Is.EqualTo(20)));22AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(21, Is.EqualTo(21)));23AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(22, Is.EqualTo(22)));24AtataContext.Current.AggregateAssertionStrategy.Assert(() => Assert.That(23, Is.EqualTo(23
Assert
Using AI Code Generation
1AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy());2AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy().Add(new AtataAssertionStrategy()));3AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy().Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()));4AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy().Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()));5AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy().Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()));6AtataContext.GlobalConfiguration.UseAssertionStrategy(new AtataAggregateAssertionStrategy().Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()).Add(new AtataAssertionStrategy()));
Assert
Using AI Code Generation
1using System;2using NUnit.Framework;3using OpenQA.Selenium;4using OpenQA.Selenium.Chrome;5using Atata;6{7 {8 public void Test()9 {10 Go.To<HomePage>().Assert(x => x.Header.Should.Contain("Welcome"));11 }12 }13}14using System;15using NUnit.Framework;16using OpenQA.Selenium;17using OpenQA.Selenium.Chrome;18using Atata;19{20 {21 public void Test()22 {23 Go.To<HomePage>().Assert(x => x.Header.Should.Contain("Welcome"));24 }25 }26}27using System;28using NUnit.Framework;29using OpenQA.Selenium;30using OpenQA.Selenium.Chrome;31using Atata;32{33 {34 public void Test()35 {36 Go.To<HomePage>().Assert(x => x.Header.Should.Contain("Welcome"));37 }38 }39}
Assert
Using AI Code Generation
1AtataContext.Current.BuildingBlock<AtataAggregateAssertionStrategy>().Assert(2 () => AtataContext.Current.PageObject.Should.Exist(),3 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),4 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));5AtataContext.Current.BuildingBlock<AtataAssertionStrategy>().Assert(6 () => AtataContext.Current.PageObject.Should.Exist(),7 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),8 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));9AtataContext.Current.BuildingBlock<AtataBuildLogAssertionStrategy>().Assert(10 () => AtataContext.Current.PageObject.Should.Exist(),11 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),12 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));13AtataContext.Current.BuildingBlock<AtataVerificationStrategy>().Assert(14 () => AtataContext.Current.PageObject.Should.Exist(),15 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),16 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));17AtataContext.Current.BuildingBlock<AtataVerificationLogAssertionStrategy>().Assert(18 () => AtataContext.Current.PageObject.Should.Exist(),19 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),20 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));21AtataContext.Current.BuildingBlock<AtataVerificationResultAssertionStrategy>().Assert(22 () => AtataContext.Current.PageObject.Should.Exist(),23 () => AtataContext.Current.PageObject.Should.HaveTitle("Page Title"),24 () => AtataContext.Current.PageObject.Should.HaveContent("Page Content"));25AtataContext.Current.BuildingBlock<AtataVerificationResultLogAssertionStrategy>().Assert(26 ()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!