Esempio n. 1
0
        public override void WaitForWindowTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            Debug.WriteLine("get the dialog launch button from the main window");
            var mainWindow = TestAutomatedApp.MainWindow as AutomationElement;

            var launchButton = mainWindow.FindAll(
                TreeScope.Descendants,
                new PropertyCondition(
                    AutomationElement.AutomationIdProperty,
                    "OpenButton",
                    PropertyConditionFlags.IgnoreCase))[0];

            Debug.WriteLine("click the button to launch the dialog");
            var invokePattern = launchButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;

            invokePattern.Invoke();

            Debug.WriteLine("wait for the window");
            TestAutomatedApp.WaitForWindow("TestDialog", DefaultTimeoutTimeSpan);

            var testDialogWindows = Microsoft.Test.AutomationUtilities.FindElementsById(AutomationElement.RootElement, "TestDialog");

            Assert.NotNull(testDialogWindows);
            Assert.Equal <int>(1, testDialogWindows.Count);
        }
Esempio n. 2
0
        public override void MainWindowTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            Assert.NotNull(TestAutomatedApp.MainWindow);
            Assert.True(typeof(AutomationElement).IsAssignableFrom(TestAutomatedApp.MainWindow.GetType()));
        }
        public override void WaitForWindowTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            Debug.WriteLine("get the dialog launch button from the main window");

            var dispatcher = ((TestAutomatedApp as InProcessApplication).ApplicationDriver as Application).Dispatcher;

            dispatcher.Invoke(DispatcherPriority.Normal,
                              (ThreadStart) delegate
            {
                var mainWindow = TestAutomatedApp.MainWindow as Window;
                mainWindow.Activate();
                var launchButton = TestHelper.GetVisualChild <Button>(mainWindow);

                Debug.WriteLine("click the button to launch the dialog");
                var clickPointWPF = launchButton.PointToScreen(new Point(2, 2));
                var clickPoint    = new System.Drawing.Point();
                clickPoint.X      = (int)clickPointWPF.X;
                clickPoint.Y      = (int)clickPointWPF.Y;

                Microsoft.Test.Input.Mouse.MoveTo(clickPoint);
                TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
                Microsoft.Test.Input.Mouse.Click(System.Windows.Input.MouseButton.Left);
            });

            Debug.WriteLine("wait for the window");
            TestAutomatedApp.WaitForWindow("TestDialog", DefaultTimeoutTimeSpan);

            bool isInitialized = false;

            dispatcher.Invoke(
                DispatcherPriority.Normal,
                (ThreadStart) delegate
            {
                Window windowToWait = null;
                foreach (Window window in Application.Current.Windows)
                {
                    if (window.Title == "TestDialog")
                    {
                        windowToWait  = window;
                        isInitialized = true;
                    }
                }
            });

            Assert.True(isInitialized);
        }
Esempio n. 4
0
        public override void OnFocusChangedTest()
        {
            var focusChangedList = new List <string>();

            TestAutomatedApp.AddEventHandler(
                AutomatedApplicationEventType.FocusChangedEvent,
                new EventHandler <AutomatedApplicationFocusChangedEventArgs>((s, e) =>
            {
                Debug.WriteLine(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Focus changed event fired. NewFocusedElement: {0}",
                                    (e.NewFocusedElement as AutomationElement).Current.Name));
                focusChangedList.Add((e.NewFocusedElement as AutomationElement).Current.Name);
            }));

            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            Debug.WriteLine("press tab");
            Keyboard.Press(Key.Tab);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            // allow time for the events to fire
            Thread.Sleep(1500);

            Debug.WriteLine("press tab again");
            Keyboard.Press(Key.Tab);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            // allow time for the events to fire
            Thread.Sleep(1500);

            Debug.WriteLine("press tab again");
            Keyboard.Press(Key.Tab);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            // allow time for the events to fire
            Thread.Sleep(1500);

            Assert.Equal <int>(4, focusChangedList.Count);
            Assert.Equal <string>("Window1", focusChangedList[0]);
            Assert.Equal <string>("Open", focusChangedList[1]);
            Assert.Equal <string>("Start Animation", focusChangedList[2]);
            Assert.Equal <string>("Debug", focusChangedList[3]);
        }
        public override void WaitForMainWindowTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            bool isInitialized = false;
            var  dispatcher    = ((TestAutomatedApp as InProcessApplication).ApplicationDriver as Application).Dispatcher;

            dispatcher.Invoke(DispatcherPriority.Normal,
                              (ThreadStart) delegate
            {
                isInitialized = TestAutomatedApp.MainWindow != null;
            });
            Assert.True(isInitialized);
        }
        public override void OnFocusChangedTest()
        {
            var focusChangedList = new List <string>();

            TestAutomatedApp.AddEventHandler(
                AutomatedApplicationEventType.FocusChangedEvent,
                new EventHandler <AutomatedApplicationFocusChangedEventArgs>((s, e) =>
            {
                Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Focus changed event fired. NewFocusedElement: {0}", (e.NewFocusedElement as ContentControl).Content.ToString()));
                focusChangedList.Add((e.NewFocusedElement as ContentControl).Content.ToString());
            }));

            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            // press tab to change focus
            var dispatcher = ((TestAutomatedApp as InProcessApplication).ApplicationDriver as Application).Dispatcher;

            dispatcher.Invoke(
                DispatcherPriority.Normal,
                (ThreadStart) delegate
            {
                Debug.WriteLine("press tab");
                Microsoft.Test.Input.Keyboard.Press(System.Windows.Input.Key.Tab);
                TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

                Debug.WriteLine("press tab again");
                Microsoft.Test.Input.Keyboard.Press(System.Windows.Input.Key.Tab);
                TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

                Debug.WriteLine("press tab again");
                Microsoft.Test.Input.Keyboard.Press(System.Windows.Input.Key.Tab);
                TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
            });

            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            Assert.Equal <int>(4, focusChangedList.Count);
            Assert.Equal <string>("System.Windows.Controls.Grid", focusChangedList[0]);
            Assert.Equal <string>("Open", focusChangedList[1]);
            Assert.Equal <string>("Start Animation", focusChangedList[2]);
            Assert.Equal <string>("Debug", focusChangedList[3]);
        }
