示例#1
0
        public static void DrawCircle(WindowsDriver <WindowsElement> session)
        {
            // Draw a circle with radius 300 and 40 (x, y) points
            const int radius = 300;
            const int points = 40;

            // Select the Brushes toolbox to have the Brushes Pane sidebar displayed and ensure that Marker is selected
            session.FindElementByAccessibilityId("Toolbox").FindElementByAccessibilityId("TopBar_ArtTools").Click();
            session.FindElementByAccessibilityId("SidebarWrapper").FindElementByAccessibilityId("Marker3d").Click();

            // Locate the drawing surface
            WindowsElement inkCanvas = session.FindElementByAccessibilityId("InteractorFocusWrapper");

            // Draw the circle with a single touch actions
            OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchContact = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
            ActionSequence touchSequence = new ActionSequence(touchContact, 0);

            touchSequence.AddAction(touchContact.CreatePointerMove(inkCanvas, 0, -radius, TimeSpan.Zero));
            touchSequence.AddAction(touchContact.CreatePointerDown(PointerButton.TouchContact));
            for (double angle = 0; angle <= 2 * Math.PI; angle += 2 * Math.PI / points)
            {
                touchSequence.AddAction(touchContact.CreatePointerMove(inkCanvas, (int)(Math.Sin(angle) * radius), -(int)(Math.Cos(angle) * radius), TimeSpan.Zero));
            }
            touchSequence.AddAction(touchContact.CreatePointerUp(PointerButton.TouchContact));
            session.PerformActions(new List <ActionSequence> {
                touchSequence
            });

            // Verify that the drawing operations took place
            WindowsElement undoButton = session.FindElementByAccessibilityId("UndoIcon");
        }
示例#2
0
        private void Tap(int xOffset, int yOffset)
        {
            System.Threading.Thread.Sleep(100);
            //the screenshot can take the place of sleeping instead

            Console.WriteLine("Tap start");
            PointerInputDevice touch         = new PointerInputDevice(PointerKind.Touch);
            ActionSequence     touchSequence = new ActionSequence(touch, 0);

            touchSequence.AddAction(touch.CreatePointerMove(CoordinateOrigin.Pointer, xOffset, yOffset, TimeSpan.Zero));
            touchSequence.AddAction(touch.CreatePointerDown(PointerButton.TouchContact));
            touchSequence.AddAction(touch.CreatePointerUp(PointerButton.TouchContact));
            List <ActionSequence> actions = new List <ActionSequence> {
                touchSequence
            };

            session.PerformActions(actions);

            ////String filename = "Tap_" + System.DateTime.Now.ToString("yyyymmdd-HHmm-ssfff") + "_" + xOffset + "_" + yOffset + ".png";
            ////Bitmap bmp = imageComparer.ScreenshotLockBits(width, height);
            ////bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);


            Console.WriteLine("Echo: " + actions[actions.Count - 1].ToString());
            Console.WriteLine("Tap end");
        }
