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);
        }
 public void WaitForWindowTest()
 {
     Assert.Throws <MockApplicationException>(
         () =>
     {
         TestAutomatedApp.WaitForWindow("TestDialog", TimeSpan.FromMilliseconds(DefaultTimeoutInMS));
     });
 }
        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);
        }
        //[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);
        }