Пример #1
0
        public override void PerformStep()
        {
            TouchAction touch = new TouchAction(TestAppMain.Instance.Connector.Driver);

            touch.Tap(_tapCordinates.X, _tapCordinates.Y);
            touch.Perform();
        }
Пример #2
0
 private void thaTimBtn_Click(object sender, EventArgs e)
 {
     thaTimBtn.Enabled  = false;
     commentBtn.Enabled = false;
     if (string.IsNullOrEmpty(thoigianthatim.Text))
     {
         MessageBox.Show("vui lòng nhập thời gian thả tim !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         var thoigianthatims = int.Parse(thoigianthatim.Text);
         foreach (var driver in androidDrivers)
         {
             TouchAction actions = new TouchAction(driver);
             for (int i = 0; i < thoigianthatims; i++)
             {
                 actions.Tap(500, 500);
                 actions.Perform();
                 Thread.Sleep(500);
             }
         }
     }
     thaTimBtn.Enabled  = true;
     commentBtn.Enabled = true;
 }
Пример #3
0
        public void MoveToTestCase()
        {
            IOSDriver <IWebElement> driver  = new IOSDriver <IWebElement>(defaultUri, capabilities);
            RequestProcessor        re      = setupTouchAction();
            IWebElement             element = driver.FindElementByIosUIAutomation(".elements()");

            ITouchAction a;

            a = new TouchAction(driver)
                .MoveTo(element, 50, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}");

            a = new TouchAction(driver)
                .MoveTo(element, 0.5, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}");

            a = new TouchAction(driver)
                .MoveTo(0.5, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"x\":0.5,\"y\":75}}]}");

            a = new TouchAction(driver)
                .MoveTo(element);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\"}}]}");
        }
        public static void DrawRectagle(Point upperLeft, int height, int width)
        {
            // Using Touch Action Classes
            TouchAction tAction1 = new TouchAction(AppiumDriver.Instance);

            //TouchAction tAction2 = new TouchAction(AppiumDriver.Instance);
            //TouchAction tAction3 = new TouchAction(AppiumDriver.Instance);
            //TouchAction tAction4 = new TouchAction(AppiumDriver.Instance);
            //TouchAction tAction5 = new TouchAction(AppiumDriver.Instance);
            //TouchAction tAction6 = new TouchAction(AppiumDriver.Instance);

            // perform the swipe
            tAction1.Press(upperLeft.X, upperLeft.Y);
            tAction1.MoveTo(upperLeft.X, upperLeft.Y + height);
            tAction1.MoveTo(upperLeft.X + width, upperLeft.Y + height);
            tAction1.MoveTo(upperLeft.X + width, upperLeft.Y);
            tAction1.MoveTo(upperLeft.X, upperLeft.Y);
            tAction1.Release();

            //MultiAction mAction = new MultiAction(AppiumDriver.Instance);
            //mAction.Add(tAction1).Add(tAction2).Add(tAction3).Add(tAction4).Add(tAction5).Add(tAction6);
            tAction1.Perform();

            // perform the swipe
            //tAction1.Press(upperLeft.X, upperLeft.Y).MoveTo(upperLeft.X, upperLeft.Y + height).MoveTo(upperLeft.X + width, upperLeft.Y + height).MoveTo(upperLeft.X + width, upperLeft.Y).MoveTo(upperLeft.X, upperLeft.Y).Release().Perform();
        }
        public void LongPressTestCase()
        {
            RequestProcessor re      = setupTouchAction();
            IWebElement      element = driver.FindElementByIosUIAutomation(".elements()");

            ITouchAction a;

            a = new TouchAction(driver)
                .LongPress(element, 50, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}");

            a = new TouchAction(driver)
                .LongPress(element, 0.5, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}");

            a = new TouchAction(driver)
                .LongPress(0.5, 75);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"x\":0.5,\"y\":75}}]}");

            a = new TouchAction(driver)
                .LongPress(element);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\"}}]}");
        }
