Пример #1
0
        /// <summary>
        /// Output a given expression tree to a string.
        /// </summary>
        /// <param name="node">The expression node.</param>
        /// <returns>The string representing the expression.</returns>
        public static new string ExpressionToString(Expression node)
        {
            Debug.Assert(node != null, "'node' should not be null.");

            ControlNameExpressionStringBuilder expressionStringBuilder = new ControlNameExpressionStringBuilder();

            expressionStringBuilder.Visit(node);

            string result = expressionStringBuilder.ToString();

            result = TrimBrackets(result);

            if (expressionStringBuilder.operatorAndCount > 0 && expressionStringBuilder.operatorElseCount == 0)
            {
                return(NormalizeBrackets(result, "&&"));
            }
            else if (expressionStringBuilder.operatorAndCount == 0 && expressionStringBuilder.operatorElseCount > 0)
            {
                return(NormalizeBrackets(result, "||"));
            }
            else
            {
                return(result);
            }
        }
Пример #2
0
        /// <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 = ControlNameExpressionStringBuilder.ExpressionToString(selector);

            return(Component.GetOrCreateDataProvider(
                       $"\"{dataPathName}\" {ProviderName}",
                       () => GetAll().Select(selector.Compile())));
        }
Пример #3
0
        /// <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 = ControlNameExpressionStringBuilder.ExpressionToString(predicateExpression);

            string actionMessage = $"Refresh page until \"{predicateMessage}\" within {timeoutTime.ToIntervalString()} with {retryIntervalTime.ToIntervalString()} retry interval";

            AtataContext.Current.Log.Start(actionMessage);

            bool isOk = Driver.
                        Try(timeoutTime, retryIntervalTime).
                        Until(x =>
            {
                activePageObject = activePageObject.RefreshPage();
                return(predicate(activePageObject));
            });

            if (!isOk)
            {
                throw new TimeoutException($"Timed out after {timeoutTime.ToIntervalString()} waiting for: {actionMessage.ToLowerFirstLetter()}.");
            }

            AtataContext.Current.Log.EndSection();

            return(activePageObject);
        }
Пример #4
0
 public static string ResolveControlName <TControl, TOwner>(Expression <Func <TControl, bool> > predicateExpression)
     where TControl : Control <TOwner>
     where TOwner : PageObject <TOwner>
 {
     return(ControlNameExpressionStringBuilder.ExpressionToString(predicateExpression));
 }