/// <summary> /// Perform the touch action /// </summary> /// <param name="touchAction">touch action to perform</param> public void PerformTouchAction(ITouchAction touchAction) { if (touchAction != null) { var parameters = new Dictionary <string, object>(); parameters.Add("actions", touchAction.GetParameters()); Execute(AppiumDriverCommand.PerformTouchAction, parameters); } }
public void PerformTouchAction(ITouchAction touchAction) { if (touchAction == null) { return; } var parameters = AppiumCommandExecutionHelper.PrepareArgument("actions", touchAction.GetParameters()); Execute(AppiumDriverCommand.PerformTouchAction, parameters); }
/// <summary> /// Add touch actions to be performed /// </summary> /// <param name="touchAction"></param> public IMultiAction Add(ITouchAction touchAction) { if (null == touchAction) { throw new ArgumentNullException("touchAction"); } actions.Add(touchAction); return(this); }
/// <summary> /// Add touch actions to be performed /// </summary> /// <param name="touchAction"></param> public IMultiAction Add(ITouchAction touchAction) { if (null == touchAction) { throw new ArgumentNullException("touchAction"); } actions.Add(touchAction); return this; }
/// <summary> /// Perform the touch action /// </summary> /// <param name="touchAction">touch action to perform</param> public void PerformTouchAction(ITouchAction touchAction) { if (null == touchAction) { return; // do nothing } var parameters = new Dictionary <string, object>(); parameters.Add("actions", touchAction.GetParameters()); this.Execute(AppiumDriverCommand.PerformTouchAction, parameters); }
public void SwipeTestCase() { driver.FindElementByName("Test Gesture").Click(); Thread.Sleep(1000); driver.FindElementByName("OK").Click(); Thread.Sleep(1000); Point loc = driver.FindElementByXPath("//UIAMapView[1]").Location; ITouchAction swipe = Actions.Swipe(driver, loc.X, loc.Y, loc.X + 150, loc.Y, 800); swipe.Perform(); }
/// <summary> /// Swipe from an initial position to an ending position based on the parameters /// </summary> /// <param name="startX"> initial value on X axis </param> /// <param name="startY"> initial value on Y axis </param> /// <param name="endX"> ending value on X axis </param> /// <param name="endY"> ending value on Y axis </param> /// <param name="duration"> time to wait until swipe to position </param> public static void SwipeScreen(int startX, int startY, int endX, int endY, int duration = 0) { ITouchAction action = BuildSingleAction(); try { action.Press(startX, startY).Wait(duration).MoveTo(endX, endY).Release().Perform(); } catch (Exception ex) { Assert.Fail("SwipeScreen threw an exception: " + ex.Message); } }
/// <summary> /// LongPress over a specific element that will be found using it's classname. /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="duration"> time to wait until swipe to position </param> public static void LongPressByClassName(string className, int duration = 1) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement element = GetControl.ByClass(className); action.LongPress(element).Wait(duration).Release().Perform(); } catch (Exception ex) { Assert.Fail("PressByClassName threw an exception: " + ex.Message); } }
/// <summary> /// Tap over a specific element that will be found using it's classname /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="x"> value to move on X axis </param> /// <param name="y"> value to move on Y axis </param> /// <param name="duration"> time to wait until swipe to position </param> public static void TapByClassName(string className, int x, int y, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement element = GetControl.ByClass(className); action.Tap(element, x, y).Wait(duration).Perform(); } catch (Exception ex) { Assert.Fail("TapByClassName threw an exception: " + ex.Message); } }
/// <summary> /// Moves to a specific position of an element that will be found using it's classname /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="x"> value to move on X axis </param> /// <param name="y"> value to move on Y axis </param> public static void MoveToByClassName(string className, int x, int y) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement scrollView = GetControl.ByClass(className); action.MoveTo(scrollView, x, y).Perform(); } catch (Exception ex) { Assert.Fail("MoveToByClassName threw an exception: " + ex.Message); } }
/// <summary> /// LongPress over a specific element that will be found using it's classname. /// Can be used when that element shows a toggle or a popUp if press. /// </summary> /// <param name="className1"></param> /// <param name="className2"></param> /// <param name="duration"></param> public static void LongPressByClassName(string className1, string className2, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement firstElem = GetControl.ByClass(className1); AppiumWebElement secondElem = GetControl.ByClass(className2); action.LongPress(firstElem).Wait(duration).MoveTo(secondElem).Release().Perform(); } catch (Exception ex) { Assert.Fail("LongPressByClassName threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // In charge of the instantiation of single Action functions // ************ --------------- ************ #region SINGLE ACTION FUNCTIONS #region MOVE ACTIONS /// <summary> /// Emulates the swipe till the end of a specific element over the X & Y axis. /// </summary> /// <param name="className"> className of the element to swipe </param> /// <param name="direction"> represents the Enum in Share class </param> /// <param name="duration"> time to wait until swipe to position </param> public static void SwipeByClassName(string className, Direction direction = Direction.Up, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement scrollView = GetControl.ByClass(className); var initialWidth = scrollView.Size.Width - (scrollView.Size.Width - 5); var initialHeight = scrollView.Size.Height - (scrollView.Size.Height - 5); var centerWidth = scrollView.Size.Width / 2; var centerHeight = scrollView.Size.Height / 2; var endWidth = scrollView.Size.Width - 5; var endHeight = scrollView.Size.Height - 5; switch (direction) { case Direction.Up: action.Press(scrollView, centerWidth, initialHeight).Wait(duration).MoveTo(scrollView, centerWidth, endHeight).Release().Perform(); break; case Direction.Down: action.Press(scrollView, centerWidth, endHeight).Wait(duration).MoveTo(scrollView, centerWidth, initialHeight).Release().Perform(); break; case Direction.Left: action.Press(scrollView, initialWidth, centerHeight).Wait(duration).MoveTo(scrollView, endWidth, centerHeight).Release().Perform(); break; case Direction.Right: action.Press(scrollView, endWidth, centerHeight).Wait(duration).MoveTo(scrollView, initialWidth, centerHeight).Release().Perform(); break; } } catch (Exception ex) { Assert.Fail("SwipeByClassName threw an exception: " + ex.Message); } }
/// <summary> /// Performs the touch-action sequence. /// </summary> /// <param name="touchAction">Touch-action sequence to perform.</param> public void PerformTouchAction(ITouchAction touchAction) { // mock method - should not do anything }