Example #1
0
        public async Task VerifyFocusProperty()
        {
            var systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.Black,
            };

            var editField = new TextEditWidget(pixelWidth: 200)
            {
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Center,
            };

            systemWindow.AddChild(editField);

            Task TestToRun(AutomationRunner testRunner)
            {
                UiThread.RunOnIdle(editField.Focus);
                testRunner.WaitFor(() => editField.ContainsFocus);
                //if (!editField.ContainsFocus) { System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); }
                // NOTE: Okay. During parallel testing, it seems that the avalanche of windows causes test UIs to lose control focus and get confused.
                Assert.IsTrue(editField.ContainsFocus, "Focused property should be true after invoking Focus method");

                return(Task.CompletedTask);
            }

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, TestToRun);
        }
Example #2
0
        public async Task VerifyFocusProperty()
        {
            SystemWindow systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.Black,
            };

            var editField = new TextEditWidget(pixelWidth: 200)
            {
                HAnchor = HAnchor.ParentCenter,
                VAnchor = VAnchor.ParentCenter,
            };

            systemWindow.AddChild(editField);

            AutomationTest testToRun = (testRunner) =>
            {
                UiThread.RunOnIdle(editField.Focus);
                testRunner.WaitUntil(() => editField.Focused, 3);
                Assert.IsTrue(editField.Focused, "Focused property should be true after invoking Focus method");

                return(Task.FromResult(0));
            };

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testToRun, 10);
        }
        public async Task GetWidgetByNameTestNoRegionSingleWindow()
        {
            // single system window
            int leftClickCount = 0;

            AutomationTest testToRun = (testRunner) =>
            {
                testRunner.ClickByName("left");
                testRunner.Wait(.5);

                Assert.IsTrue(leftClickCount == 1, "Got left button click");

                return(Task.FromResult(0));
            };

            SystemWindow buttonContainer = new SystemWindow(300, 200);

            Button leftButton = new Button("left", 10, 40);

            leftButton.Name   = "left";
            leftButton.Click += (sender, e) => { leftClickCount++; };
            buttonContainer.AddChild(leftButton);

            await AutomationRunner.ShowWindowAndExecuteTests(buttonContainer, testToRun, 10);
        }
Example #4
0
        public async Task VerifyFocusMakesTextWidgetEditable()
        {
            TextEditWidget editField    = null;
            var            systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.Black,
            };

            Task TestToRun(AutomationRunner testRunner)
            {
                UiThread.RunOnIdle(editField.Focus);

                testRunner.Type("Test Text");

                testRunner.Delay(1);
                Assert.IsTrue(editField.Text == "Test Text", "validate text is typed");

                return(Task.CompletedTask);
            }

            editField = new TextEditWidget(pixelWidth: 200)
            {
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Center,
            };
            systemWindow.AddChild(editField);

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, TestToRun);
        }
Example #5
0
        public async Task VerifyFocusMakesTextWidgetEditable()
        {
            TextEditWidget editField    = null;
            SystemWindow   systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.Black,
            };

            AutomationTest testToRun = (testRunner) =>
            {
                UiThread.RunOnIdle(editField.Focus);

                testRunner.Type("Test Text");

                testRunner.Wait(1);
                Assert.IsTrue(editField.Text == "Test Text", "validate text is typed");

                return(Task.FromResult(0));
            };

            editField = new TextEditWidget(pixelWidth: 200)
            {
                HAnchor = HAnchor.ParentCenter,
                VAnchor = VAnchor.ParentCenter,
            };
            systemWindow.AddChild(editField);

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testToRun, 10);
        }
Example #6
0
        public async Task VerifyFocusProperty()
        {
            var systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.Black,
            };

            var editField = new TextEditWidget(pixelWidth: 200)
            {
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Center,
            };

            systemWindow.AddChild(editField);

            Task TestToRun(AutomationRunner testRunner)
            {
                UiThread.RunOnIdle(editField.Focus);
                testRunner.WaitFor(() => editField.ContainsFocus);
                Assert.IsTrue(editField.ContainsFocus, "Focused property should be true after invoking Focus method");

                return(Task.CompletedTask);
            }

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, TestToRun);
        }
        public async Task GetWidgetByNameTestRegionSingleWindow()
        {
            int leftClickCount = 0;

            AutomationTest testToRun = (testRunner) =>
            {
                testRunner.ClickByName("left");
                testRunner.Wait(.5);
                Assert.AreEqual(1, leftClickCount, "Should have one left click count after click");

                Assert.IsTrue(testRunner.NameExists("left"), "Left button should exist");

                SearchRegion rightButtonRegion = testRunner.GetRegionByName("right");

                Assert.IsFalse(testRunner.NameExists("left", searchRegion: rightButtonRegion), "Left button should not exist in the right button region");

                return(Task.FromResult(0));
            };

            SystemWindow buttonContainer = new SystemWindow(300, 200);

            Button leftButton = new Button("left", 10, 40);

            leftButton.Name   = "left";
            leftButton.Click += (sender, e) => { leftClickCount++; };
            buttonContainer.AddChild(leftButton);

            Button rightButton = new Button("right", 110, 40);

            rightButton.Name = "right";
            buttonContainer.AddChild(rightButton);

            await AutomationRunner.ShowWindowAndExecuteTests(buttonContainer, testToRun, 10);
        }
