예제 #1
0
        public static void Tap(UIObject obj)
        {
            // Allowing three attempts to work around occasional failure on Phone builds.
            int retries = 3;

            while (retries > 0)
            {
                try
                {
                    Log.Comment("Tap on {0}.", obj.GetIdentifier());
                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Tap))
                    {
                        if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                        {
                            Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                            obj.Click(PointerButtons.Primary);
                        }
                        else
                        {
                            obj.Tap();
                        }
                    }

                    retries = 0;
                }
                catch (Exception e)
                {
                    Log.Warning("Exception while tapping: " + e.Message);
                    retries--;
                }
            }

            Wait.ForIdle();
        }
예제 #2
0
        public static void DoubleTap(UIObject obj, double offsetX, double offsetY)
        {
            try
            {
                Log.Comment("Double-tap on {0} at ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
                using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Tap))
                {
                    if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                    {
                        Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                        obj.DoubleClick(PointerButtons.Primary, offsetX, offsetY);
                    }
                    else
                    {
                        obj.DoubleTap(offsetX, offsetY);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Warning("Exception while double-tapping: " + e.Message);
            }

            Wait.ForIdle();
        }
예제 #3
0
        public static void Stretch(UIObject obj, uint distance, Direction direction, bool pivot)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Error("Touch input is not available on OS versions less than RS5, and there is no mouse fallback for stretch. This test should be disabled pre-RS5.");
                return;
            }

            string id = obj.GetIdentifier();
            string pivotMode;

            if (pivot)
            {
                pivotMode = "one finger stationary";
            }
            else
            {
                pivotMode = "both fingers moving";
            }
            Log.Comment("Stretch with {0} on {1}, in the {2} direction, over a distance of {3} pixels.",
                        pivotMode, id, direction, distance);

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Pinch))
            {
                MultiPointGesture.Stretch(obj, distance, DirectionToAngle(direction), pivot);
            }
            Wait.ForIdle();
        }
예제 #4
0
 public static void LeftClick(UIObject obj)
 {
     Log.Comment("Left-click on {0}.", obj.GetIdentifier());
     using (var waiter = GetWaiterForInputEvent(obj, InputEvent.LeftClick))
     {
         obj.Click(PointerButtons.Primary);
     }
     Wait.ForIdle();
 }
예제 #5
0
 public static void LeftClick(UIObject obj, double offsetX, double offsetY)
 {
     Log.Comment("Left-click on {0}, at ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
     using (var waiter = GetWaiterForInputEvent(obj, InputEvent.LeftClick))
     {
         obj.Click(PointerButtons.Primary, offsetX, offsetY);
     }
     Wait.ForIdle();
 }
예제 #6
0
        public static void Pan(UIObject obj, int distance, Direction direction, uint holdDuration = DefaultPanHoldDuration, float panAcceleration = DefaultPanAcceleration, uint dragDuration = DefaultDragDuration, bool waitForIdle = true)
        {
            Log.Comment("Pan on {0} for {1} pixels in the {2} direction, after holding {3} ms.",
                        obj.GetIdentifier(), distance, direction, holdDuration);
            Log.Comment("Clickable point of pan object is {0}", obj.GetClickablePoint());
            Log.Comment("Bounding rectangle of object is {0}", obj.BoundingRectangle);

            Pan(obj, obj.GetClickablePoint(), distance, direction, holdDuration, panAcceleration, dragDuration, waitForIdle);
        }
예제 #7
0
        public static void RightClick(UIObject obj, int offsetX = 0, int offsetY = 0)
        {
            if (offsetX == 0 && offsetY == 0)
            {
                Log.Comment("Right-click on {0}.", obj.GetIdentifier());
            }
            else
            {
                Log.Comment("Right-click on {0} at offset ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
            }

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.RightClick))
            {
                obj.Click(PointerButtons.Secondary, offsetX, offsetY);
            }

            Wait.ForIdle();
        }