Пример #6
0
        public void SwipeDisplayElements(Point fromPoint,
                                         Point toPoint,
                                         int duration,
                                         int waitingInterval,
                                         PageCustomProcess processPageFunction)
        {
            List <AndroidElement> allElements    = new List <AndroidElement>();
            List <string>         allElementKeys = new List <string>();
            int pageIndex = 0;

            while (1 == 1)
            {
                Thread.Sleep(waitingInterval);
                bool goon = processPageFunction(pageIndex);
                if (goon)
                {
                    try
                    {
                        TouchAction action = new TouchAction(Driver);
                        action.Press(fromPoint.X, fromPoint.Y).Wait(duration).MoveTo(toPoint.X, toPoint.Y).Release();
                        action.Perform();
                    }
                    catch (Exception ex)
                    {
                        //此处经常运行出错,但是实际操作并没出现什么异常,比较奇怪
                    }
                }
                else
                {
                    break;
                }
                pageIndex++;
            }
        }
Пример #7
0
        public void Click(Point point)
        {
            TouchAction action = new TouchAction(Driver);

            action.Press(point.X, point.Y).Release();
            action.Perform();
        }
        //move the screen from element to another.
        public void Swipe(string StartId, params string[] arguments)
        {
            try
            {
                if (arguments != null && 1 == arguments.Length)
                {
                    IWebElement endElement   = GetElement(arguments[0]);
                    IWebElement startElement = GetElement(StartId);

                    int xEnd = endElement.Location.X;
                    int yEnd = endElement.Location.Y;

                    int xStart = startElement.Location.X;
                    int yStart = startElement.Location.Y;

                    TouchAction action = new TouchAction(_driver);
                    action.Press(xStart, yStart).MoveTo(xEnd - xStart, yEnd - yStart).Perform();
                    //_driver.Swipe(xStart, yStart, xEnd, yEnd, 1000);
                }
                else if (arguments != null && arguments.Length > 1)
                {
                    IWebElement   startElement = GetElement(StartId);
                    Point         startPoint   = new Point(startElement.Location.X, startElement.Location.Y);
                    IList <Point> swipePoints  = new List <Point>();
                    //IList<IWebElement> swipeElements = new List<IWebElement>();
                    foreach (string s in arguments)
                    {
                        IWebElement element = GetElement(s);
                        swipePoints.Add(new Point(element.Location.X, element.Location.Y));
                    }
                    TouchAction action = new TouchAction(_driver);
                    action.Press(startPoint.X, startPoint.Y);
                    for (int i = 0; i < swipePoints.Count; i++)
                    {
                        if (i == 0)
                        {
                            action.MoveTo(swipePoints[i].X - startPoint.X, swipePoints[i].Y - startPoint.Y);
                        }
                        else
                        {
                            action.MoveTo(swipePoints[i].X - swipePoints[i - 1].X, swipePoints[i].Y - swipePoints[i - 1].Y);
                        }
                    }
                    action.Perform();
                }
                else
                {
                    throw new Exception("Swipe operator miss some parameters");
                }
            }
            catch
            {
                if (arguments.Contains("-i"))
                {
                    return;
                }
                throw;
            }
        }
Пример #9
0
        public void SimpleActionTestCase()
        {
            IWebElement  el     = driver.FindElementByAccessibilityId("ComputeSumButton");
            ITouchAction action = new TouchAction(driver);

            action.Press(el, 10, 10).Release();
            action.Perform();
        }
Пример #10
0
        //public static void swip(int x1, int y1, int x2, int y2)
        //{

        //    Swipe(x1, y1, x1, y1-(y2 - y1));

        //}

        //坐标点击
        public void Tap(int x, int y)
        {
            ITouchAction a2 = new TouchAction(Driver)
                              .Press(x, y)
                              .Wait(50)
                              .Release();

            a2.Perform();
        }
Пример #11
0
        public override void PerformStep()
        {
            TouchAction touch = new TouchAction(TestAppMain.Instance.Connector.Driver);

            touch.Press(_swipeStartCordinates.X, _swipeStartCordinates.Y);
            touch.MoveTo(_swipeStopCordinates.X, _swipeStopCordinates.Y);
            touch.Release();
            touch.Perform();
        }
Пример #12
0
        public static void Swipe(this IWebDriver driver, int startX, int startY, int endX, int endY, int duration)
        {
            ITouchAction touchAction = new TouchAction((IPerformsTouchActions)driver)
                                       .Press(startX, startY)
                                       .MoveTo(endX, endY)
                                       .Release();

            touchAction.Perform();
        }
