示例#1
0
 /// <summary>
 /// Performs a long tap on the element of the specified driver.
 /// </summary>
 /// <param name="driver">The driver to use.</param>
 /// <param name="element">The element to long tap.</param>
 public static void Longtap(IWebDriver driver, IWebElement element)
 {
     if (driver is IHasTouchScreen)
     {
         TouchActions longtap = new TouchActions(driver);
         Point        center  = GetCenter(element);
         longtap.Down(center.X, center.Y);
         longtap.Perform();
         try
         {
             Thread.Sleep(750);
         }
         catch (ThreadInterruptedException)
         {
         }
         longtap.Up(center.X, center.Y);
         longtap.Perform();
     }
     else
     {
         ILocatable   locatable = (ILocatable)element;
         ICoordinates coords    = locatable.Coordinates;
         IMouse       mouse     = ((IHasInputDevices)driver).Mouse;
         mouse.MouseDown(coords);
         try
         {
             Thread.Sleep(750);
         }
         catch (ThreadInterruptedException)
         {
         }
         mouse.MouseUp(coords);
     }
 }
        /// <summary>
        /// Zoom at the specified point
        /// </summary>
        /// <param name="x">x screen location</param>
        /// <param name="y">y screen location</param>
        public void Zoom(int x, int y)
        {
            var touchAction1 = new TouchActions(this);

            touchAction1.Down(x, y).Move(x, y - 100).Up(x, y - 100);

            var touchAction2 = new TouchActions(this);

            touchAction2.Down(x, y).Move(x, y + 100).Up(x, y + 100);

            var multiTouchAction = new MultiTouchAction(this);

            multiTouchAction.Add(touchAction1);
            multiTouchAction.Add(touchAction2);
            PerformMultiTouchAction(multiTouchAction);
        }
示例#3
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);
            }
        }