예제 #1
0
        public virtual void ScrollTo(string automationId)
        {
            var action = new TouchActions(Driver);

            action.Scroll(0, 100)
            .Perform();
        }
예제 #2
0
        public void tapElement(AppiumWebElement element)
        {
            TouchActions actions = new TouchActions(driver);

            actions.SingleTap(element);
            actions.Perform();
        }
예제 #3
0
        /// <summary>
        /// Gets the list of actions for the touch action to be used in MultiTouchAction
        /// </summary>
        /// <param name="touchAction">touch action</param>
        /// <returns></returns>
        public static List <Dictionary <string, object> > GetActionsList(this TouchActions touchAction)
        {
            if (null == touchAction)
            {
                throw new ArgumentNullException("touchAction");
            }

            var actionsList = new List <Dictionary <string, object> >();

            foreach (var iaction in touchAction.GetActions())
            {
                Dictionary <string, object> yy = null;
                if (null == iaction)
                {
                    // do nothing
                }
                else if (null == (yy = iaction._GetParameters()))
                {
                    // do nothing
                }
                else
                {
                    actionsList.Add(yy);
                }
            }

            return(actionsList);
        }
예제 #4
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);
     }
 }
        protected void DoubleTap(IWebElement element)
        {
            WaitForElement(element);
            TouchActions action = new TouchActions(DriverFactory.INSTANCE);

            action.DoubleTap(element);
            action.Perform();
        }
예제 #6
0
        protected void doubleTap(IWebElement element)
        {
            WaitForElement(element);
            //IWebElement iElement = driver.FindElement(element);
            TouchActions action = new TouchActions(DriverFactory.GetDriver());

            action.DoubleTap(element);
            action.Perform();
        }
        protected void LongPress(IWebElement element)
        {
            WaitForElement(element);
            TouchActions action = new TouchActions(DriverFactory.INSTANCE);

            action.LongPress(element);
            action.Release();
            action.Perform();
        }
예제 #8
0
        protected void longPress(IWebElement element)
        {
            WaitForElement(element);
            //IWebElement iElement = driver.FindElement(element);

            TouchActions action = new TouchActions(DriverFactory.GetDriver());

            action.LongPress(element);
            action.Perform();
        }
        /// <summary>
        /// Add touch actions to be performed
        /// </summary>
        /// <param name="touchAction"></param>
        public MultiTouchAction Add(TouchActions touchAction)
        {
            if (null == touchAction)
            {
                throw new ArgumentNullException("touchAction");
            }

            _MultiTouchActionList.Add(touchAction);
            return(this);
        }
예제 #10
0
 /// <summary>
 /// Performs a single tap on the element of the specified driver.
 /// </summary>
 /// <param name="driver">The driver to use.</param>
 /// <param name="element">The element.</param>
 public static void Tap(IWebDriver driver, IWebElement element)
 {
     if (driver is IHasTouchScreen)
     {
         TouchActions tap = (new TouchActions(driver)).SingleTap(element);
         tap.Perform();
     }
     else
     {
         element.Click();
     }
 }
예제 #11
0
        protected void Tap(IWebElement element)
        {
            //waitForElement(element);
            //TouchActions action = new TouchActions(driver);
            //action.singleTap(element);
            //action.perform();
            WaitForElement(element);
            //IWebElement iElement = driver.FindElement(element);
            TouchActions action = new TouchActions(DriverFactory.GetDriver());

            action.SingleTap(element);
            action.Perform();
        }
예제 #12
0
 public void TouchUp()
 {
     if (!_interactionEnabled)
     {
         return;
     }
     if (!_touchedDown)
     {
         return;
     }
     _touchedDown = false;
     TouchActions.TouchUp(Input.mousePosition);
 }
예제 #13
0
        public void TestTouchActions()
        {
            var touches = new TouchActions(this.driver);

            var pivot = this.driver.FindElementById("MainPivot");

            touches.Flick(pivot, -300, 0, 500).Perform();

            var wait    = new WebDriverWait(this.driver, TimeSpan.FromSeconds(5));
            var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("SecondTabTextBox")));

            Assert.AreEqual("Nice swipe!", element.Text);
        }