Пример #13
0
        //自定义滑动
        public void Swipe(int startX, int startY, int endX, int endY, int duration)
        {
            ITouchAction touchAction = new TouchAction(Driver)
                                       .Press(startX, startY)
                                       .Wait(duration)
                                       .MoveTo(endX, endY)
                                       .Release();

            touchAction.Perform();
        }
        protected void DoSwipe(int startx, int starty, int endx, int endy, int duration)
        {
            TouchAction touchAction = new TouchAction(this);

            // appium converts Press-wait-MoveTo-Release to a swipe action
            touchAction.Press(startx, starty).Wait(duration)
            .MoveTo(endx, endy).Release();

            touchAction.Perform();
        }
        public void ReleaseTestCase()
        {
            RequestProcessor re = setupTouchAction();
            ITouchAction     a;

            a = new TouchAction(driver)
                .Release();
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"release\"}]}");
        }
Пример #16
0
        public void Click(int x, int y, int delay)
        {
            var touchAction = new TouchAction(_driver);

            touchAction.Press(x, y);
            touchAction.Wait(500);
            touchAction.Release();
            touchAction.Perform();
            System.Threading.Thread.Sleep(delay);
        }
        public void Swipe(IPerformsTouchActions touchActionsPerformer, int startx, int starty, int endx, int endy, int duration)
        {
            TouchAction touchAction = new TouchAction(touchActionsPerformer);

            // appium converts Press-wait-MoveTo-Release to a swipe action
            touchAction.Press(startx, starty).Wait(duration)
            .MoveTo(endx, endy).Release();

            touchAction.Perform();
        }
Пример #18
0
        public void ScrollUsingTouchActions(int xStart, int yStart, int xFinal, int yFinal)
        {
            TouchAction action = new TouchAction(DriverFactory.GetDriver());

            action.Press(xStart, yStart);
            action.MoveTo(xFinal, yFinal);
            action.Wait(100);
            action.Perform();
            action.Release();
            ExtentReportHelpers.AddTestInfo(3, "");
        }
Пример #19
0
        private void LongPress(AndroidElement element)
        {
            var topCorner = element.Location;
            var centerX   = topCorner.X + element.Size.Width / 2;
            var centerY   = topCorner.Y + element.Size.Height / 2;

            var touch = new TouchAction(driver);

            touch.Press(centerX, centerY).Wait(2000).MoveTo(centerX, centerY).Release();
            touch.Perform();
        }
Пример #20
0
        public void ReleaseTestCase()
        {
            IOSDriver <IWebElement> driver = new IOSDriver <IWebElement>(defaultUri, capabilities);
            RequestProcessor        re     = setupTouchAction();
            ITouchAction            a;

            a = new TouchAction(driver)
                .Release();
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"release\"}]}");
        }
Пример #21
0
        protected void ZZZZScrollUsingTouchActions(string direcao)
        {
            TouchAction action = new TouchAction(DriverFactory.GetDriver());

            action.Press(100, 300);
            action.MoveTo(300, 300);
            action.Perform();
            action.Release();
            ExtentReportHelpers.AddTestInfo(3, "");

            // driver.ExecuteScript("mobile:scroll", new Dictionary<string, string> { { "direction", "left" } });
        }
