Beispiel #1
0
        // ************ DATE 10/16/2020 ************
        // ***** IMPORTANT: All Click by CLASSNAME will search an element and then click it.
        // ************ --------------- ************
        #region BY CLASSNAME


        /// <summary>
        /// Finds the first element in the screen that matches the className criteria and clicks it.
        /// </summary>
        /// <param name="className">ClassName to find the object</param>
        public static void ByClassName(string className)
        {
            try
            {
                var element = GetControl.ByClass(className);
                element.Click();
            }
            catch (Exception ex)
            {
                Assert.Fail("ClickByClassName threw an exception: " + ex.Message);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Finds the first element in the screen that matches the className criteria and then simulates typing text into the element.
 /// </summary>
 /// <param name="className">ClassName to find the object</param>
 /// <param name="text">Text to match a specific element</param>
 /// <param name="inputText">The text to type into the element.</param>
 public static void ByClassName(string className, string text, string inputText)
 {
     try
     {
         var element = GetControl.ByClass(className, text);
         element.Clear();
         element.SendKeys(inputText);
     }
     catch (Exception ex)
     {
         Assert.Fail("InputByClassName threw an exception: " + ex.Message);
     }
 }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
        /// <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);
            }
        }
Beispiel #5
0
        /// <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);
            }
        }
Beispiel #6
0
        /// <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);
            }
        }
Beispiel #7
0
        // ************ 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);
            }
        }