示例#1
0
        internal static QueryEx FindInternal(this IApp app, QueryEx target, QueryEx within = null, FindScrollDirection direction = FindScrollDirection.DownThenUp, TimeSpan?timeOut = null)
        {
            // TODO: Add Visibility check here ?

            if (AttemptToFindTargetBeforeScrolling && target.HasResults())
            {
                return(target);
            }

            Action executeScrollDownTo;
            Action executeScrollUpTo;

            if (within == null)
            {
                executeScrollDownTo = () =>
                {
                    app.ScrollDownTo(
                        toQuery: target,
                        strategy: DefaultScrollStrategy,
                        swipeSpeed: InstantSwipeSpeed,
                        withInertia: false,
                        timeout: timeOut
                        );
                };

                executeScrollUpTo = () =>
                {
                    app.ScrollUpTo(
                        toQuery: target,
                        strategy: DefaultScrollStrategy,
                        swipeSpeed: InstantSwipeSpeed,
                        withInertia: false,
                        timeout: timeOut
                        );
                };
            }
            else
            {
                executeScrollDownTo = () =>
                {
                    app.ScrollDownTo(
                        toQuery: target,
                        withinQuery: within,
                        strategy: DefaultScrollStrategy,
                        swipeSpeed: InstantSwipeSpeed,
                        withInertia: false,
                        timeout: timeOut
                        );
                };

                executeScrollUpTo = () =>
                {
                    app.ScrollUpTo(
                        toQuery: target,
                        withinQuery: within,
                        strategy: DefaultScrollStrategy,
                        swipeSpeed: InstantSwipeSpeed,
                        withInertia: false,
                        timeout: timeOut
                        );
                };
            }

            // First step. Ignore misses if search is two-step process
            switch (direction)
            {
            case FindScrollDirection.Down:
                executeScrollDownTo();
                return(target);

            case FindScrollDirection.DownThenUp:
                try
                {
                    executeScrollDownTo();
                }
                catch (Exception) { }
                break;

            case FindScrollDirection.Up:
                executeScrollUpTo();
                return(target);

            case FindScrollDirection.UpThenDown:
                try
                {
                    executeScrollUpTo();
                }
                catch (Exception) { }
                break;
            }

            // Second step (if the search is a two step process)
            switch (direction)
            {
            case FindScrollDirection.DownThenUp:
                executeScrollUpTo();
                break;

            case FindScrollDirection.UpThenDown:
                executeScrollDownTo();
                break;
            }

            return(target);
        }