示例#3
0
        private void Tap(int xOffset, int yOffset)
        {
            System.Threading.Thread.Sleep(100);
            //the screenshot can take the place of sleeping instead

            Console.WriteLine("Tap start");
            PointerInputDevice touch         = new PointerInputDevice(PointerKind.Touch);
            ActionSequence     touchSequence = new ActionSequence(touch, 0);

            touchSequence.AddAction(touch.CreatePointerMove(CoordinateOrigin.Pointer, xOffset, yOffset, TimeSpan.Zero));
            touchSequence.AddAction(touch.CreatePointerDown(PointerButton.TouchContact));
            touchSequence.AddAction(touch.CreatePointerUp(PointerButton.TouchContact));
            List <ActionSequence> actions = new List <ActionSequence> {
                touchSequence
            };

            session.PerformActions(actions);

            if (record)
            {
                String eventFolder = installDirectory + "\\" + currentEventName;
                String filename    = eventFolder + "\\" + currentEventName + "_" + currentEventTapCount + ".png";
                currentEventTapCount++;
                Bitmap bmp = imageComparer.ScreenshotLockBits(width, height);
                bmp.Save(filename, ImageFormat.Png);
                bmp.Dispose();//doesn't work?
            }

            Console.WriteLine("Echo: " + actions[actions.Count - 1].ToString());
            Console.WriteLine("Tap end");
        }
        public void DrawBasicSquare()
        {
            Point canvasCoordinate = inkCanvas.Coordinates.LocationInViewport;
            Size  squareSize       = new Size(inkCanvas.Size.Width * 3 / 5, inkCanvas.Size.Height * 3 / 5);
            Point A = new Point(canvasCoordinate.X + inkCanvas.Size.Width / 5, canvasCoordinate.Y + inkCanvas.Size.Height / 5);

            // A        B
            //  ┌──────┐   Draw a basic ABCD square using Pen through the Actions API
            //  │      │   in viewport(default) origin mode:
            //  │      │   - X is absolute horizontal position in the session window
            //  └──────┘   - Y is absolute vertical position in the session window
            // D        C
            PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
            ActionSequence     sequence  = new ActionSequence(penDevice, 0);

            // Draw line AB from point A to B
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X + squareSize.Width, A.Y, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line BC from point B to C
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X + squareSize.Width, A.Y + squareSize.Height, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line CD from point C to D
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y + squareSize.Height, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // Draw line DA from point D to A
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            newStickyNoteSession.PerformActions(new List <ActionSequence> {
                sequence
            });

            try
            {
                var result = newStickyNoteSession.FindElementByAccessibilityId("RichEditBox");
                Assert.Fail("RichEditBox should not be defined anymore after a pen input is successfully performed.");
            }
            catch { }
        }
示例#5
0
        private void ScrollToEnd(WindowsDriver <WindowsElement> driver, AppiumWebElement element)
        {
            var            input       = new PointerInputDevice(PointerKind.Mouse);
            ActionSequence scrollToEnd = new ActionSequence(input);

            scrollToEnd.AddAction(input.CreatePointerMove(element, 0, 0, TimeSpan.Zero));
            scrollToEnd.AddAction(input.CreatePointerDown(MouseButton.Middle));
            scrollToEnd.AddAction(input.CreatePointerMove(element, 0, 600, TimeSpan.FromMilliseconds(200)));
            scrollToEnd.AddAction(input.CreatePointerUp(MouseButton.Middle));
            driver.PerformActions(new List <ActionSequence>()
            {
                scrollToEnd
            });
        }
        private void FlickUp(WindowsDriver <WindowsElement> driver, AppiumWebElement element)
        {
            var            input   = new PointerInputDevice(PointerKind.Touch);
            ActionSequence FlickUp = new ActionSequence(input);

            FlickUp.AddAction(input.CreatePointerMove(element, 0, 0, TimeSpan.Zero));
            FlickUp.AddAction(input.CreatePointerDown(MouseButton.Left));
            FlickUp.AddAction(input.CreatePointerMove(element, 0, -300, TimeSpan.FromMilliseconds(200)));
            FlickUp.AddAction(input.CreatePointerUp(MouseButton.Left));
            driver.PerformActions(new List <ActionSequence>()
            {
                FlickUp
            });
        }
