/// <summary> /// Verifies that collection contains a single item matching <paramref name="predicateExpression"/>. /// </summary> /// <typeparam name="TItem">The type of the collection item.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="predicateExpression">The predicate expression.</param> /// <returns>The owner instance.</returns> public static TOwner ContainSingle <TItem, TOwner>(this IDataVerificationProvider <IEnumerable <TItem>, TOwner> should, Expression <Func <TItem, bool> > predicateExpression) { var predicate = predicateExpression.CheckNotNull(nameof(predicateExpression)).Compile(); return(should.Satisfy( actual => actual != null && actual.Count(predicate) == 1, $"contain single {Stringifier.ToString(predicateExpression)}")); }
public static TOwner EqualSequence <TData, TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, IEnumerable <TData> expected) { expected.CheckNotNullOrEmpty(nameof(expected)); return(should.Satisfy( actual => actual != null && actual.SequenceEqual(expected), $"equal sequence {Stringifier.ToString(expected)}")); }
/// <summary> /// Switches to frame represented by <paramref name="element"/> parameter. /// </summary> /// <param name="element">The frame element.</param> /// <returns>The instance of this page object.</returns> public TOwner SwitchToFrame(IWebElement element) { Log.ExecuteSection( new LogSection($"Switch to frame of {Stringifier.ToString(element).ToLowerFirstLetter()}", LogLevel.Trace), (Action)(() => Driver.SwitchTo().Frame(element))); return((TOwner)this); }
public static TOwner BeEquivalent <TData, TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, IEnumerable <TData> expected) { expected.CheckNotNullOrEmpty(nameof(expected)); return(should.Satisfy( actual => actual != null && actual.Count() == expected.Count() && actual.All(expected.Contains), $"be equivalent to {Stringifier.ToString(expected)}")); }
/// <summary> /// Verifies that collection contains at least one item matching <paramref name="predicateExpression"/>. /// </summary> /// <typeparam name="TObject">The type of the collection item object.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="predicateExpression">The predicate expression.</param> /// <returns>The owner instance.</returns> public static TOwner Contain <TObject, TOwner>(this IDataVerificationProvider <IEnumerable <IObjectProvider <TObject> >, TOwner> should, Expression <Func <TObject, bool> > predicateExpression) { var predicate = predicateExpression.CheckNotNull(nameof(predicateExpression)).Compile(); return(should.Satisfy( actual => actual != null && actual.Any(predicate), $"contain {Stringifier.ToString(predicateExpression)}")); }
/// <summary> /// Verifies that collection contains exact count of items equal to <paramref name="expectedValue"/> parameter. /// </summary> /// <typeparam name="TData">The type of the collection item data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="expectedCount">The expected count of items.</param> /// <param name="expectedValue">An expected data value.</param> /// <returns>The owner instance.</returns> public static TOwner ContainExactly <TData, TOwner>( this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, int expectedCount, TData expectedValue) { return(should.Satisfy( actual => actual != null && actual.Count((TData x) => Equals(x, expectedValue)) == expectedCount, $"contain exactly {expectedCount} {Stringifier.ToString(expectedValue)} items")); }
public static TOwner Satisfy <TData, TOwner>(this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args) { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); void ExecuteVerification() { TData actual = default; Exception exception = null; bool doesSatisfy = ExecuteUntil( () => { try { actual = should.DataProvider.Value; bool result = predicate(actual) != should.IsNegation; exception = null; return(result); } catch (Exception e) { exception = e; return(false); } }, should.GetRetryOptions()); if (!doesSatisfy) { string expectedMessage = VerificationUtils.BuildExpectedMessage(message, args?.Cast <object>().ToArray()); string actualMessage = exception == null?Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage); should.ReportFailure(failureMessage, exception); } } if (AtataContext.Current is null) { ExecuteVerification(); } else { string verificationConstraintMessage = VerificationUtils.BuildConstraintMessage(should, message, args); LogSection logSection = should.DataProvider.Component is null ? (LogSection) new ValueVerificationLogSection(should.VerificationKind, should.DataProvider.ProviderName, verificationConstraintMessage) : new VerificationLogSection(should.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage); AtataContext.Current.Log.ExecuteSection(logSection, ExecuteVerification); } return(should.Owner); }
/// <summary> /// Verifies that collection contains items equal to expected values. /// </summary> /// <typeparam name="TData">The type of the collection item data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="expected">An expected data values.</param> /// <returns>The owner instance.</returns> public static TOwner Contain <TData, TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, IEnumerable <TData> expected) { expected.CheckNotNullOrEmpty(nameof(expected)); return(should.Satisfy( actual => actual != null && should.IsNegation ? actual.Intersect(expected).Any() : actual.Intersect(expected).Count() == expected.Count(), $"contain {Stringifier.ToString(expected)}")); }
/// <summary> /// Verifies that collection contains exact count of items equal to <paramref name="expectedValue"/> parameter. /// </summary> /// <typeparam name="TItem">The type of the collection item.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="expectedCount">The expected count of items.</param> /// <param name="expectedValue">An expected item value.</param> /// <returns>The owner instance.</returns> public static TOwner ContainExactly <TItem, TOwner>( this IDataVerificationProvider <IEnumerable <TItem>, TOwner> should, int expectedCount, TItem expectedValue) where TOwner : PageObject <TOwner> { return(should.Satisfy( actual => actual != null && actual.Count(x => Equals(x, expectedValue)) == expectedCount, $"contain exactly {expectedCount} {Stringifier.ToString(expectedValue)} items")); }
private static string AppendSectionResultToMessage(string message, object result) { string resultAsString = result is Exception resultAsException ? $"{resultAsException.GetType().FullName}: {resultAsException.Message}" : Stringifier.ToString(result); string separator = resultAsString.Contains(Environment.NewLine) ? Environment.NewLine : " "; return($"{message} >>{separator}{resultAsString}"); }
/// <summary> /// Verifies that collection contains exact count of items matching <paramref name="predicateExpression"/>. /// </summary> /// <typeparam name="TItem">The type of the collection item.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="expectedCount">The expected count of items.</param> /// <param name="predicateExpression">The predicate expression.</param> /// <returns>The owner instance.</returns> public static TOwner ContainExactly <TItem, TOwner>( this IDataVerificationProvider <IEnumerable <TItem>, TOwner> should, int expectedCount, Expression <Func <TItem, bool> > predicateExpression) { expectedCount.CheckGreaterOrEqual(nameof(expectedCount), 0); var predicate = predicateExpression.CheckNotNull(nameof(predicateExpression)).Compile(); return(should.Satisfy( actual => actual != null && actual.Count(predicate) == expectedCount, $"contain exactly {expectedCount} {Stringifier.ToString(predicateExpression)} items")); }
/// <summary> /// Clears the column header texts of the component. /// </summary> /// <returns>The instance of the owner page object.</returns> public TOwner ClearValueCache() { if (HasCachedValue) { var cachedValue = CachedValue; CachedValue = default; HasCachedValue = false; Log.Trace($"Cleared value cache of {ComponentFullName}: {Stringifier.ToString(cachedValue)}"); } return(Owner); }
/// <inheritdoc/> public TOwner ClearScopeCache() { var cachedScope = CachedScope; if (cachedScope != null) { CachedScope = null; Log.Trace($"Cleared scope cache of {ComponentFullName}: {Stringifier.ToString(cachedScope)}"); } return(Owner); }
private static string AppendSectionResultToMessage(string message, object result) { string resultAsString = result is Exception resultAsException ? BuildExceptionShortSingleLineMessage(resultAsException) : Stringifier.ToString(result); string separator = resultAsString.Contains(Environment.NewLine) ? Environment.NewLine : " "; return($"{message} >>{separator}{resultAsString}"); }
public static TOwner Satisfy <TData, TOwner>( this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, Predicate <IEnumerable <TData> > predicate, string message, params TData[] args) where TOwner : PageObject <TOwner> { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); string expectedMessage = (args != null && args.Any()) ? message?.FormatWith(Stringifier.ToString(args)) : message; string verificationConstraintMessage = $"{should.GetShouldText()} {expectedMessage}"; AtataContext.Current.Log.ExecuteSection( new VerificationLogSection(should.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage), () => { IEnumerable <TData> actual = null; Exception exception = null; bool doesSatisfy = AtataContext.Current.Driver.Try().Until( _ => { try { actual = should.DataProvider.Value?.Select(x => x.Value).ToArray(); bool result = predicate(actual) != should.IsNegation; exception = null; return(result); } catch (Exception e) { exception = e; return(false); } }, should.GetRetryOptions()); if (!doesSatisfy) { string actualMessage = exception == null ? Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage); should.ReportFailure(failureMessage, exception); } }); return(should.Owner); }
/// <summary> /// Verifies that object satisfies the specified predicate. /// </summary> /// <typeparam name="TData">The type of the data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The verification provider.</param> /// <param name="predicate">The predicate.</param> /// <param name="message">The message that should sound in a way of "{Something} should {message}".</param> /// <param name="args">The message arguments.</param> /// <returns>The owner instance.</returns> /// TODO: Atata v2. Change type of predicate from "Predicate" to "Func". public static TOwner Satisfy <TData, TOwner>( this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args) { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); void ExecuteVerification() { TData actual = default; Exception exception = null; bool doesSatisfy = VerificationUtils.ExecuteUntil( () => { try { actual = should.DataProvider.Value; bool result = predicate(actual) != should.IsNegation; exception = null; return(result); } catch (Exception e) { exception = e; return(false); } }, should.GetRetryOptions()); if (!doesSatisfy) { string shortenExpectedMessage = null; bool isExpectedMessageShorten = !should.IsNegation && TryShortenExpectedMessage(message, out shortenExpectedMessage); string expectedMessage = VerificationUtils.BuildExpectedMessage( isExpectedMessageShorten ? shortenExpectedMessage : message, args?.Cast <object>().ToArray()); string actualMessage = exception == null?Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage, !isExpectedMessageShorten); should.ReportFailure(failureMessage, exception); } } return(VerificationUtils.Verify(should, ExecuteVerification, message, args)); }
/// <summary> /// Verifies that collection satisfies the specified predicate. /// </summary> /// <typeparam name="TData">The type of the data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The verification provider.</param> /// <param name="predicate">The predicate.</param> /// <param name="message">The message that should sound in a way of "{Something} should {message}".</param> /// <param name="args">The message arguments.</param> /// <returns>The owner instance.</returns> public static TOwner Satisfy <TData, TOwner>( this IDataVerificationProvider <IEnumerable <IObjectProvider <TData> >, TOwner> should, Predicate <IEnumerable <TData> > predicate, string message, params TData[] args) { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); string expectedMessage = (args != null && args.Any()) ? message?.FormatWith(Stringifier.ToString(args)) : message; void ExecuteVerification() { IEnumerable <TData> actual = null; Exception exception = null; bool doesSatisfy = VerificationUtils.ExecuteUntil( () => { try { actual = should.DataProvider.Value?.Select(x => x.Value).ToArray(); bool result = predicate(actual) != should.IsNegation; exception = null; return(result); } catch (Exception e) { exception = e; return(false); } }, should.GetRetryOptions()); if (!doesSatisfy) { string actualMessage = exception == null?Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage); should.ReportFailure(failureMessage, exception); } } return(VerificationUtils.Verify(should, ExecuteVerification, expectedMessage)); }
private static string BuildLogMessageForScript(string script, object[] args) { IEnumerable <string> scriptLines = script .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()); string scriptTruncated = string.Join(" ", scriptLines) .Truncate(ScriptMaxLength); StringBuilder builder = new StringBuilder($@"""{scriptTruncated}"""); if (args != null && args.Length > 0) { builder.Append($" with argument{(args.Length > 1 ? "s" : null)}: {Stringifier.ToString(args)}"); } return(builder.ToString()); }
[Obsolete("Use Stringifier.ToString(...) instead.")] // Obsolete since v1.9.0. public static string ToString(object value) { return(Stringifier.ToString(value)); }
public static string BuildExpectedMessage(string message, object[] args) { return(args != null && args.Any() ? message.FormatWith(args.Select(x => Stringifier.ToString(x)).ToArray()) : message); }
[Obsolete("Use Stringifier.ToString(...) instead.")] // Obsolete since v1.9.0. public static string ToString <T>(Expression <Func <T, bool> > predicateExpression) { return(Stringifier.ToString(predicateExpression)); }
[Obsolete("Use Stringifier.ToString(...) instead.")] // Obsolete since v1.9.0. public static string ToString(Expression expression) { return(Stringifier.ToString(expression)); }
public ElementSendKeysLogSection(IWebElement element, string text) { Message = $"Send keys \"{SpecialKeys.Replace(text)}\" to {Stringifier.ToString(element).ToLowerFirstLetter()}"; Level = LogLevel.Trace; }
[Obsolete("Use Stringifier.ToString(...) instead.")] // Obsolete since v1.9.0. public static string ToString <T>(IEnumerable <T> collection) { return(Stringifier.ToString(collection)); }
/// <summary> /// Verifies that collection contains a single item equal to <paramref name="expected"/> parameter. /// </summary> /// <typeparam name="TData">The type of the collection item data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="should">The should instance.</param> /// <param name="expected">An expected data value.</param> /// <returns>The owner instance.</returns> public static TOwner ContainSingle <TData, TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, TData expected) { return(should.Satisfy( actual => actual != null && actual.Count((TData x) => Equals(x, expected)) == 1, $"contain single {Stringifier.ToString(expected)}")); }
public static TOwner Contain <TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <string, TOwner> >, TOwner> should, TermMatch match, IEnumerable <string> expected) where TOwner : PageObject <TOwner> { expected.CheckNotNullOrEmpty(nameof(expected)); return(should.Satisfy( actual => actual != null && should.IsNegation ? expected.Any(expectedValue => actual.Any(actualValue => match.IsMatch(actualValue, expectedValue))) : expected.All(expectedValue => actual.Any(actualValue => match.IsMatch(actualValue, expectedValue))), $"contain having value that {match.ToString(TermCase.MidSentence)} {Stringifier.ToString(expected)}")); }
public ElementClearLogSection(IWebElement element) { Message = $"Clear {Stringifier.ToString(element).ToLowerFirstLetter()}"; Level = LogLevel.Trace; }
private static string ResolveSearchContextName(ISearchContext searchContext) { return(searchContext is IWebDriver ? searchContext.GetType().Name : Stringifier.ToString(searchContext)); }
public static TOwner ContainHavingContent <TControl, TOwner>(this IDataVerificationProvider <IEnumerable <TControl>, TOwner> should, TermMatch match, IEnumerable <string> expected) where TControl : Control <TOwner> where TOwner : PageObject <TOwner> { expected.CheckNotNullOrEmpty(nameof(expected)); return(should.Satisfy( actual => { if (actual == null) { return false; } var actualValues = actual.Select(x => x.Content.Value).ToArray(); return should.IsNegation ? expected.Any(expectedValue => actualValues.Any(actualValue => match.IsMatch(actualValue, expectedValue))) : expected.All(expectedValue => actualValues.Any(actualValue => match.IsMatch(actualValue, expectedValue))); }, $"contain having content that {match.ToString(TermCase.MidSentence)} {Stringifier.ToString(expected)}")); }