Example #8
0
        public void SheetEditorLayoutAndNavigation()
        {
            var systemWindow = new SystemWindow(800, 600)
            {
                Name = "Main Window",
            };

            Application.AddTextWidgetRightClickMenu();

            AutomationRunner.TimeToMoveMouse = .1;

            var sheetData   = new SheetData(5, 5);
            var undoBuffer  = new UndoBuffer();
            var theme       = ApplicationController.Instance.Theme;
            var sheetEditor = new SheetEditorWidget(sheetData, null, undoBuffer, theme);

            systemWindow.AddChild(sheetEditor);

            AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testRunner =>
            {
                testRunner.Delay(100);

                return(Task.CompletedTask);
            },
                                                       2000);
        }
        public static async Task RunTest(
            AutomationTest testMethod,
            string staticDataPathOverride      = null,
            double maxTimeToRun                = 60,
            QueueTemplate queueItemFolderToAdd = QueueTemplate.None,
            int overrideWidth        = -1,
            int overrideHeight       = -1,
            string defaultTestImages = null)
        {
            // Walk back a step in the stack and output the callers name
            StackTrace st = new StackTrace(false);

            Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now);

            if (staticDataPathOverride == null)
            {
                // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
                staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");
            }

#if DEBUG
            string outputDirectory = "Debug";
#else
            string outputDirectory = "Release";
#endif

            Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory);

