private void AnimateMouseThroughPoints(IEnumerable <Point> points)
 {
     foreach (var point in points)
     {
         Mouse.MoveTo(point);
         Delay(5);
     }
 }
        private void DrawSineWaveOnCanvas(AutomationElement canvasElement)
        {
            var bounds = canvasElement.Current.BoundingRectangle;

            var left   = (int)bounds.Left;
            int center = (int)(bounds.Y + bounds.Height / 2);

            Mouse.MoveTo(new Point(left, center));
            Mouse.Down(MouseButton.Left);

            AnimateMouseThroughPoints(GetPointsForSineWave(left, (int)bounds.Right, center));

            Mouse.Up(MouseButton.Left);
        }
        private void DrawSpirographWaveOnCanvas(AutomationElement canvasElement)
        {
            var bounds = canvasElement.Current.BoundingRectangle;

            var centerX = (int)(bounds.X + bounds.Width / 2);
            int centerY = (int)(bounds.Y + bounds.Height / 2);

            var points = GetPointsForSpirograph(centerX, centerY, 1.02, 5, 2, 0, 300);

            Mouse.MoveTo(points.First());
            Mouse.Down(MouseButton.Left);

            AnimateMouseThroughPoints(points);

            Mouse.Up(MouseButton.Left);
        }
        private void AutomateMainWindow(AutomationElement mainWindow)
        {
            // find the Paint.Net drawing Canvas
            var canvas = mainWindow.FindDescendentByIdPath(new[] { "appWorkspace", "workspacePanel", "DocumentView", "scrollableCanvasControl", "canvasView" });

            DrawSpirographWaveOnCanvas(canvas);

            // the the audience appreciate the masterpiece!
            Delay(5000);

            var closeButton = mainWindow.FindDescendentByIdPath(new[] { "TitleBar", "Close" });

            closeButton.GetInvokePattern().Invoke();

            // give chance for the close dialog to open
            Delay();

            var dontSaveButton = mainWindow.FindDescendentByNamePath(new[] { "Unsaved Changes", "Don't Save" });

            Mouse.MoveTo(dontSaveButton.GetClickablePoint().ToDrawingPoint());
            Mouse.Click(MouseButton.Left);
        }