コード例 #1
0
        internal void Initialize(bool doLaunch = false, string deploymentDir = null)
        {
            var topWindowCondition = _windowCondition.OrWith(_appFrameWindowCondition);

            UIObject topWindowObj  = null;
            bool     didFindWindow = UIObject.Root.Children.TryFind(topWindowCondition, out topWindowObj);

            // Only try to launch the app if we couldn't find the window.
            if (doLaunch && !didFindWindow)
            {
                CoreWindow = Launch(deploymentDir);
                if (CoreWindow.Parent.Matches(_appFrameWindowCondition))
                {
                    ApplicationFrameWindow = CoreWindow.Parent;
                }
            }
            else if (didFindWindow)
            {
                if (topWindowObj.Matches(_windowCondition))
                {
                    // If the top level window is CoreWindow, then there is no AppFrame window:
                    CoreWindow             = topWindowObj;
                    ApplicationFrameWindow = null;
                }
                else
                {
                    Verify.IsTrue(topWindowObj.Matches(_appFrameWindowCondition));

                    ApplicationFrameWindow = topWindowObj;
                    CoreWindow             = topWindowObj.Children.Find(_windowCondition);
                }
            }

            if (CoreWindow == null)
            {
                // We expect to have a window by this point.
                throw new UIObjectNotFoundException("Could not find application window.");
            }

            // If this is running on desktop (it has an app frame window) then try to
            // maximize the window.

            if (ApplicationFrameWindow != null)
            {
                var appFrameWindow = new Window(ApplicationFrameWindow);
                if (appFrameWindow.CanMaximize)
                {
                    appFrameWindow.SetWindowVisualState(WindowVisualState.Maximized);
                }
            }

            Process = Process.GetProcessById(CoreWindow.ProcessId);

            Wait.InitializeWaitHelper();

#if USING_TAEF
            if (TestEnvironment.TestContext.Properties.Contains("WaitForAppDebugger"))
#else
            if (TestEnvironment.TestContext.Properties.ContainsKey("WaitForAppDebugger"))
#endif
            {
                Wait.ForAppDebugger();
            }

            TestCleanupHelper.TestSetupHelperPendingDisposals = 0;
        }
コード例 #2
0
        internal void Initialize(bool doLaunch = false, string deploymentDir = null)
        {
            var topWindowCondition = _windowCondition.OrWith(_appFrameWindowCondition);

            UIObject topWindowObj  = null;
            bool     didFindWindow = UIObject.Root.Children.TryFind(topWindowCondition, out topWindowObj);

            // Only try to launch the app if we couldn't find the window.
            if (doLaunch && !didFindWindow)
            {
                CoreWindow = Launch(deploymentDir);
                if (CoreWindow.Parent.Matches(_appFrameWindowCondition))
                {
                    ApplicationFrameWindow = CoreWindow.Parent;
                }
            }
            else if (didFindWindow)
            {
                // topWindowObj should match either _windowCondition or _appFrameWindowCondition

                if (topWindowObj.Matches(_windowCondition))
                {
                    // If the top level window is CoreWindow, then there is no AppFrame window:
                    CoreWindow             = topWindowObj;
                    ApplicationFrameWindow = null;
                }
                else // _appFrameWindowCondition
                {
                    if (!topWindowObj.Matches(_appFrameWindowCondition))
                    {
                        // This should never happen
                        Verify.Fail($"Expected topWindowObj ({UIObjectToLoggableString(topWindowObj)}) to match _appFrameWindowCondition ({_appFrameWindowCondition})");
                    }

                    // Maxmize window to ensure we can find UIA elements
                    var appFrameWindow = new Window(topWindowObj);
                    if (appFrameWindow.CanMaximize)
                    {
                        appFrameWindow.SetWindowVisualState(WindowVisualState.Maximized);
                    }

                    Verify.IsTrue(topWindowObj.Matches(_appFrameWindowCondition));
                    ApplicationFrameWindow = topWindowObj;

                    Log.Comment("Looking for CoreWindow...");
                    for (int retries = 0; retries < 5; ++retries)
                    {
                        if (topWindowObj.Children.TryFind(_windowCondition, out var coreWindowObject))
                        {
                            CoreWindow = coreWindowObject;
                            Log.Comment("Found CoreWindow.");
                            break;
                        }

                        Log.Comment("CoreWindow not found. Sleep for 500 ms and retry");
                        Thread.Sleep(500);
                    }
                }
            }

            if (CoreWindow == null)
            {
                // We expect to have a window by this point.
                LogDumpTree();
                throw new UIObjectNotFoundException("Could not find application window.");
            }

            // If this is running on desktop (it has an app frame window) then try to
            // maximize the window.

            if (ApplicationFrameWindow != null)
            {
                var appFrameWindow = new Window(ApplicationFrameWindow);
                if (appFrameWindow.CanMaximize)
                {
                    appFrameWindow.SetWindowVisualState(WindowVisualState.Maximized);
                }
            }

            Process = Process.GetProcessById(CoreWindow.ProcessId);

            Wait.InitializeWaitHelper();

            if (TestEnvironment.TestContext.Properties.Contains("WaitForAppDebugger"))
            {
                Wait.ForAppDebugger();
            }

            TestCleanupHelper.TestSetupHelperPendingDisposals = 0;
        }