Esempio n. 7
0
        public override void WaitForInputIdleTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            var mainWindow = TestAutomatedApp.MainWindow as AutomationElement;

            var winPattern = mainWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;

            winPattern.SetWindowVisualState(WindowVisualState.Maximized);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
            Assert.Equal <WindowVisualState>(WindowVisualState.Maximized, winPattern.Current.WindowVisualState);

            winPattern.SetWindowVisualState(WindowVisualState.Minimized);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
            Assert.Equal <WindowVisualState>(WindowVisualState.Minimized, winPattern.Current.WindowVisualState);

            winPattern.SetWindowVisualState(WindowVisualState.Normal);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
            Assert.Equal <WindowVisualState>(WindowVisualState.Normal, winPattern.Current.WindowVisualState);
        }
        //[Fact]
        public override void WaitForWindowTest()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            Debug.WriteLine("get the dialog launch button from the main window");
            var mainWindow   = TestAutomatedApp.MainWindow as Window;
            var launchButton = TestHelper.GetVisualChild <Button>(mainWindow);

            Debug.WriteLine("click the button to launch the dialog");
            var clickPointWPF = launchButton.PointToScreen(new Point(3, 3));
            var clickPoint    = new System.Drawing.Point();

            clickPoint.X = (int)clickPointWPF.X;
            clickPoint.Y = (int)clickPointWPF.Y;

            Microsoft.Test.Input.Mouse.MoveTo(clickPoint);
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);
            Microsoft.Test.Input.Mouse.Click(System.Windows.Input.MouseButton.Left);

            Debug.WriteLine("wait for the window");
            TestAutomatedApp.WaitForWindow("TestDialog", DefaultTimeoutTimeSpan);

            Window windowToWait = null;

            foreach (Window window in Application.Current.Windows)
            {
                if (window.Title == "TestDialog")
                {
                    windowToWait = window;
                }
            }

            Assert.NotNull(windowToWait);
        }
        public override void WaitForInputIdleTest()
        {
            bool isWaitForOperationCompleted = false;
            var  operationOrderQueue         = new Queue <int>();

            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            var dispatcher = ((TestAutomatedApp as InProcessApplication).ApplicationDriver as Application).Dispatcher;

            dispatcher.Hooks.OperationCompleted += (completedSender, completedArgs) =>
            {
                if (completedArgs.Operation.Priority == DispatcherPriority.ApplicationIdle)
                {
                    operationOrderQueue.Enqueue(2);

                    isWaitForOperationCompleted = true;
                    Debug.WriteLine(string.Format(
                                        CultureInfo.CurrentCulture,
                                        "operation completed: pri: {0}, status: {1}, result: {2}",
                                        completedArgs.Operation.Priority,
                                        completedArgs.Operation.Status,
                                        completedArgs.Operation.Result));
                }
            };

            // add other operations to the queue that should run before ApplicationIdle
            dispatcher.BeginInvoke(new DispatcherOperationCallback((param) =>
            {
                Debug.WriteLine("minimize the window");
                (TestAutomatedApp.MainWindow as Window).WindowState = WindowState.Minimized;

                Debug.WriteLine("maximize the window");
                (TestAutomatedApp.MainWindow as Window).WindowState = WindowState.Maximized;

                Debug.WriteLine("normalize the window");
                (TestAutomatedApp.MainWindow as Window).WindowState = WindowState.Normal;

                operationOrderQueue.Enqueue(1);

                return(null);
            }),
                                   DispatcherPriority.DataBind,
                                   new object[] { null });

            Assert.False(isWaitForOperationCompleted);

            operationOrderQueue.Enqueue(0);

            Debug.WriteLine("wait for input idle");
            TestAutomatedApp.WaitForInputIdle(DefaultTimeoutTimeSpan);

            operationOrderQueue.Enqueue(3);

            Assert.True(isWaitForOperationCompleted);

            // verify the operations took place in the correct order
            for (int i = 0; i < operationOrderQueue.Count; i++)
            {
                Assert.Equal <int>(i, operationOrderQueue.Dequeue());
            }
        }