#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            StaticData.Instance = new FileSystemStaticData(staticDataPathOverride);
#endif
            // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl"));

            if (queueItemFolderToAdd != QueueTemplate.None)
            {
                string queueTemplateDirectory = queueItemFolderToAdd.ToString();
                MatterControlUtilities.AddItemsToQueue(queueTemplateDirectory);
            }

            if (defaultTestImages == null)
            {
                defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages");
            }

            UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic");
            //GL.HardwareAvailable = false;
            MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(overrideWidth, overrideHeight);

            var config = TestAutomationConfig.Load();

            // Extract mouse speed from config
            AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse;

            await AutomationRunner.ShowWindowAndExecuteTests(matterControlWindow, testMethod, maxTimeToRun, defaultTestImages, config.AutomationInputType);
        }
        public async Task ClickSuppressedOnMouseUpWithinChild2()
        {
            // Agg currently fires mouse up events in child controls when the parent has the mouse captured
            // and is performing drag like operations. If the mouse goes down in the parent and comes up on the child
            // neither control should get a click event

            var testWindow        = new ClickTestsWindow(300, 200);
            var bounds            = testWindow.BlueWidget.BoundsRelativeToParent;
            var mouseDownPosition = new Vector2(bounds.Left + 25, bounds.Bottom + 4);

            var    childBounds = testWindow.OrangeWidget.BoundsRelativeToParent;
            double childX      = bounds.Left + childBounds.Center.X;
            double childY      = bounds.Bottom + childBounds.Center.Y;

            await AutomationRunner.ShowWindowAndExecuteTests(
                testWindow,
                (testRunner) =>
            {
                MouseEventArgs mouseEvent;

                // ** Click should occur on mouse[down/up] within the controls bounds **
                //
                // Move to a position within BlueWidget for mousedown
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, mouseDownPosition.X, mouseDownPosition.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseDown(mouseEvent);

                // Move to a position within BlueWidget for mouseup
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, bounds.Center.X, bounds.Center.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseUp(mouseEvent);

                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Expected 1 click on root widget");

                // ** Click should not occur when mouse up occurs on child controls **
                //
                // Move to a position within BlueWidget for mousedown
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, mouseDownPosition.X, mouseDownPosition.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseDown(mouseEvent);

                // Move to a position with the OrangeWidget for mouseup
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, childX, childY, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseUp(mouseEvent);

                // There should be no increment in the click count
                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Expected click count to not increment on mouse up within child control");

                return(Task.CompletedTask);
            });
        }
        public async Task ClickSuppressedOnExternalMouseUp()
        {
            var testWindow        = new ClickTestsWindow(300, 200);
            var bounds            = testWindow.BlueWidget.BoundsRelativeToParent;
            var mouseDownPosition = new Vector2(bounds.Left + 25, bounds.Bottom + 4);

            await AutomationRunner.ShowWindowAndExecuteTests(
                testWindow,
                (testRunner) =>
            {
                MouseEventArgs mouseEvent;

                // ** Click should occur on mouse[down/up] within the controls bounds **
                //
                // Move to a position within the blueWidget for mousedown
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, mouseDownPosition.X, mouseDownPosition.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseDown(mouseEvent);

                // Move to a position within blueWidget for mouseup
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, bounds.Center.X, bounds.Center.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseUp(mouseEvent);

                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Expected 1 click on root widget");

                // ** Click should not occur when mouse up is outside of the control bounds **
                //
                // Move to a position within BlueWidget for mousedown
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, mouseDownPosition.X, mouseDownPosition.Y, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseDown(mouseEvent);

                // Move to a position **outside** of BlueWidget for mouseup
                mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, 50, 50, 0);
                testRunner.SetMouseCursorPosition(testWindow, (int)mouseEvent.X, (int)mouseEvent.Y);
                testWindow.OnMouseUp(mouseEvent);

                // There should be no increment in the click count
                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Expected 1 click on root widget");

                return(Task.CompletedTask);
            });
        }
        public async Task ClickFiresOnCorrectWidgets()
        {
            var testWindow = new ClickTestsWindow(300, 200);

            await AutomationRunner.ShowWindowAndExecuteTests(
                testWindow,
                (testRunner) =>
            {
                testRunner.ClickByName("blueWidget");
                testRunner.Delay(.1);
                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Unexpected click count on blue widget");
                Assert.AreEqual(0, testWindow.OrangeWidget.ClickCount, "Unexpected click count on orange widget");
                Assert.AreEqual(0, testWindow.PurpleWidget.ClickCount, "Unexpected click count on purple widget");

                testRunner.ClickByName("orangeWidget");
                testRunner.Delay(.1);
                Assert.AreEqual(1, testWindow.BlueWidget.ClickCount, "Unexpected click count on blue widget");
                Assert.AreEqual(1, testWindow.OrangeWidget.ClickCount, "Unexpected click count on orange widget");
                Assert.AreEqual(0, testWindow.PurpleWidget.ClickCount, "Unexpected click count on purple widget");

                testRunner.ClickByName("blueWidget");
                testRunner.Delay(.1);
                Assert.AreEqual(2, testWindow.BlueWidget.ClickCount, "Unexpected click count on blue widget");
                Assert.AreEqual(1, testWindow.OrangeWidget.ClickCount, "Unexpected click count on orange widget");
                Assert.AreEqual(0, testWindow.PurpleWidget.ClickCount, "Unexpected click count on purple widget");

                testRunner.ClickByName("orangeWidget");
                testRunner.Delay(.1);
                Assert.AreEqual(2, testWindow.BlueWidget.ClickCount, "Unexpected click count on root widget");
                Assert.AreEqual(2, testWindow.OrangeWidget.ClickCount, "Unexpected click count on orange widget");
                Assert.AreEqual(0, testWindow.PurpleWidget.ClickCount, "Unexpected click count on purple widget");

                testRunner.ClickByName("purpleWidget");
                testRunner.Delay(.1);
                Assert.AreEqual(2, testWindow.BlueWidget.ClickCount, "Unexpected click count on blue widget");
                Assert.AreEqual(2, testWindow.OrangeWidget.ClickCount, "Unexpected click count on orange widget");
                Assert.AreEqual(1, testWindow.PurpleWidget.ClickCount, "Unexpected click count on purple widget");

                return(Task.CompletedTask);
            });
        }
