Example #1
0
        public void VerifyFocusMakesTextWidgetEditable()
        {
            TextEditWidget editField    = null;
            SystemWindow   systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.Black,
            };

            Action <AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
            {
                UiThread.RunOnIdle(editField.Focus);
                AutomationRunner testRunner = new AutomationRunner();
                testRunner.Wait(1);

                // Now do the actions specific to this test. (replace this for new tests)
                testRunner.Type("Test Text");

                resultsHarness.AddTestResult(editField.Text == "Test Text", "validate text is typed");

                systemWindow.CloseOnIdle();
            };

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

            AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(systemWindow, testToRun, 10);

            Assert.IsTrue(testHarness.AllTestsPassed);
            Assert.IsTrue(testHarness.TestCount == 1);             // make sure we can all our tests
        }
        public static Task ShowWindowAndExecuteTests(SystemWindow initialSystemWindow, AutomationTest testMethod, double secondsToTestFailure = 30, string imagesDirectory = "", Action closeWindow = null)
        {
            var testRunner = new AutomationRunner(InputMethod, DrawSimulatedMouse, imagesDirectory);

            var resetEvent = new AutoResetEvent(false);

            // On load, release the reset event
            initialSystemWindow.Load += (s, e) =>
            {
                resetEvent.Set();
            };

            int testTimeout = (int)(1000 * secondsToTestFailure);
            var timer       = Stopwatch.StartNew();

            bool testTimedOut = false;

            // Start two tasks, the timeout and the test method. Block in the test method until the first draw
            Task <Task> task = Task.WhenAny(
                Task.Delay(testTimeout),
                Task.Run(() =>
            {
                // Wait until the first system window draw before running the test method, up to the timeout
                resetEvent.WaitOne(testTimeout);

                return(testMethod(testRunner));
            }));

            // Once either the timeout or the test method has completed, store if a timeout occurred and shutdown the SystemWindow
            task.ContinueWith(innerTask =>
            {
                long elapsedTime = timer.ElapsedMilliseconds;
                testTimedOut     = elapsedTime >= testTimeout;

                // Invoke the callers close implementation or fall back to CloseOnIdle
                if (closeWindow != null)
                {
                    closeWindow();
                }
                else
                {
                    initialSystemWindow.CloseOnIdle();
                }
            });

            // Main thread blocks here until released via CloseOnIdle above
            initialSystemWindow.ShowAsSystemWindow();

            // Wait for CloseOnIdle to complete
            testRunner.WaitFor(() => initialSystemWindow.HasBeenClosed);

            if (testTimedOut)
            {
                // Throw an exception for test timeouts
                throw new TimeoutException("TestMethod timed out");
            }

            // After the system window is closed return the task and any exception to the calling context
            return(task?.Result ?? Task.CompletedTask);
        }
        public bool InstallUpdate()
        {
            string downloadToken = ApplicationSettings.Instance.get(LatestVersionRequest.VersionKey.CurrentBuildToken);

            string updateFileName = Path.Combine(updateFileLocation, "{0}.{1}".FormatWith(downloadToken, InstallerExtension));

#if __ANDROID__
            string friendlyFileName = Path.Combine(updateFileLocation, "MatterControlSetup.apk");
#else
            string releaseVersion   = ApplicationSettings.Instance.get(LatestVersionRequest.VersionKey.CurrentReleaseVersion);
            string friendlyFileName = Path.Combine(updateFileLocation, "MatterControlSetup-{0}.{1}".FormatWith(releaseVersion, InstallerExtension));
#endif

            if (System.IO.File.Exists(friendlyFileName))
            {
                System.IO.File.Delete(friendlyFileName);
            }

            try
            {
                //Change download file to friendly file name
                System.IO.File.Move(updateFileName, friendlyFileName);
#if __ANDROID__
                if (InstallUpdateFromMainActivity != null)
                {
                    InstallUpdateFromMainActivity(this, null);
                }
                return(true);
#else
                int tries = 0;
                do
                {
                    Thread.Sleep(10);
                } while (tries++ < 100 && !File.Exists(friendlyFileName));

                //Run installer file
                Process installUpdate = new Process();
                installUpdate.StartInfo.FileName = friendlyFileName;
                installUpdate.Start();

                //Attempt to close current application
                SystemWindow topSystemWindow = MatterControlApplication.Instance as SystemWindow;
                if (topSystemWindow != null)
                {
                    topSystemWindow.CloseOnIdle();
                    return(true);
                }
#endif
            }
            catch
            {
                GuiWidget.BreakInDebugger();
                if (System.IO.File.Exists(friendlyFileName))
                {
                    System.IO.File.Delete(friendlyFileName);
                }
            }

            return(false);
        }
