Ejemplo n.º 1
0
        public static void AssertLoadAasx(Application application, Window mainWindow, string path)
        {
            if (!File.Exists(path))
            {
                throw new InvalidOperationException($"The AASX file to be loaded does not exist: {path}");
            }

            var fileMenuItem = mainWindow
                               .FindFirstDescendant(
                cf => cf.ByClassName("MenuItem").And(cf.ByName("File")))
                               .AsMenuItem();

            fileMenuItem.Click();

            var openMenuItem = fileMenuItem
                               .FindFirstChild(cf => cf.ByName("Open .."))
                               .AsMenuItem();

            if (openMenuItem == null)
            {
                throw new AssertionException(
                          "The open menu item is null. You need to thoroughly inspect what happened -- " +
                          "this is quite strange.");
            }

            openMenuItem.Click();

            Retry.WhileEmpty(
                () => mainWindow.ModalWindows,
                throwOnTimeout: true, timeout: TimeSpan.FromSeconds(10),
                timeoutMessage: "Could not find the modal windows of the main window");

            Assert.AreEqual(1, mainWindow.ModalWindows.Length);

            var modal     = mainWindow.ModalWindows[0];
            var pathCombo = modal.FindFirstChild(cf => cf.ByAutomationId("1148")).AsComboBox();

            pathCombo.EditableText = path;

            var openButton = modal.FindFirstChild(cf => cf.ByAutomationId("1")).AsButton();

            openButton.Click();

            Assert.IsEmpty(modal.ModalWindows,
                           $"Unexpected modal window (probably an error) while opening the AASX: {path}");

            Retry.WhileTrue(() => mainWindow.ModalWindows.Length > 0,
                            throwOnTimeout: true, timeout: TimeSpan.FromSeconds(10));

            if (application.HasExited)
            {
                throw new AssertionException(
                          "The application unexpectedly exited. " +
                          $"Check manually why the file could not be opened: {path}");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds the main AASX Package Explorer window and executes the code dependent on it.
        /// </summary>
        /// <remarks>This method is necessary since splash screen confuses FlaUI and prevents us from
        /// easily determining the main window.</remarks>
        /// <param name="implementation">Code to be executed</param>
        public static void RunWithMainWindow(Implementation implementation)
        {
            string environmentVariable = "AASX_PACKAGE_EXPLORER_RELEASE_DIR";
            string releaseDir          = System.Environment.GetEnvironmentVariable(environmentVariable);

            if (releaseDir == null)
            {
                throw new InvalidOperationException(
                          $"Expected the environment variable to be set: {environmentVariable}; " +
                          "otherwise we can not find binaries to be tested through functional tests.");
            }

            string pathToExe = Path.Combine(releaseDir, "AasxPackageExplorer.exe");

            if (!File.Exists(pathToExe))
            {
                throw new FileNotFoundException(
                          "The executable of the AASX Package Explorer " +
                          $"could not be found in the release directory: {pathToExe}; did you compile it properly before?");
            }

            var app = Application.Launch(pathToExe);

            try
            {
                using (var automation = new UIA3Automation())
                {
                    // ReSharper disable once AccessToDisposedClosure
                    Retry.WhileEmpty(() => app.GetAllTopLevelWindows(automation));

                    var mainWindow = app
                                     .GetAllTopLevelWindows(automation)
                                     .First((w) => w.Title == "AASX Package Explorer");

                    implementation(app, automation, mainWindow);
                }
            }
            finally
            {
                app.Kill();
            }
        }