Example #13
0
        public async Task SelectAllOnFocusCanStillClickAfterSelection()
        {
            var editField = new TextEditWidget(pixelWidth: 200)
            {
                Name    = "editField",
                Text    = "Some Text",
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Center,
            };

            var systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.Gray,
            };

            systemWindow.AddChild(editField);

            Task TestToRun(AutomationRunner testRunner)
            {
                editField.SelectAllOnFocus = true;
                testRunner.Delay(1);
                testRunner.ClickByName(editField.Name);

                editField.SelectAllOnFocus = true;
                testRunner.Type("123");
                Assert.AreEqual("123", editField.Text, "Text input on newly focused control should replace selection");

                testRunner.ClickByName(editField.Name);
                //testRunner.WaitFor(() => editField.ContainsFocus);

                testRunner.Type("123");
                //testRunner.WaitFor(() => "123123" == editField.Text, maxSeconds: 60);
                // NOTE: Used to get intermittent failures here. These issues might have been sorted out now.
                Assert.AreEqual("123123", editField.Text, "Text should be appended if control is focused and has already received input");

                return(Task.CompletedTask);
            }

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, TestToRun);
        }
Example #14
0
        public void AutomationRunnerTimeoutTest()
        {
            // Ensure AutomationRunner throws timeout exceptions
            var systemWindow = new SystemWindow(300, 200);

            var leftButton = new Button("left", 10, 40);

            leftButton.Name = "left";
            systemWindow.AddChild(leftButton);

            Assert.ThrowsAsync <TimeoutException>(
                () => AutomationRunner.ShowWindowAndExecuteTests(
                    systemWindow,
                    (testRunner) =>
            {
                // Test method that runs for 10+ seconds
                Thread.Sleep(10 * 1000);
                return(Task.CompletedTask);
            },
                    // Timeout after 1 second
                    secondsToTestFailure: 1));
        }
Example #15
0
        public async Task SelectAllOnFocusCanStillClickAfterSelection()
        {
            var editField = new TextEditWidget(pixelWidth: 200)
            {
                Name    = "editField",
                Text    = "Some Text",
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Center,
            };

            var systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.Gray,
            };

            systemWindow.AddChild(editField);

            Task TestToRun(AutomationRunner testRunner)
            {
                editField.SelectAllOnFocus = true;
                testRunner.Delay(1);
                testRunner.ClickByName(editField.Name);

                editField.SelectAllOnFocus = true;
                testRunner.Type("123");
                Assert.AreEqual("123", editField.Text, "Text input on newly focused control should replace selection");

                testRunner.ClickByName(editField.Name);
                testRunner.Delay(.2);

                testRunner.Type("123");
                Assert.AreEqual("123123", editField.Text, "Text should be appended if control is focused and has already received input");

                return(Task.CompletedTask);
            }

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, TestToRun);
        }
Example #16
0
        public async Task SelectAllOnFocusCanStillClickAfterSelection()
        {
            var editField = new TextEditWidget(pixelWidth: 200)
            {
                Name    = "editField",
                Text    = "Some Text",
                HAnchor = HAnchor.ParentCenter,
                VAnchor = VAnchor.ParentCenter,
            };

            var systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.Gray,
            };

            systemWindow.AddChild(editField);

            AutomationTest testToRun = (testRunner) =>
            {
                editField.SelectAllOnFocus = true;
                testRunner.Wait(1);
                testRunner.ClickByName(editField.Name, 1);

                editField.SelectAllOnFocus = true;
                testRunner.Type("123");
                Assert.AreEqual("123", editField.Text, "Text input on newly focused control should replace selection");

                testRunner.ClickByName(editField.Name, 1);
                testRunner.Wait(.2);

                testRunner.Type("123");
                Assert.AreEqual("123123", editField.Text, "Text should be appended if control is focused and has already received input");

                return(Task.FromResult(0));
            };

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testToRun, 15);
        }
Example #17
0
        public async Task GetWidgetByNameTestNoRegionSingleWindow()
        {
            // single system window
            int leftClickCount = 0;

            var buttonContainer = new SystemWindow(300, 200);

            var leftButton = new Button("left", 10, 40);

            leftButton.Name   = "left";
            leftButton.Click += (sender, e) => { leftClickCount++; };
            buttonContainer.AddChild(leftButton);

            await AutomationRunner.ShowWindowAndExecuteTests(buttonContainer, (testRunner) =>
            {
                testRunner.ClickByName("left");
                testRunner.Delay(.5);

                Assert.IsTrue(leftClickCount == 1, "Got left button click");

                return(Task.CompletedTask);
            });
        }