예제 #14
0
 public void TouchDown()
 {
     if (!_interactionEnabled)
     {
         return;
     }
     if (touchCount == 0)
     {
         touchCount++;
         StartCoroutine(StartLevelWithDelay());
     }
     _touchedDown = true;
     TouchActions.TouchDown(Input.mousePosition);
 }
예제 #15
0
    public void TouchEvent_CanTrigger()
    {
        Browser.MountTestComponent <TouchEventComponent>();

        var input = Browser.Exists(By.Id("touch_input"));

        var output = Browser.Exists(By.Id("output"));

        Assert.Equal(string.Empty, output.Text);

        var actions = new TouchActions(Browser).SingleTap(input);

        actions.Perform();
        Browser.Equal("touchstart,touchend,", () => output.Text);
    }
예제 #16
0
        public IReturnType Calculate(Objects.ValidSetOfTouchPoints set)
        {
            TouchActions actions = new TouchActions();

            foreach (var item in set)
            {
                TouchActionInfo info = new TouchActionInfo()
                {
                    Action = item.Action,
                    TouchDeviceId = item.TouchDeviceId
                };
                actions.Add(info);
            }

            return actions;
        }
        /// <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);
        }
예제 #18
0
        /// <summary>
        /// Pause execution of action chain for the given number of milliseconds.
        /// Defaults to zero so that it can be used for synchronizing actions
        /// </summary>
        /// <param name="touchAction">touch action chain to pause</param>
        /// <param name="ms">number of milliseconds to pause the action chain for</param>
        /// <returns></returns>
        public static TouchActions Wait(this TouchActions touchAction, int ms = 0)
        {
            if (null == touchAction)
            {
                throw new ArgumentNullException("touchAction");
            }

            // use reflection to find the AddAction() to add the wait action into the action chain
            var mi = typeof(TouchActions).GetMethod("AddAction", BindingFlags.NonPublic | BindingFlags.Instance);

            if (null != mi)
            {
                mi.Invoke(touchAction, new object[] { new WaitAction(ms) });
            }

            return(touchAction);
        }
예제 #19
0
        public void DraggableItemsTest()
        {
            IWebElement DraggableItem = _driver.FindElement(By.XPath("//div[@id='todrag']/span"));

            IWebElement DropBox = _driver.FindElement(By.Id("mydropzone"));

            TouchActions drag = new TouchActions(_driver);

            drag.LongPress(DraggableItem)
            .MoveToElement(DropBox)
            .Release(DropBox)
            .Perform();

            System.Threading.Thread.Sleep(15000);

            _driver.FindElement(DroppedItemList).Text.Should().Contain("Draggable 1");
        }
        public void ShouldTouch()
        {
            //Dictionary<String, String> mobileEmulation = new Dictionary<String, String>();
            //mobileEmulation.Add("deviceName", "Nexus 5");
            ChromeOptions chromeCapabilities = new ChromeOptions();

            chromeCapabilities.EnableMobileEmulation("Google Nexus 5");
            var driver = new TouchCapableChromeDriver();

            driver.Navigate().GoToUrl("https://en.wikipedia.org/wiki/Main_Page");

            var element = driver.FindElement(By.Id("searchInput"));

            var touchActions = new TouchActions(driver);

            touchActions.SingleTap(element)
            .Perform();

            driver.Quit();
        }
예제 #21
0
        /// <summary>
        /// Returns a list of actions
        /// </summary>
        /// <param name="actions"></param>
        /// <returns></returns>
        private static IEnumerable <IAction> GetActions(this TouchActions actions)
        {
            List <IAction> retVal = null;

            if (null == actions)
            {
                return(null);
            }

            try
            {
                //var compositeActionObj = _ActionFieldInfo.Value.GetValue(actions);
                retVal = _ActionsListFieldInfo.Value.GetValue(actions.Build()) as List <IAction>;
            }
            catch
            {
                // unable to get the field
            }

            return(retVal);
        }
예제 #22
0
        public void scrollDown()
        {
            TouchActions actions = new TouchActions(driver);

            actions.Scroll(50, 0);
        }
예제 #23
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);
            }
        }
예제 #24
0
 public TouchService(IWebDriver wrappedDriver)
     : base(wrappedDriver)
 {
     WrappedTouchActions = new TouchActions(wrappedDriver);
 }