Example #4
0
        public static void CloseMatterControl(AutomationRunner testRunner)
        {
            SystemWindow mcWindowLocal = MatterControlApplication.Instance;

            Assert.IsTrue(testRunner.ClickByName("File Menu", 2));
            Assert.IsTrue(testRunner.ClickByName("Exit Menu Item", 2));
            testRunner.Wait(.2);
            if (mcWindowLocal.Parent != null)
            {
                mcWindowLocal.CloseOnIdle();
            }
        }
Example #5
0
        public bool InstallUpdate(GuiWidget windowToClose)
        {
            string downloadToken = ApplicationSettings.Instance.get("CurrentBuildToken");

            string updateFileName   = Path.Combine(updateFileLocation, "{0}.{1}".FormatWith(downloadToken, InstallerExtension));
            string releaseVersion   = ApplicationSettings.Instance.get("CurrentReleaseVersion");
            string friendlyFileName = Path.Combine(updateFileLocation, "MatterControlSetup-{0}.{1}".FormatWith(releaseVersion, InstallerExtension));

            if (System.IO.File.Exists(friendlyFileName))
            {
                System.IO.File.Delete(friendlyFileName);
            }

            try
            {
                //Change download file to friendly file name
                System.IO.File.Move(updateFileName, friendlyFileName);

                int tries = 0;
                do
                {
                    Thread.Sleep(10);
                } while (tries++ < 100 && !File.Exists(friendlyFileName));

                //Run installer file
                Process installUpdate = new Process();
                installUpdate.StartInfo.FileName = friendlyFileName;
                installUpdate.Start();

                while (windowToClose != null && windowToClose as SystemWindow == null)
                {
                    windowToClose = windowToClose.Parent;
                }

                //Attempt to close current application
                SystemWindow topSystemWindow = windowToClose as SystemWindow;
                if (topSystemWindow != null)
                {
                    topSystemWindow.CloseOnIdle();
                    return(true);
                }
            }
            catch
            {
                if (System.IO.File.Exists(friendlyFileName))
                {
                    System.IO.File.Delete(friendlyFileName);
                }
            }

            return(false);
        }
Example #6
0
        public static Task ShowWindowAndExecuteTests(SystemWindow initialSystemWindow, AutomationTest testMethod, double secondsToTestFailure, string imagesDirectory = "", InputType inputType = InputType.Native)
        {
            var testRunner = new AutomationRunner(imagesDirectory, inputType);

            AutoResetEvent resetEvent = new AutoResetEvent(false);

            bool firstDraw = true;

            initialSystemWindow.AfterDraw += (sender, e) =>
            {
                if (firstDraw)
                {
                    firstDraw = false;
                    resetEvent.Set();
                }
            };

            int testTimeout = (int)(1000 * secondsToTestFailure);
            var timer       = Stopwatch.StartNew();

            // Start two tasks, the timeout and the test method. Block in the test method until the first draw
            Task <Task> task = Task.WhenAny(
                Task.Delay(testTimeout),
                Task.Run(() =>
            {
                // Wait until the first system window draw before running the test method
                resetEvent.WaitOne();

                return(testMethod(testRunner));
            }));

            // Once either the timeout or the test method has completed, reassign the task/result for timeout errors and shutdown the SystemWindow
            task.ContinueWith((innerTask) =>
            {
                long elapsedTime = timer.ElapsedMilliseconds;

                // Create an exception Task for test timeouts
                if (elapsedTime >= testTimeout)
                {
                    task = new Task <Task>(() => { throw new TimeoutException("TestMethod timed out"); });
                    task.RunSynchronously();
                }

                initialSystemWindow.CloseOnIdle();
            });

            // Main thread blocks here until released via CloseOnIdle above
            initialSystemWindow.ShowAsSystemWindow();

            // After the system window is closed return the task and any exception to the calling context
            return(task?.Result ?? Task.FromResult(0));
        }
        private static void CloseMatterControlViaMenu(AutomationRunner testRunner)
        {
            SystemWindow mcWindowLocal = MatterControlApplication.Instance;

            testRunner.ClickByName("File Menu", 5);
            testRunner.ClickByName("Exit Menu Item", 5);

            testRunner.Delay(.2);
            if (mcWindowLocal.Parent != null)
            {
                mcWindowLocal.CloseOnIdle();
            }
        }