Example #18
0
        public async Task ToolTipsShow()
        {
            SystemWindow buttonContainer = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.White,
            };

            AutomationTest testToRun = (testRunner) =>
            {
                testRunner.Delay(1);

                testRunner.MoveToByName("ButtonWithToolTip");
                testRunner.Delay(1.5);
                GuiWidget toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
                Assert.IsTrue(toolTipWidget != null, "Tool tip is showing");
                testRunner.MoveToByName("right");
                toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
                Assert.IsTrue(toolTipWidget == null, "Tool tip is not showing");

                testRunner.Delay(1);
                buttonContainer.CloseOnIdle();

                return(Task.FromResult(0));
            };

            Button leftButton = new Button("left", 10, 40);

            leftButton.Name        = "ButtonWithToolTip";
            leftButton.ToolTipText = "Left Tool Tip";
            buttonContainer.AddChild(leftButton);
            Button rightButton = new Button("right", 110, 40);

            rightButton.Name = "right";
            buttonContainer.AddChild(rightButton);

            await AutomationRunner.ShowWindowAndExecuteTests(buttonContainer, testToRun, 10000);
        }
        public void AutomationRunnerTimeoutTest()
        {
            // Ensure AutomationRunner throws timeout exceptions
            var systemWindow = new SystemWindow(300, 200);

            var leftButton = new Button("left", 10, 40);

            leftButton.Name = "left";
            systemWindow.AddChild(leftButton);

            // NOTE: This test once failed. Possibly due to ShowWindowAndExecuteTests using different timing sources. A Stopwatch and a Task.Delay.

            Assert.ThrowsAsync <TimeoutException>(
                () => AutomationRunner.ShowWindowAndExecuteTests(
                    systemWindow,
                    (testRunner) =>
            {
                // Test method that runs for 10+ seconds
                Thread.Sleep(10 * 1000);
                return(Task.CompletedTask);
            },
                    // Timeout after 1 second
                    secondsToTestFailure: 1));
        }
