예제 #1
0
        /// <summary>
        /// Tracks the element of the specified driver by the specified offsets
        /// </summary>
        /// <param name="driver">The driver to use.</param>
        /// <param name="element">The element to track.</param>
        /// <param name="x">Amount of pixels to move horizontally</param>
        /// <param name="y">Amount of pixels to move vertically</param>
        /// <param name="step">Generate a move event every (step) pixels</param>
        public static void Track(IWebDriver driver, IWebElement element, int x, int y, int step)
        {
            if (driver is IHasTouchScreen)
            {
                if (step == 0)
                {
                    step = 1;
                    // TODO: no move if step == 0
                }

                Point center = GetCenter(element);

                int posX = center.X;
                int posY = center.Y;

                int endX = posX + x;
                int endY = posY + y;

                TouchActions touchAction = new TouchActions(driver);
                touchAction.Down(posX, posY);

                while ((x < 0 && posX > endX || x > 0 && posX < endX) || (y < 0 && posY > endY || y > 0 && posY < endY))
                {
                    if (x > 0 && posX < endX)
                    {
                        if (posX + step > endX)
                        {
                            posX += endX - (posX + step);
                        }
                        else
                        {
                            posX += step;
                        }
                    }

                    else if (x < 0 && posX > endX)
                    {
                        if (posX - step < endX)
                        {
                            posX -= endX + (posX - step);
                        }
                        else
                        {
                            posX -= step;
                        }
                    }

                    if (y > 0 && posY < endY)
                    {
                        if (posY + step > endY)
                        {
                            posY += endY - (posY + step);
                        }
                        else
                        {
                            posY += step;
                        }
                    }

                    else if (y < 0 && posY > endY)
                    {
                        if (posY - step < endY)
                        {
                            posY -= endY + (posY - step);
                        }
                        else
                        {
                            posY -= step;
                        }
                    }

                    touchAction.Move(posX, posY);
                }

                touchAction.Up(posX, posY).Perform();
            }
            else
            {
                Actions mouseAction = new Actions(driver);
                mouseAction.DragAndDropToOffset(element, x, y);
            }
        }