Example #8
0
        private void done_Click(object sender, EventArgs mouseEvent)
        {
            GuiWidget windowToClose = this;

            while (windowToClose != null && windowToClose as SystemWindow == null)
            {
                windowToClose = windowToClose.Parent;
            }

            SystemWindow topSystemWindow = windowToClose as SystemWindow;

            if (topSystemWindow != null)
            {
                topSystemWindow.CloseOnIdle();
            }
        }
Example #9
0
        public void ToolTipsShow()
        {
            SystemWindow buttonContainer = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.White,
            };

            Action <AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
            {
                AutomationRunner testRunner = new AutomationRunner("C:/TestImages");
                testRunner.Wait(1);

                // Now do the actions specific to this test. (replace this for new tests)
                {
                    testRunner.MoveToByName("ButtonWithToolTip");
                    testRunner.Wait(1.5);
                    GuiWidget toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
                    resultsHarness.AddTestResult(toolTipWidget != null, "Tool tip is showing");
                    testRunner.MoveToByName("right");
                    toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
                    resultsHarness.AddTestResult(toolTipWidget == null, "Tool tip is not showing");
                }

                testRunner.Wait(1);
                buttonContainer.CloseOnIdle();
            };

            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);

            AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(buttonContainer, testToRun, 10000);

            Assert.IsTrue(testHarness.AllTestsPassed);
            Assert.IsTrue(testHarness.TestCount == 2);             // make sure we can all our tests
        }
Example #10
0
        public void SelectAllOnFocusCanStillClickAfterSelection()
        {
            TextEditWidget editField    = null;
            SystemWindow   systemWindow = new SystemWindow(300, 200)
            {
                BackgroundColor = RGBA_Bytes.Black,
            };

            Action <AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
            {
                editField.SelectAllOnFocus = true;
                AutomationRunner testRunner = new AutomationRunner();
                testRunner.Wait(1);

                resultsHarness.AddTestResult(testRunner.ClickByName(editField.Name, 1));

                editField.SelectAllOnFocus = true;
                testRunner.Type("123");
                resultsHarness.AddTestResult(editField.Text == "123", "on enter we have selected all and replaced the text");

                resultsHarness.AddTestResult(testRunner.ClickByName(editField.Name, 1));
                testRunner.Type("123");
                resultsHarness.AddTestResult(editField.Text == "123123", "we already have the contol selected so don't select all again.");

                systemWindow.CloseOnIdle();
            };

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

            AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(systemWindow, testToRun, 15);

            Assert.IsTrue(testHarness.AllTestsPassed);
            Assert.IsTrue(testHarness.TestCount == 4);             // make sure we can all our tests
        }
		private AutomationTesterHarness(SystemWindow initialSystemWindow, Action<AutomationTesterHarness> functionContainingTests, double secondsToTestFailure)
		{
			bool firstDraw = true;
			initialSystemWindow.DrawAfter += (sender, e) =>
			{
				if (firstDraw)
				{
					Task.Run(() => CloseAfterTime(initialSystemWindow, secondsToTestFailure));

					firstDraw = false;
					Task.Run(() =>
					{
						functionContainingTests(this);

						initialSystemWindow.CloseOnIdle();
					});
				}
			};

			initialSystemWindow.ShowAsSystemWindow();
		}
        private AutomationTesterHarness(SystemWindow initialSystemWindow, Action <AutomationTesterHarness> functionContainingTests, double secondsToTestFailure)
        {
            bool firstDraw = true;

            initialSystemWindow.DrawAfter += (sender, e) =>
            {
                if (firstDraw)
                {
                    Task.Run(() => CloseAfterTime(initialSystemWindow, secondsToTestFailure));

                    firstDraw = false;
                    Task.Run(() =>
                    {
                        functionContainingTests(this);

                        initialSystemWindow.CloseOnIdle();
                    });
                }
            };

            initialSystemWindow.ShowAsSystemWindow();
        }