Example #20
0
        public async Task GetWidgetByNameTestRegionSingleWindow()
        {
            int leftClickCount = 0;

            var buttonContainer = new SystemWindow(300, 200);

            var leftButton = new Button("left", 10, 40);

            leftButton.Name   = "left";
            leftButton.Click += (sender, e) => { leftClickCount++; };
            buttonContainer.AddChild(leftButton);

            var rightButton = new Button("right", 110, 40);

            rightButton.Name = "right";
            buttonContainer.AddChild(rightButton);

            await AutomationRunner.ShowWindowAndExecuteTests(buttonContainer, (testRunner) =>
            {
                testRunner.ClickByName("left");
                testRunner.Delay(.5);
                Assert.AreEqual(1, leftClickCount, "Should have one left click count after click");

                Assert.IsTrue(testRunner.NameExists("left"), "Left button should exist");

                var widget = testRunner.GetWidgetByName(
                    "left",
                    out _,
                    5,
                    testRunner.GetRegionByName("right"));

                Assert.IsNull(widget, "Left button should not exist in the right button region");

                return(Task.CompletedTask);
            });
        }
        public async Task ClickFiresOnCorrectWidgets()
        {
            int blueClickCount   = 0;
            int orangeClickCount = 0;
            int purpleClickCount = 0;

            lastClicked = null;

            double waitTime = .5;

            AutomationTest testToRun = (testRunner) =>
            {
                testRunner.Delay(2);
                testRunner.ClickByName("rootClickable", 5);
                testRunner.Delay(waitTime);

                Assert.AreEqual(blueClickCount, 1, "Expected 1 click on blue widget");
                Assert.AreEqual(orangeClickCount, 0, "Expected 0 clicks on orange widget");
                Assert.AreEqual(purpleClickCount, 0, "Expected 1 click on purple widget");

                testRunner.ClickByName("orangeClickable", 1);
                testRunner.Delay(waitTime);
                Assert.AreEqual(blueClickCount, 1, "Expected 1 click on blue widget");
                Assert.AreEqual(orangeClickCount, 1, "Expected 1 clicks on orange widget");
                Assert.AreEqual(purpleClickCount, 0, "Expected 0 click on purple widget");

                testRunner.ClickByName("rootClickable", 1);
                testRunner.Delay(waitTime);
                Assert.AreEqual(blueClickCount, 2, "Expected 1 click on blue widget");
                Assert.AreEqual(orangeClickCount, 1, "Expected 0 clicks on orange widget");
                Assert.AreEqual(purpleClickCount, 0, "Expected 1 click on purple widget");

                testRunner.ClickByName("orangeClickable", 1);
                testRunner.Delay(waitTime);
                Assert.AreEqual(blueClickCount, 2, "Expected 1 click on root widget");
                Assert.AreEqual(orangeClickCount, 2, "Expected 2 clicks on orange widget");
                Assert.AreEqual(purpleClickCount, 0, "Expected 0 click on purple widget");

                testRunner.ClickByName("purpleClickable", 1);
                testRunner.Delay(waitTime);
                Assert.AreEqual(blueClickCount, 2, "Expected 1 click on blue widget");
                Assert.AreEqual(orangeClickCount, 2, "Expected 2 clicks on orange widget");
                Assert.AreEqual(purpleClickCount, 1, "Expected 1 click on purple widget");

                return(Task.FromResult(0));
            };

            SystemWindow systemWindow = new SystemWindow(300, 200)
            {
                Padding = new BorderDouble(20)
            };

            var rootClickable = new GuiWidget()
            {
                Width           = 50,
                HAnchor         = HAnchor.ParentLeftRight,
                VAnchor         = VAnchor.ParentBottomTop,
                Margin          = new BorderDouble(50),
                Name            = "rootClickable",
                BackgroundColor = RGBA_Bytes.Blue
            };

            rootClickable.Click += (sender, e) =>
            {
                var widget = sender as GuiWidget;
                blueClickCount += 1;
                var color = rootClickable.BackgroundColor.AdjustSaturation(0.4);
                systemWindow.BackgroundColor = color.GetAsRGBA_Bytes();
                lastClicked = rootClickable;
            };
            rootClickable.AfterDraw += widget_DrawSelection;

            var orangeClickable = new GuiWidget()
            {
                Width  = 35,
                Height = 25,
                OriginRelativeParent = new VectorMath.Vector2(10, 10),
                Name            = "orangeClickable",
                Margin          = new BorderDouble(10),
                BackgroundColor = RGBA_Bytes.Orange
            };

            orangeClickable.Click += (sender, e) =>
            {
                var widget = sender as GuiWidget;
                orangeClickCount += 1;

                var color = widget.BackgroundColor.AdjustSaturation(0.4);
                systemWindow.BackgroundColor = color.GetAsRGBA_Bytes();
                lastClicked = widget;
            };
            orangeClickable.AfterDraw += widget_DrawSelection;
            rootClickable.AddChild(orangeClickable);

            var purpleClickable = new GuiWidget()
            {
                Width  = 35,
                Height = 25,
                OriginRelativeParent = new VectorMath.Vector2(0, 10),
                HAnchor         = HAnchor.ParentRight,
                Name            = "purpleClickable",
                Margin          = new BorderDouble(10),
                BackgroundColor = new RGBA_Bytes(141, 0, 206)
            };

            purpleClickable.Click += (sender, e) =>
            {
                var widget = sender as GuiWidget;

                purpleClickCount += 1;

                var color = widget.BackgroundColor.AdjustSaturation(0.4);
                systemWindow.BackgroundColor = color.GetAsRGBA_Bytes();
                lastClicked = widget;
            };
            purpleClickable.AfterDraw += widget_DrawSelection;
            rootClickable.AddChild(purpleClickable);

            systemWindow.AddChild(rootClickable);

            await AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testToRun, 25);
        }
 public static Task RunTest(this SystemWindow systemWindow, AutomationTest automationTest, int timeout)
 {
     return(AutomationRunner.ShowWindowAndExecuteTests(systemWindow, automationTest, timeout));
 }
