Esempio n. 1
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 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]);
        }