Example #13
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);
        }
        private static void ShowFileDialog(Action <string> dialogClosedHandler)
        {
            var systemWindow = new SystemWindow(600, 200)
            {
                Title           = "TestAutomation File Input",
                BackgroundColor = Color.DarkGray
            };

            var warningLabel = new TextWidget("This dialog should not appear outside of automation tests.\nNotify technical support if visible", pointSize: 15, textColor: Color.Pink)
            {
                Margin  = new BorderDouble(20),
                VAnchor = VAnchor.Top,
                HAnchor = HAnchor.Stretch
            };

            systemWindow.AddChild(warningLabel);

            var fileNameInput = new TextEditWidget(pixelWidth: 400)
            {
                VAnchor = VAnchor.Center,
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(30, 15),
                Name    = "Automation Dialog TextEdit"
            };

            fileNameInput.EnterPressed += (s, e) => systemWindow.CloseOnIdle();
            systemWindow.AddChild(fileNameInput);

            systemWindow.Load   += (s, e) => fileNameInput.Focus();
            systemWindow.Closed += (s, e) =>
            {
                dialogClosedHandler(fileNameInput.Text);
            };

            systemWindow.ShowAsSystemWindow();
        }
Example #15
0
		public void ToolTipsShow()
		{
			SystemWindow buttonContainer = new SystemWindow(300, 200)
			{
				BackgroundColor = RGBA_Bytes.White,
			};

			Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
			{
				AutomationRunner testRunner = new AutomationRunner("C:/TestImages");
				testRunner.Wait(1);

				// Now do the actions specific to this test. (replace this for new tests)
				{
					testRunner.MoveToByName("ButtonWithToolTip");
					testRunner.Wait(1.5);
					GuiWidget toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
					resultsHarness.AddTestResult(toolTipWidget != null, "Tool tip is showing");
					testRunner.MoveToByName("right");
					toolTipWidget = buttonContainer.FindNamedChildRecursive("ToolTipWidget");
					resultsHarness.AddTestResult(toolTipWidget == null, "Tool tip is not showing");
				}

				testRunner.Wait(1);
				buttonContainer.CloseOnIdle();
			};

			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);

			AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(buttonContainer, testToRun, 10);

			Assert.IsTrue(testHarness.AllTestsPassed);
			Assert.IsTrue(testHarness.TestCount == 2); // make sure we can all our tests
		}
		public static void CloseAfterTime(SystemWindow windowToClose, double timeInSeconds)
		{
			Thread.Sleep((int)(timeInSeconds * 1000));
			windowToClose.CloseOnIdle();
		}
Example #17
0
		public void VerifyFocusMakesTextWidgetEditable()
		{
			TextEditWidget editField = null;
			SystemWindow systemWindow = new SystemWindow(300, 200)
			{
				BackgroundColor = RGBA_Bytes.Black,
			};

			bool firstDraw = true;
			Stopwatch testDiedTimer = Stopwatch.StartNew();
			Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
			{
				UiThread.RunOnIdle(editField.Focus);
				AutomationRunner testRunner = new AutomationRunner();
				testRunner.Wait(1);

				// Now do the actions specific to this test. (replace this for new tests)
				testRunner.Type("Test Text");

				resultsHarness.AddTestResult(editField.Text == "Test Text", "validate text is typed");

				systemWindow.CloseOnIdle();
			};

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

			AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(systemWindow, testToRun, 10);

			Assert.IsTrue(testHarness.AllTestsPassed);
			Assert.IsTrue(testHarness.TestCount == 1); // make sure we can all our tests
		}
Example #18
0
		public void SelectAllOnFocusCanStillClickAfterSelection()
		{
			TextEditWidget editField = null;
			SystemWindow systemWindow = new SystemWindow(300, 200)
			{
				BackgroundColor = RGBA_Bytes.Black,
			};

			Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
			{
				editField.SelectAllOnFocus = true;
				AutomationRunner testRunner = new AutomationRunner();
				testRunner.Wait(1);

				resultsHarness.AddTestResult(testRunner.ClickByName(editField.Name, 1));

				editField.SelectAllOnFocus = true;
				testRunner.Type("123");
				resultsHarness.AddTestResult(editField.Text == "123", "on enter we have selected all and replaced the text");

				resultsHarness.AddTestResult(testRunner.ClickByName(editField.Name, 1));
				testRunner.Type("123");
				resultsHarness.AddTestResult(editField.Text == "123123", "we already have the contol selected so don't select all again.");

				systemWindow.CloseOnIdle();
			};

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

			AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(systemWindow, testToRun, 15);

			Assert.IsTrue(testHarness.AllTestsPassed);
			Assert.IsTrue(testHarness.TestCount == 4); // make sure we can all our tests
		}
 public static void CloseAfterTime(SystemWindow windowToClose, double timeInSeconds)
 {
     Thread.Sleep((int)(timeInSeconds * 1000));
     windowToClose.CloseOnIdle();
 }