Example #23
0
        public async Task OpenAndCloseMenus()
        {
            int item1ClickCount = 0;
            int item2ClickCount = 0;
            int item3ClickCount = 0;

            DropDownList testList = new DropDownList("no selection", Color.Blue)
            {
                MenuItemsBackgroundColor      = Color.White,
                MenuItemsBackgroundHoverColor = Color.LightGray,
                Name       = "menu1",
                HoverColor = Color.Green
            };

            AutomationTest testToRun = (testRunner) =>
            {
                Assert.AreEqual(0, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item1");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item2");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item3");

                testRunner.WaitFor(() => testList.IsOpen, 2);
                Assert.IsTrue(testList.IsOpen, "It should remain open when clicking on a disabled item.");
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);
                testRunner.ClickByName("item2");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(2, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("OffMenu");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                //if (testList.IsOpen) { System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); }
                Assert.IsTrue(!testList.IsOpen);

                testRunner.ClickByName("menu1");
                testRunner.Delay(.1);
                //testRunner.Delay(5);
                //if (!testList.IsOpen) { System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); }
                Assert.IsTrue(testList.IsOpen);

                testRunner.ClickByName("item3");
                testRunner.Delay(.1);
                //if (!testList.IsOpen) { System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); }
                Assert.IsTrue(testList.IsOpen);

                //testRunner.Delay(5);
                testRunner.MoveToByName("OffMenu");
                // NOTE: Sometimes get failures here. Using a large delay now.
                // NOTE: The menu was once closed for those 10s...
                // Update: Failures may have been due to tests fighting over platform UI focus.
                //if (!testList.IsOpen) { System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); }
                Assert.IsTrue(testList.IsOpen);

                testRunner.ClickByName("OffMenu");
                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsFalse(testList.IsOpen, "Menus should close when clicking off menu");

                return(Task.CompletedTask);
            };

            var menuTestContainer = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.White,
                Name            = "SystemWindow",
            };

            var menuItem1 = testList.AddItem("item1");

            menuItem1.Name      = "item1";
            menuItem1.Selected += (s, e) => item1ClickCount++;

            var menuItem2 = testList.AddItem("item2");

            menuItem2.Name      = "item2";
            menuItem2.Selected += (s, e) => item2ClickCount++;

            var menuItem3 = testList.AddItem("item3");

            menuItem3.Name      = "item3";
            menuItem3.Enabled   = false;
            menuItem3.Selected += (s, e) => item3ClickCount++;

            menuTestContainer.AddChild(testList);

            menuTestContainer.AddChild(new GuiWidget(20, 20)
            {
                OriginRelativeParent = new Vector2(160, 150),
                BackgroundColor      = Color.Cyan,
                Name = "OffMenu",
            });

            await AutomationRunner.ShowWindowAndExecuteTests(menuTestContainer, testToRun);
        }
Example #24
0
        public async Task OpenAndCloseMenus()
        {
            int item1ClickCount = 0;
            int item2ClickCount = 0;
            int item3ClickCount = 0;

            DropDownList testList = new DropDownList("no selection", Color.Blue)
            {
                MenuItemsBackgroundColor      = Color.White,
                MenuItemsBackgroundHoverColor = Color.LightGray,
                Name       = "menu1",
                HoverColor = Color.Green
            };

            AutomationTest testToRun = (testRunner) =>
            {
                Assert.AreEqual(0, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item1");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item2");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item3");

                testRunner.WaitFor(() => testList.IsOpen, 2);
                Assert.IsTrue(testList.IsOpen, "It should remain open when clicking on a disabled item.");
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);
                testRunner.ClickByName("item2");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(2, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("OffMenu");

                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);

                testRunner.ClickByName("menu1");
                testRunner.Delay(.1);
                Assert.IsTrue(testList.IsOpen);

                testRunner.ClickByName("item3");
                testRunner.Delay(.1);
                Assert.IsTrue(testList.IsOpen);

                testRunner.MoveToByName("OffMenu");
                Assert.IsTrue(testList.IsOpen);

                testRunner.ClickByName("OffMenu");
                testRunner.WaitFor(() => !testList.IsOpen, 2);
                Assert.IsFalse(testList.IsOpen, "Menus should close when clicking off menu");

                return(Task.CompletedTask);
            };

            var menuTestContainer = new SystemWindow(300, 200)
            {
                BackgroundColor = Color.White,
                Name            = "SystemWindow",
            };

            var menuItem1 = testList.AddItem("item1");

            menuItem1.Name      = "item1";
            menuItem1.Selected += (s, e) => item1ClickCount++;

            var menuItem2 = testList.AddItem("item2");

            menuItem2.Name      = "item2";
            menuItem2.Selected += (s, e) => item2ClickCount++;

            var menuItem3 = testList.AddItem("item3");

            menuItem3.Name      = "item3";
            menuItem3.Enabled   = false;
            menuItem3.Selected += (s, e) => item3ClickCount++;

            menuTestContainer.AddChild(testList);

            menuTestContainer.AddChild(new GuiWidget(20, 20)
            {
                OriginRelativeParent = new Vector2(160, 150),
                BackgroundColor      = Color.Cyan,
                Name = "OffMenu",
            });

            await AutomationRunner.ShowWindowAndExecuteTests(menuTestContainer, testToRun);
        }