示例#7
0
        public static void DrawTriangle(WindowsDriver <WindowsElement> session)
        {
            OpenQA.Selenium.Appium.Interactions.PointerInputDevice penDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Pen);

            // Select the Brushes toolbox to have the Brushes Pane sidebar displayed and ensure that Marker is selected
            session.FindElementByAccessibilityId("Toolbox").FindElementByAccessibilityId("TopBar_ArtTools").Click();
            session.FindElementByAccessibilityId("SidebarWrapper").FindElementByAccessibilityId("PixelPencil3d").Click();

            // Locate the drawing surface
            WindowsElement inkCanvas = session.FindElementByAccessibilityId("InteractorFocusWrapper");

            Point    canvasCoordinate = inkCanvas.Coordinates.LocationInViewport;
            Size     squareSize       = new Size(inkCanvas.Size.Width * 3 / 5, inkCanvas.Size.Height * 3 / 5);
            Point    A       = new Point(canvasCoordinate.X + inkCanvas.Size.Width / 5, canvasCoordinate.Y + inkCanvas.Size.Height / 5);
            TimeSpan howFast = TimeSpan.FromMilliseconds(500.0);

            ActionSequence sequence = new ActionSequence(penDevice, 0);

            var halfWidth  = (inkCanvas.Size.Width / 2) + 100;
            var halfHeight = (inkCanvas.Size.Height / 2) + 500;

            // left base
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth, halfHeight, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.TouchContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth - 1000, halfHeight, howFast));
            sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // right base
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth, halfHeight, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerDown(PointerButton.TouchContact));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth + 1000, halfHeight, howFast));
            //sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));

            // right top
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth + 1000, halfHeight, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth, halfHeight - 1000, howFast));

            // left top
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth, halfHeight - 1000, TimeSpan.Zero));
            sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, halfWidth - 1000, halfHeight, howFast));


            session.PerformActions(new List <ActionSequence> {
                sequence
            });
        }
        public void AddNewItemWithNewCategory()
        {
            var capabilities = new AppiumOptions();

            capabilities.AddAdditionalCapability(MobileCapabilityType.App, "8b831c56-bc54-4a8b-af94-a448f80118e7_sezxftbtgh66j!App");
            capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows");
            capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC");

            var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build();

            _appiumLocalService.Start();
            var driver = new WindowsDriver <WindowsElement>(_appiumLocalService, capabilities);

            // Create new Category item first
            var categoryButton = driver.FindElement(MobileBy.AccessibilityId("AddCategory"));

            categoryButton.Click();

            // fill out the form for a new category
            var categoryName = driver.FindElement(MobileBy.AccessibilityId("categoryName"));

            categoryName.Clear();
            categoryName.SendKeys("New category from automation");

            //save category
            var saveCategory = driver.FindElement(MobileBy.AccessibilityId("Save"));

            saveCategory.Click();

            var el1 = driver.FindElementByAccessibilityId("Add");

            el1.Click();

            var elItemText = driver.FindElementByAccessibilityId("ItemText");

            elItemText.Clear();
            elItemText.SendKeys("This is a new Item");

            var elItemDetail = driver.FindElementByAccessibilityId("ItemDescription");

            elItemDetail.Clear();
            elItemDetail.SendKeys("These are the details");

            var elItemCategory = driver.FindElement(MobileBy.AccessibilityId("ItemCategory"));

            elItemCategory.Click();

            var categoryListItem = elItemCategory.FindElement(By.Name("New category from automation"));

            categoryListItem.Click();

            var elSave = driver.FindElementByAccessibilityId("Save");

            elSave.Click();
            elSave.ClearCache();

            //wait for progress bar to disapear
            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(500)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.Until(d => d.FindElementByName("Second item"));

            var listview = driver.FindElementByAccessibilityId("ItemsListView");

            //now use wait to scroll untill we find item
            wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(500)
            };
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));

            var elementfound = wait.Until(d =>
            {
                var input = new PointerInputDevice(PointerKind.Touch);
                ActionSequence FlickUp = new ActionSequence(input);
                FlickUp.AddAction(input.CreatePointerMove(listview, 0, 0, TimeSpan.Zero));
                FlickUp.AddAction(input.CreatePointerDown(MouseButton.Left));
                FlickUp.AddAction(input.CreatePointerMove(listview, 0, -300, TimeSpan.FromMilliseconds(200)));
                FlickUp.AddAction(input.CreatePointerUp(MouseButton.Left));
                driver.PerformActions(new List <ActionSequence>()
                {
                    FlickUp
                });

                return(d.FindElementByName("This is a new Item"));
            });

            Assert.IsTrue(elementfound != null);

            driver.CloseApp();
        }
