示例#1
0
        protected override string DoImpl()
        {
            if (!this.ExecutedCommand.Parameters.ContainsKey("x") &&
                this.ExecutedCommand.Parameters.ContainsKey("y"))
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            var x = this.ExecutedCommand.GetParameterAsInt("x");
            var y = this.ExecutedCommand.GetParameterAsInt("y");

            bool success;

            if (this.ExecutedCommand.Parameters.ContainsKey("element"))
            {
                var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
                var element       = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

                success = TouchSimulator.TouchDown(element, x, y);
            }
            else
            {
                success = TouchSimulator.TouchDown(x, y);
            }

            return(success
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
示例#2
0
 public void Action(GameObject target)
 {
     if (TouchSimulator.touchCount > 0)
     {
         var dp = TouchSimulator.GetTouch(0).deltaPosition;
         target.transform.position += new Vector3(dp.x, 0, 0);
     }
 }
        private static bool Drag(List <TouchAction> actions)
        {
            var startPoint = actions[0].GetLocation();
            var endPoint   = actions[1].GetLocation();

            return(TouchSimulator.Scroll(
                       (int)startPoint.X,
                       (int)startPoint.Y,
                       (int)endPoint.X,
                       (int)endPoint.Y));
        }
        private static bool Flick(List <TouchAction> actions)
        {
            var startPoint = actions[0].GetLocation();
            var endPoint   = actions[2].GetLocation();

            return(TouchSimulator.Flick(
                       (int)startPoint.X,
                       (int)startPoint.Y,
                       (int)endPoint.X,
                       (int)endPoint.Y,
                       actions[1].MiliSeconds));
        }
        private static bool DragWithTimes(List <TouchAction> actions)
        {
            var startPoint = actions[0].GetLocation();
            var endPoint   = actions[2].GetLocation();

            return(TouchSimulator.Scroll(
                       (int)startPoint.X,
                       (int)startPoint.Y,
                       (int)endPoint.X,
                       (int)endPoint.Y,
                       actions[1].MiliSeconds,
                       actions[3].MiliSeconds));
        }
        protected override string DoImpl()
        {
            var haveElement = this.ExecutedCommand.Parameters.ContainsKey("element");
            var havePoint   = this.ExecutedCommand.Parameters.ContainsKey("x") &&
                              this.ExecutedCommand.Parameters.ContainsKey("y");

            if (!(haveElement || havePoint))
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            bool             success;
            CruciatusElement element = null;
            var x = 0;
            var y = 0;

            if (haveElement)
            {
                var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
                element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);
            }

            if (havePoint)
            {
                x = this.ExecutedCommand.GetParameterAsInt("x");
                y = this.ExecutedCommand.GetParameterAsInt("y");
            }

            var duration = this.ExecutedCommand.Parameters.ContainsKey("duration")
                               ? this.ExecutedCommand.GetParameterAsInt("duration")
                               : 1000;

            if (haveElement && havePoint)
            {
                success = TouchSimulator.LongTap(element, x, y, duration);
            }
            else if (haveElement)
            {
                success = TouchSimulator.LongTap(element, duration);
            }
            else
            {
                success = TouchSimulator.LongTap(x, y, duration);
            }

            return(success
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
示例#7
0
        protected override string DoImpl()
        {
            if (!this.ExecutedCommand.Parameters.ContainsKey("element"))
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
            var element       = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

            return(TouchSimulator.DoubleTap(element)
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
示例#8
0
        string Flick()
        {
            if (!(this.ExecutedCommand.Parameters.ContainsKey("xspeed") &&
                  this.ExecutedCommand.Parameters.ContainsKey("yspeed")))
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            var xSpeed = this.ExecutedCommand.GetParameterAsInt("xspeed");
            var ySpeed = this.ExecutedCommand.GetParameterAsInt("yspeed");

            return(TouchSimulator.Flick(xSpeed, ySpeed)
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
示例#9
0
        string FlickElement()
        {
            if (
                !(this.ExecutedCommand.Parameters.ContainsKey("element") &&
                  this.ExecutedCommand.Parameters.ContainsKey("xoffset") &&
                  this.ExecutedCommand.Parameters.ContainsKey("yoffset") &&
                  this.ExecutedCommand.Parameters.ContainsKey("speed")))
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
            var element       = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

            var xOffset = this.ExecutedCommand.GetParameterAsInt("xoffset");
            var yOffset = this.ExecutedCommand.GetParameterAsInt("yoffset");

            var pixelsPerSecond = this.ExecutedCommand.GetParameterAsInt("speed");

            return(TouchSimulator.FlickElement(element, xOffset, yOffset, pixelsPerSecond)
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
        private static bool Perform(List <TouchAction> actions)
        {
            var    previousX      = 0;
            var    previousY      = 0;
            var    havePrevious   = false;
            string previousAction = null;

            for (var i = 0; i < actions.Count; i++)
            {
                var action = actions[i];

                Point point;

                switch (action.Action)
                {
                case TouchAction.LongPress:
                    point = action.GetLocation();
                    TouchSimulator.LongTap((int)point.X, (int)point.Y, action.MiliSeconds);
                    havePrevious = false;
                    break;

                case TouchAction.MoveTo:
                    int?duration = null;
                    if (i > 0 && actions[i - 1].Action == TouchAction.Wait)
                    {
                        duration = actions[i - 1].MiliSeconds;
                    }
                    point = action.GetLocation();
                    var x = (int)point.X;
                    var y = (int)point.Y;
                    TouchSimulator.MoveTo(previousX, previousY, previousX + x, previousY + y, duration);
                    previousX   += x;
                    previousY   += y;
                    havePrevious = true;
                    break;

                case TouchAction.Press:
                    point = action.GetLocation();
                    TouchSimulator.TouchDown((int)point.X, (int)point.Y);
                    previousX    = (int)point.X;
                    previousY    = (int)point.Y;
                    havePrevious = true;
                    break;

                case TouchAction.Release:
                    if (previousAction == TouchAction.Tap || previousAction == TouchAction.LongPress)
                    {
                        break;
                    }
                    TouchSimulator.TouchUp(previousX, previousY);
                    havePrevious = false;
                    break;

                case TouchAction.Tap:
                    point = action.GetLocation();
                    for (var n = 1; n <= action.Count; n++)
                    {
                        TouchSimulator.Tap((int)point.X, (int)point.Y);
                        Thread.Sleep(250);
                    }
                    havePrevious = false;
                    break;

                case TouchAction.Wait:
                    if (actions.Count > i + 1 && actions[i + 1].Action == TouchAction.MoveTo)
                    {
                        break;
                    }
                    if (havePrevious)
                    {
                        var startTime = DateTime.Now;
                        while (DateTime.Now < startTime + TimeSpan.FromMilliseconds(action.MiliSeconds))
                        {
                            TouchSimulator.TouchUpdate(previousX, previousY);
                            Thread.Sleep(16);
                        }
                    }
                    else
                    {
                        Thread.Sleep(action.MiliSeconds);
                    }
                    break;

                default:
                    throw new AutomationException($"unrecognised action {action.Action}");
                }

                previousAction = action.Action;
            }

            return(true);
        }
示例#11
0
        protected override string DoImpl()
        {
            var haveElement = this.ExecutedCommand.Parameters.ContainsKey("element");
            var haveOffset  = this.ExecutedCommand.Parameters.ContainsKey("xoffset") &&
                              this.ExecutedCommand.Parameters.ContainsKey("yoffset");

            if (!haveOffset)
            {
                // TODO: in the future '400 : invalid argument' will be used
                return(this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS"));
            }

            var element = CruciatusFactory.Root;

            if (haveElement)
            {
                var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
                element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);
            }

            var rect = element.Properties.BoundingRectangle;

            var startPoint = new Point(
                rect.Left + (rect.Width / 2),
                rect.Top + (rect.Height / 2));

            var xOffset = this.ExecutedCommand.GetParameterAsInt("xoffset");
            var yOffset = this.ExecutedCommand.GetParameterAsInt("yoffset");

            var endPoint = new Point(
                startPoint.X + xOffset,
                startPoint.Y + yOffset);

            if (!TouchSimulator.TouchDown((int)startPoint.X, (int)startPoint.Y))
            {
                return(this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
            }

            var distance = Math.Sqrt(Math.Pow(startPoint.X - endPoint.X, 2) + Math.Pow(startPoint.Y - endPoint.Y, 2));

            for (var soFar = 6; soFar < distance; soFar += 6)
            {
                var soFarFraction = soFar / distance;

                var x = (int)(startPoint.X + (xOffset * soFarFraction));
                var y = (int)(startPoint.Y + (yOffset * soFarFraction));
                if (!TouchSimulator.TouchUpdate(x, y))
                {
                    return(this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
                }

                Thread.Sleep(8);
            }

            var startTime = DateTime.Now;

            while (DateTime.Now < (startTime + TimeSpan.FromMilliseconds(500)))
            {
                if (!TouchSimulator.TouchUpdate((int)endPoint.X, (int)endPoint.Y))
                {
                    return(this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
                }
                Thread.Sleep(16);
            }

            return(TouchSimulator.TouchUp((int)endPoint.X, (int)endPoint.Y)
                ? this.JsonResponse()
                : this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed"));
        }
示例#12
0
 // FixedUpdate is called once per frame before Update
 void FixedUpdate()
 {
     TouchSimulator.Update();
 }