Example #25
0
        public async Task DisabledMenuItemsWorkCorrectly()
        {
            int item1ClickCount = 0;
            int item2ClickCount = 0;
            int item3ClickCount = 0;

            DropDownList testList = new DropDownList("no selection", RGBA_Bytes.Blue, RGBA_Bytes.Green)
            {
                MenuItemsBackgroundColor      = RGBA_Bytes.White,
                MenuItemsBackgroundHoverColor = RGBA_Bytes.LightGray,
                Name = "menu1",
            };

            AutomationTest testToRun = (testRunner) =>
            {
                Assert.AreEqual(0, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item1");

                testRunner.Delay(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(0, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item2");

                testRunner.Delay(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item3");

                testRunner.Delay(() => testList.IsOpen, 2);
                Assert.IsTrue(testList.IsOpen, "It should remain open when clicking on a disabled item.");
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(1, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);
                testRunner.ClickByName("item2");

                testRunner.Delay(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);
                Assert.AreEqual(1, item1ClickCount);
                Assert.AreEqual(2, item2ClickCount);
                Assert.AreEqual(0, item3ClickCount);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("OffMenu");

                testRunner.Delay(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen);

                testRunner.ClickByName("menu1");
                testRunner.ClickByName("item3");
                testRunner.ClickByName("OffMenu");

                testRunner.Delay(() => !testList.IsOpen, 2);
                Assert.IsTrue(!testList.IsOpen, "had a bug where after clicking a disabled item would not close clicking outside");

                return(Task.FromResult(0));
            };

            var menuTestContainer = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.White,
                Name            = "SystemWindow",
            };

            var menuItem1 = testList.AddItem("item1");

            menuItem1.Name      = "item1";
            menuItem1.Selected += (s, e) => item1ClickCount++;


            var menuItem2 = testList.AddItem("item2");

            menuItem2.Name      = "item2";
            menuItem2.Selected += (s, e) => item2ClickCount++;

            var menuItem3 = testList.AddItem("item3");

            menuItem3.Name      = "item3";
            menuItem3.Enabled   = false;
            menuItem3.Selected += (s, e) => item3ClickCount++;

            menuTestContainer.AddChild(testList);

            menuTestContainer.AddChild(new GuiWidget(20, 20)
            {
                OriginRelativeParent = new Vector2(160, 150),
                BackgroundColor      = RGBA_Bytes.Cyan,
                Name = "OffMenu",
            });

            await AutomationRunner.ShowWindowAndExecuteTests(menuTestContainer, testToRun, 20);
        }
Example #26
0
        public static async Task RunTest(
            AutomationTest testMethod,
            string staticDataPathOverride      = null,
            double maxTimeToRun                = 60,
            QueueTemplate queueItemFolderToAdd = QueueTemplate.None,
            int overrideWidth        = -1,
            int overrideHeight       = -1,
            string defaultTestImages = null)
        {
            // Walk back a step in the stack and output the callers name
            //StackTrace st = new StackTrace(false);
            //Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now);

            if (staticDataPathOverride == null)
            {
                // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
                staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");
            }

#if DEBUG
            string outputDirectory = "Debug";
#else
            string outputDirectory = "Release";
#endif

            Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory);

            // Override the default SystemWindow type without config.json
            AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";

#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            AggContext.StaticData = new FileSystemStaticData(staticDataPathOverride);
#endif
            // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl"));

            if (queueItemFolderToAdd != QueueTemplate.None)
            {
                MatterControlUtilities.AddItemsToQueue(queueItemFolderToAdd.ToString());
            }

            if (defaultTestImages == null)
            {
                defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages");
            }

            UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic");
            //GL.HardwareAvailable = false;

            var config = TestAutomationConfig.Load();
            if (config.UseAutomationDialogs)
            {
                AggContext.Config.ProviderTypes.DialogProvider = "MatterHackers.Agg.Platform.AutomationDialogProvider, GuiAutomation";
            }

            // Extract mouse speed from config
            AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse;
            AutomationRunner.UpDelaySeconds  = config.MouseUpDelay;

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";
            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var(width, height) = RootSystemWindow.GetStartupBounds();

            rootSystemWindow = Application.LoadRootWindow(
                overrideWidth == -1 ? width : overrideWidth,
                overrideHeight == -1 ? height : overrideHeight);

            OemSettings.Instance.ShowShopButton = false;

            if (!config.UseAutomationMouse)
            {
                AutomationRunner.InputMethod = new WindowsInputMethods();
            }

            await AutomationRunner.ShowWindowAndExecuteTests(
                rootSystemWindow,
                testMethod,
                maxTimeToRun,
                defaultTestImages,
                closeWindow : () =>
            {
                if (ApplicationController.Instance.ActivePrinter.Connection.CommunicationState == CommunicationStates.Printing)
                {
                    ApplicationController.Instance.ActivePrinter.Connection.Disable();
                }

                rootSystemWindow.Close();
            });
        }