示例#9
0
        // draws a given digit on canvas
        // (0,0)  (x,0)
        //  ┌───────┐
        //  │       │   In viewport(default) origin mode:
        //  │       │   - X is absolute horizontal position in the session window
        //  └───────┘   - Y is absolute vertical position in the session window
        // (y,0)  (x,y) - (0,0) is on the top left corner, and (x,y) is on bottom right corner
        public void Draw(uint digit)
        {
            PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
            ActionSequence     sequence  = new ActionSequence(penDevice, 0);
            Point canvasCoordiante       = inkCanvas.Coordinates.LocationInViewport;

            switch (digit)
            {
            case 0:
            {
                // drawing a circle around a center
                // start from cos(0), sin(0)
                var centerX  = canvasCoordiante.X + inkCanvas.Size.Width / 2;
                var centerY  = canvasCoordiante.Y + inkCanvas.Size.Height / 2;
                var radius   = inkCanvas.Size.Width / 3;
                var stepSize = 10;
                DrawCircle(penDevice, sequence, centerX, centerY, radius, stepSize);
                break;
            }

            case 1:
                // (0,0)   (x,0)
                //  ┌───────┐   Draw a basic line from top to bottom.
                //  │   |   │
                //  │   |   │
                //  └───────┘
                // (y,0)   (x,y)
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + inkCanvas.Size.Width / 2,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 9,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + inkCanvas.Size.Width / 2,
                                       canvasCoordiante.Y + 8 * inkCanvas.Size.Height / 9,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
                break;

            case 2:
                break;

            case 3:
                break;

            case 4:
                // (0,0)   (x,0)
                //  ┌───────┐
                //  │  / |  │
                //  │ ───── |
                //  │    |  │
                //  └───────┘
                // (y,0)   (x,y)
                // vertical line
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 2 * inkCanvas.Size.Width / 3,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 8,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 2 * inkCanvas.Size.Width / 3,
                                       canvasCoordiante.Y + 5 * inkCanvas.Size.Height / 6,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
                // horizontal line
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + inkCanvas.Size.Width / 4,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 2,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 3 * inkCanvas.Size.Width / 4,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 2,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
                // diagonal
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + inkCanvas.Size.Width / 4,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 2,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 2 * inkCanvas.Size.Width / 3,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 8,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
                break;

            case 5:
                break;

            case 6:
                break;

            case 7:
                // (0,0)   (x,0)
                //  ┌───────┐
                //  │ ───── |
                //  │    /  │
                //  │   /   │
                //  └───────┘
                // (y,0)   (x,y)
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + inkCanvas.Size.Width / 6,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 6,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 6 * inkCanvas.Size.Width / 6,
                                       canvasCoordiante.Y + inkCanvas.Size.Height / 6,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerMove(
                                       CoordinateOrigin.Viewport,
                                       canvasCoordiante.X + 3 * inkCanvas.Size.Width / 6,
                                       canvasCoordiante.Y + 5 * inkCanvas.Size.Height / 6,
                                       TimeSpan.Zero));
                sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
                break;

            case 8:
            {
                // two circles. Smaller circle on top of bigger circle
                var centerX = canvasCoordiante.X + inkCanvas.Size.Width / 2;
                var centerY = canvasCoordiante.Y + inkCanvas.Size.Height / 5 + inkCanvas.Size.Height / 10;
                var radius  = inkCanvas.Size.Height / 6;

                var stepSize = 10;
                DrawCircle(penDevice, sequence, centerX, centerY, radius, stepSize);
                centerX = canvasCoordiante.X + inkCanvas.Size.Width / 2;
                centerY = canvasCoordiante.Y + 3 * inkCanvas.Size.Height / 5 + inkCanvas.Size.Height / 10;
                radius  = Convert.ToInt32(1.4 * inkCanvas.Size.Height / 6);
                DrawCircle(penDevice, sequence, centerX, centerY, radius, stepSize);
                break;
            }

            case 9:
                break;

            default:
                Assert.Fail("wrong argument");
                break;
            }
            session.PerformActions(new List <ActionSequence> {
                sequence
            });
        }