예제 #1
0
파일: Gestures.cs 프로젝트: sung-su/maui
        public static bool ScrollForElement(this IApp app, string query, Drag drag, int maxSteps = 25)
        {
            Func <AppQuery, AppQuery> elementQuery = q => q.Raw(query);

            int centerTolerance = 50;
            var appResults      = app.QueryNTimes(elementQuery, 10, null);

            // Visible elements
            if (appResults.Length > 1)
            {
                throw new UITestQueryMultipleResultsException(query);
            }

            appResults = app.QueryNTimes(elementQuery, maxSteps, () => app.DragCoordinates(drag.XStart, drag.YStart, drag.XEnd, drag.YEnd));
            if (appResults.Length > 0)
            {
                // centering an element whos CenterX is close to the bounding rectangle's center X can sometime register the swipe as a tap
                float elementDistanceToDragCenter = Math.Abs(appResults.First().Rect.CenterY - drag.DragBounds.CenterY);
                if (elementDistanceToDragCenter > centerTolerance)
                {
                    app.CenterElementInView(appResults.First().Rect, drag.DragBounds, drag.DragDirection);
                }
                return(true);
            }

            drag.DragDirection = drag.OppositeDirection;
            appResults         = app.QueryNTimes(elementQuery, maxSteps, () => app.DragCoordinates(drag.XStart, drag.YStart, drag.XEnd, drag.YEnd));

            if (appResults.Length > 0)
            {
                app.CenterElementInView(appResults.First().Rect, drag.DragBounds, drag.DragDirection);
                return(true);
            }

            return(false);
        }
예제 #2
0
        public static bool ScrollForElement(this IApp app, string query, Drag drag, int maxSteps = 25)
        {
            Func <AppQuery, AppQuery> elementQuery = q => q.Raw(query);

            int count = 0;

            int centerTolerance = 50;

            // Visible elements
            if (app.Query(elementQuery).Length > 1)
            {
                throw new UITestQueryMultipleResultsException(query);
            }

            // check to see if the element is visible already
            if (app.Query(elementQuery).Length == 1)
            {
                // centering an element whos CenterX is close to the bounding rectangle's center X can sometime register the swipe as a tap
                float elementDistanceToDragCenter = Math.Abs(app.Query(elementQuery).First().Rect.CenterY - drag.DragBounds.CenterY);
                if (elementDistanceToDragCenter > centerTolerance)
                {
                    app.CenterElementInView(elementQuery, drag.DragBounds, drag.DragDirection);
                }
                return(true);
            }

            // loop until element is seen
            while (app.Query(elementQuery).Length == 0 && count < maxSteps)
            {
                app.DragCoordinates(drag.XStart, drag.YStart, drag.XEnd, drag.YEnd);
                count++;
            }

            if (count != maxSteps)
            {
                // centering an element whos CenterX is close to the bounding rectangle's center X can sometime register the swipe as a tap
                float elementDistanceToDragCenter = Math.Abs(app.Query(elementQuery).First().Rect.CenterY - drag.DragBounds.CenterY);
                if (elementDistanceToDragCenter > centerTolerance)
                {
                    app.CenterElementInView(elementQuery, drag.DragBounds, drag.DragDirection);
                }
                return(true);
            }

            count = 0;
            drag.DragDirection = drag.OppositeDirection;

            while (app.Query(elementQuery).Length == 0 && count < maxSteps)
            {
                app.DragCoordinates(drag.XStart, drag.YStart, drag.XEnd, drag.YEnd);
                count++;
            }

            if (count != maxSteps)
            {
                app.CenterElementInView(elementQuery, drag.DragBounds, drag.DragDirection);
                return(true);
            }

            return(false);
        }