/// <summary> /// Selects the specified data (property) set of each control. /// Data can be a sub-control, an instance of <see cref="DataProvider{TData, TOwner}"/>, etc. /// </summary> /// <typeparam name="TData">The type of the data.</typeparam> /// <param name="selector">The data selector.</param> /// <returns>An instance of <see cref="DataProvider{TData, TOwner}"/>.</returns> public DataProvider <IEnumerable <TData>, TOwner> SelectData <TData>(Expression <Func <TItem, TData> > selector) { string dataPathName = ObjectExpressionStringBuilder.ExpressionToString(selector); return(Component.GetOrCreateDataProvider( $"\"{dataPathName}\" {ProviderName}", () => GetAll().Select(selector.Compile()))); }
/// <summary> /// Creates a new dynamic <see cref="Subject{TResult}"/> from the result of the specified <paramref name="functionExpression"/>. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="functionExpression">The function expression.</param> /// <returns>A new <see cref="Subject{TResult}"/> instance.</returns> public Subject <TResult> DynamicResultOf <TResult>(Expression <Func <TObject, TResult> > functionExpression) { functionExpression.CheckNotNull(nameof(functionExpression)); var function = functionExpression.Compile(); string functionName = ObjectExpressionStringBuilder.ExpressionToString(functionExpression); return(DynamicResultOf(function, functionName)); }
/// <summary> /// Executes the specified <paramref name="actionExpression"/>. /// Appends the text representation of the <paramref name="actionExpression"/> to the <c>ProviderName</c> property of this instance. /// </summary> /// <param name="actionExpression">The action expression.</param> /// <returns>The same subject instance.</returns> public TSubject Act(Expression <Action <TObject> > actionExpression) { actionExpression.CheckNotNull(nameof(actionExpression)); var action = actionExpression.Compile(); string actionName = ObjectExpressionStringBuilder.ExpressionToString(actionExpression); return(Act(action, actionName)); }
/// <summary> /// Creates a new lazy <see cref="ActionProvider{TOwner}"/> from the invocation of the specified <paramref name="actionExpression"/>. /// </summary> /// <param name="actionExpression">The action expression.</param> /// <returns>A new <see cref="ActionProvider{TOwner}"/> instance.</returns> public ActionProvider <TSubject> DynamicInvoking(Expression <Action <TObject> > actionExpression) { actionExpression.CheckNotNull(nameof(actionExpression)); var action = actionExpression.Compile(); string actionName = ObjectExpressionStringBuilder.ExpressionToString(actionExpression); return(DynamicInvoking(action, actionName)); }
/// <summary> /// Verifies that object satisfies the specified predicate expression. /// </summary> /// <typeparam name="TData">The type of the data.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="verifier">The verification provider.</param> /// <param name="predicateExpression">The predicate expression.</param> /// <returns>The owner instance.</returns> public static TOwner Satisfy <TData, TOwner>( this IDataVerificationProvider <TData, TOwner> verifier, Expression <Predicate <TData> > predicateExpression) { predicateExpression.CheckNotNull(nameof(predicateExpression)); var predicate = predicateExpression.Compile(); string expressionAsString = ObjectExpressionStringBuilder.ExpressionToString(predicateExpression); return(verifier.Satisfy(predicate, $"satisfy {expressionAsString}")); }
/// <summary> /// Refreshes the current page until the condition specified by <paramref name="predicateExpression"/> argument is met. /// </summary> /// <param name="predicateExpression">The predicate expression to test the page.</param> /// <param name="timeout">The timeout in seconds.</param> /// <param name="retryInterval">The retry interval in seconds.</param> /// <returns>The instance of this page object.</returns> /// <example> /// <code> /// PageObject.RefreshPageUntil(x => x.SomeControl.IsVisible, timeout: 60, retryInterval: 5); /// </code> /// </example> public TOwner RefreshPageUntil(Expression <Func <TOwner, bool> > predicateExpression, double?timeout = null, double?retryInterval = null) { var predicate = predicateExpression.CheckNotNull(nameof(predicateExpression)).Compile(); TimeSpan timeoutTime = timeout.HasValue ? TimeSpan.FromSeconds(timeout.Value) : AtataContext.Current.WaitingTimeout; TimeSpan retryIntervalTime = retryInterval.HasValue ? TimeSpan.FromSeconds(retryInterval.Value) : AtataContext.Current.WaitingRetryInterval; TOwner activePageObject = (TOwner)this; string predicateMessage = ObjectExpressionStringBuilder.ExpressionToString(predicateExpression); string actionMessage = $"Refresh page until \"{predicateMessage}\" within {timeoutTime.ToShortIntervalString()} with {retryIntervalTime.ToShortIntervalString()} retry interval"; AtataContext.Current.Log.ExecuteSection( new LogSection(actionMessage), () => { bool isOk = Driver. Try(timeoutTime, retryIntervalTime). Until(x => { activePageObject = activePageObject.RefreshPage(); return(predicate(activePageObject)); }); if (!isOk) { throw new TimeoutException($"Timed out after {timeoutTime.ToShortIntervalString()} waiting for: {actionMessage.ToLowerFirstLetter()}."); } }); return(activePageObject); }
public static string ResolveControlName <TControl, TOwner>(Expression <Func <TControl, bool> > predicateExpression) where TControl : Control <TOwner> where TOwner : PageObject <TOwner> { return(ObjectExpressionStringBuilder.ExpressionToString(predicateExpression)); }
public static string ToString(Expression expression) { return($"\"{ObjectExpressionStringBuilder.ExpressionToString(expression)}\""); }
public static string ToString <T>(Expression <Func <T, bool> > predicateExpression) { return($"\"{ObjectExpressionStringBuilder.ExpressionToString(predicateExpression)}\" {GetItemTypeName(typeof(T))}"); }
private static string ConvertToValueName(Expression expression) => ObjectExpressionStringBuilder.ExpressionToString(expression);