예제 #8
0
        public static void Pan(UIObject obj, Point start, int distance, Direction direction, uint holdDuration = DefaultPanHoldDuration, float panAcceleration = DefaultPanAcceleration, uint dragDuration = DefaultDragDuration, bool waitForIdle = true)
        {
            Log.Comment("Pan on {0}, starting at ({1}, {2}), for {3} pixels in the {4} direction, after holding {5} ms.",
                        obj.GetIdentifier(), start.X, start.Y, distance, direction, holdDuration);
            double directionRadians = DirectionToAngle(direction) * Math.PI / 180d;
            Point  end = new Point()
            {
                X = start.X + (int)Math.Round(distance * Math.Cos(directionRadians)),
                Y = start.Y - (int)Math.Round(distance * Math.Sin(directionRadians))
            };

            Pan(obj, start, end, holdDuration, panAcceleration, dragDuration, waitForIdle);
        }
예제 #9
0
        public static void MoveMouse(UIObject obj, int offsetX, int offsetY)
        {
            Log.Comment("Move mouse on {0} to offset ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.MouseMove))
            {
                var point = obj.GetClickablePoint();

                point.X += offsetX;
                point.Y += offsetY;

                PointerInput.Move(point);
            }
            Wait.ForIdle();
        }
예제 #10
0
        public static void Stretch(UIObject obj)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Error("Touch input is not available on OS versions less than RS5, and there is no mouse fallback for stretch. This test should be disabled pre-RS5.");
                return;
            }

            Log.Comment("Stretch on {0}.", obj.GetIdentifier());
            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Pinch))
            {
                MultiPointGesture.Stretch(obj);
            }
            Wait.ForIdle();
        }
예제 #11
0
        public static void Flick(UIObject obj, int distance, Direction direction)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Error("Touch input is not available on OS versions less than RS5, and there is no mouse fallback for flick. This test should be disabled pre-RS5.");
                return;
            }

            Log.Comment("Flick on {0} over {1} pixels in the {2} direction.", obj.GetIdentifier(), distance, direction);
            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Flick))
            {
                obj.Flick(distance, DirectionToAngle(direction));
            }
            Wait.ForIdle();
        }
예제 #12
0
        public static void LeftMouseButtonUp(UIObject obj, int offsetX = 0, int offsetY = 0)
        {
            if (offsetX == 0 && offsetY == 0)
            {
                Log.Comment("Left mouse button up on {0}.", obj.GetIdentifier());
            }
            else
            {
                Log.Comment("Left mouse button up on {0} at offset ({1}, {2}).",
                            obj.GetIdentifier(), offsetX, offsetY);
            }

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.MouseUp))
            {
                var point = obj.GetClickablePoint();

                point.X += offsetX;
                point.Y += offsetY;

                PointerInput.Move(point);
                PointerInput.Release(PointerButtons.Primary);
            }
            Wait.ForIdle();
        }
예제 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="offsetX">value from top left</param>
        /// <param name="offsetY">value from top left</param>
        public static void Tap(UIObject obj, double offsetX, double offsetY)
        {
            // Allowing three attempts to work around occasional failure on Phone builds.
            int retries = 3;

            while (retries > 0)
            {
                try
                {
                    Log.Comment("Tap on {0} at ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
                    Log.Comment("Bounding rectangle is: " + obj.BoundingRectangle.ToString());

                    if (offsetX > obj.BoundingRectangle.Width)
                    {
                        Log.Warning("Warning, the tap offsetX is higher than the bounding rectangle width");
                    }

                    if (offsetY > obj.BoundingRectangle.Height)
                    {
                        Log.Warning("Warning, the tap offsetY is higher than the bounding rectangle height");
                    }

                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Tap))
                    {
                        if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                        {
                            Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                            obj.Click(PointerButtons.Primary, offsetX, offsetY);
                        }
                        else
                        {
                            obj.Tap(offsetX, offsetY);
                        }
                    }

                    retries = 0;
                }
                catch (Exception e)
                {
                    Log.Warning("Exception while tapping: " + e.Message);
                    retries--;
                }
            }

            Wait.ForIdle();
        }