Пример #22
0
 public bool touch_outside_element_by_id()
 {
     try
     {
         ITouchAction touch = new TouchAction(driver).Tap(driver.FindElementById(menu_pane_id).Size.Width + 1, (int)(driver.FindElementById(menu_pane_id).Size.Height / 2));
         touch.Perform();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public void CheckTap(IPerformsTouchActions performer)
        {
            TouchAction t = new TouchAction(performer);

            t.Tap(accessibility);
            t.Perform();

            MultiAction m = new MultiAction(performer);

            m.Add(new TouchAction().Tap(customView));
            m.Add(new TouchAction(performer).Tap(clickable));
            m.Perform();
        }
Пример #24
0
        public void CheckTap(IPerformsTouchActions performer)
        {
            var t = new TouchAction(performer);

            t.Tap(_accessibility);
            t.Perform();

            var m = new MultiAction(performer);

            m.Add(new TouchAction(performer).Tap(_customView));
            m.Add(new TouchAction(performer).Tap(_clickable));
            m.Perform();
        }
Пример #25
0
        public void SimpleActionTestCase()
        {
            driver.FindElementById("TextField1").Clear();
            driver.FindElementById("TextField1").SendKeys("1");
            driver.FindElementById("TextField2").Clear();
            driver.FindElementById("TextField2").SendKeys("3");
            IWebElement  el     = driver.FindElementByAccessibilityId("ComputeSumButton");
            ITouchAction action = new TouchAction(driver);

            action.Press(el, 10, 10).Release();
            action.Perform();
            const string str = "4";

            Assert.AreEqual(driver.FindElementByXPath("//*[@name = \"Answer\"]").Text, str);
        }
        public void WaitTestCase()
        {
            RequestProcessor re = setupTouchAction();
            ITouchAction     a;

            a = new TouchAction(driver)
                .Wait(1000);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\",\"options\":{\"ms\":1000}}]}");

            a = new TouchAction(driver)
                .Wait();
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\"}]}");
        }
Пример #27
0
        public void WaitTestCase()
        {
            IOSDriver <IWebElement> driver = new IOSDriver <IWebElement>(defaultUri, capabilities);
            RequestProcessor        re     = setupTouchAction();
            ITouchAction            a;

            a = new TouchAction(driver)
                .Wait(1000);
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\",\"options\":{\"ms\":1000}}]}");

            a = new TouchAction(driver)
                .Wait();
            a.Perform();
            Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\"}]}");
        }
Пример #28
0
        public void CheckAppRunning()
        {
            _driver.PressKeyCode(AndroidKeyCode.Home);
            Thread.Sleep(1000);

            var clickableCountBefore = _driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)").Count;

            var pressAndHold = new TouchAction(_driver);

            var action = pressAndHold.LongPress(500, 700);

            //SUPER DIRTY HACK
            var stepsField = pressAndHold.GetType()
                             .GetField("steps", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var field = (stepsField.GetValue(pressAndHold) as IEnumerable <object>).ElementAt(0);
            var dic   = field.GetType()
                        .GetField("parameters", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
                        .GetValue(field) as IDictionary;

            dic["action"] = "longPress";

            action.Perform();

            var widgetsButton = _driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"WIDGETS\")");

            widgetsButton.Click();


            var kateSmall = _driver.FindElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                                                                    + "new UiSelector().textContains(\"Kate Mobile 1x1\"));");



            var pressAndHoldKateWidget = new TouchAction(_driver)
                                         .Press(kateSmall.Location.X + 10, kateSmall.Location.Y + 20).Wait(500).MoveTo(100, -200)
                                         .Wait(2000).Release();

            pressAndHoldKateWidget.Perform();


            var clickableCountAfter = _driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)").Count;

            Assert.True(clickableCountAfter > clickableCountBefore);
        }
        protected void Click(IWebElement element)
        {
            AguardarLoading();
            WebDriverException possibleWebDriverException = null;
            Stopwatch          timeOut = new Stopwatch();

            timeOut.Start();
            while ((((int)timeOut.Elapsed.TotalSeconds) / 1000) <= GlobalParameters.CONFIG_DEFAULT_TIMEOUT_IN_SECONDS)
            {
                try
                {
                    TouchAction action = new TouchAction(DriverFactory.INSTANCE);
                    action.Tap(element);
                    // action.SingleTap(element);
                    action.Perform();
                    action.Release();
                    ExtentReportHelpers.AddTestInfo(3, "");
                    timeOut.Stop();
                    return;
                }
                catch (StaleElementReferenceException e)
                {
                    continue;
                }
                catch (WebDriverException e)
                {
                    possibleWebDriverException = e;
                    if (e.Message.Contains("Other element would receive the click"))
                    {
                        continue;
                    }
                    throw e;
                }
            }
            try
            {
                throw new Exception(possibleWebDriverException.Message);
            }
            catch (Exception e)
            {
                e.StackTrace.ToString();
            }
        }