예제 #14
0
 public static void TapAndHold(UIObject obj, uint durationMs)
 {
     Log.Comment("Tap and hold on {0} for {1} ms.", obj.GetIdentifier(), durationMs);
     using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Tap))
     {
         if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
         {
             Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
             PointerInput.Move(obj);
             PointerInput.Press(PointerButtons.Primary);
             Wait.ForMilliseconds(durationMs);
             PointerInput.Release(PointerButtons.Primary);
         }
         else
         {
             obj.TapAndHold(durationMs);
         }
     }
     Wait.ForIdle();
 }
예제 #15
0
        public static void Pan(UIObject obj, Point start, Point end, uint holdDuration = DefaultPanHoldDuration, float panAcceleration = DefaultPanAcceleration, uint dragDuration = DefaultDragDuration, bool waitForIdle = true)
        {
            Log.Comment("Pan on {0}, starting at ({1}, {2}), ending at ({3}, {4}), after holding {5} ms, with acceleration {6}.",
                        obj.GetIdentifier(), start.X, start.Y, end.X, end.Y, holdDuration, panAcceleration);

            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
                {
                    Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                    PointerInput.Move(start);
                    PointerInput.ClickDrag(end, PointerButtons.Primary, dragDuration);
                }
            }
            else
            {
                if (panAcceleration == 0.0f)
                {
                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
                    {
                        SinglePointGesture.Current.Move(start);
                        SinglePointGesture.Current.PressAndDrag(end, dragDuration, holdDuration);
                    }
                }
                else
                {
                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Pan))
                    {
                        SinglePointGesture.Current.Move(start);
                        SinglePointGesture.Current.Pan(end, holdDuration, panAcceleration);
                    }
                }
            }

            if (waitForIdle)
            {
                Wait.ForIdle();
            }
        }
예제 #16
0
        public static void DragDistance(UIObject obj, int distance, Direction direction, uint duration = 4000)
        {
            Log.Comment("Drag {0} {1} pixels in the {2} direction.", obj.GetIdentifier(), distance, direction);
            Point  startPoint       = obj.GetClickablePoint();
            double directionRadians = DirectionToAngle(direction) * Math.PI / 180d;

            Log.Comment("Start Point X:{0} Y:{1}", startPoint.X, startPoint.Y);

            Point end = new Point()
            {
                X = startPoint.X + (int)Math.Round(distance * Math.Cos(directionRadians)),
                Y = startPoint.Y - (int)Math.Round(distance * Math.Sin(directionRadians))
            };

            Log.Comment("End Point X:{0} Y:{1}", end.X, end.Y);

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
            {
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                    Log.Comment("Move input to Start Point.");
                    PointerInput.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    PointerInput.ClickDrag(end, PointerButtons.Primary, duration);
                    Log.Comment("Drag Complete.");
                }
                else
                {
                    Log.Comment("Move input to Start Point.");
                    SinglePointGesture.Current.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    SinglePointGesture.Current.ClickDrag(end, PointerButtons.Primary, duration);
                    Log.Comment("Drag Complete.");
                }
            }
            Wait.ForIdle();
        }
예제 #17
0
 public static void RotateWheel(UIObject obj, int mouseWheelDelta)
 {
     Log.Comment("RotateWheel on {0} with mouseWheelDelta: {1}.", obj.GetIdentifier(), mouseWheelDelta);
     MouseWheelInput.RotateWheel(obj, mouseWheelDelta);
     Wait.ForIdle();
 }
예제 #18
0
 public static void LeftDoubleClick(UIObject obj, double offsetX, double offsetY)
 {
     Log.Comment("Left double-click on {0}, at ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
     obj.DoubleClick(PointerButtons.Primary, offsetX, offsetY);
     Wait.ForIdle();
 }
예제 #19
0
 public static void LeftDoubleClick(UIObject obj)
 {
     Log.Comment("Left double-click on {0}.", obj.GetIdentifier());
     obj.DoubleClick(PointerButtons.Primary);
     Wait.ForIdle();
 }