Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var processId = Convert.ToInt32(ProcessIdText.Text);

            _app = new FlaUI.Core.Application(processId);
            RegisterEvents();
        }
        //--------------------------------------------------------------------------------------------------

        public void Init(bool enableWelcomeDialog, string filepath = null)
        {
            // Set up paths
            var applicationDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var applicationPath      = Path.Combine(applicationDirectory, "Macad.exe");
            var applicationArguments = "-sandbox";

            if (!enableWelcomeDialog)
            {
                applicationArguments += " -nowelcome";
            }

            if (!filepath.IsNullOrEmpty())
            {
                applicationArguments += " \"" + filepath + "\"";
            }

            // Start the app
            var processStartInfo = new ProcessStartInfo
            {
                FileName  = applicationPath,
                Arguments = applicationArguments
            };

            Application = FlaUI.Core.Application.Launch(processStartInfo);
            Assume.That(Application, Is.Not.Null);
            Application.WaitWhileMainHandleIsMissing();
        }
Ejemplo n.º 3
0
        public void AutoClickStart()
        {
            try
            {
                Application app = FlaUI.Core.Application.Attach(Process.GetProcessById(RemotePlayProcess.Id));

                using (var automation = new UIA2Automation())
                {
                    while (true)
                    {
                        Window window  = app.GetMainWindow(automation);
                        Button button1 = window.FindFirstDescendant(cf => cf.ByText("Start"))?.AsButton();
                        if (button1 == null)
                        {
                            Thread.Sleep(1000);
                        }

                        else
                        {
                            button1?.Invoke();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error("Problem with auto-clicker: " + ex.Message);
            }
        }
Ejemplo n.º 4
0
        public void StartThis(string appName, string appPath)
        {
            var     aUI3 = new UIA3Automation();
            Process apps = Process.Start(appPath);

            System.Threading.Thread.Sleep(30000);
            Process[] SC = Process.GetProcesses();

            foreach (Process proc in SC)
            {
                System.Diagnostics.Debug.Write(" proc :: " + proc.ProcessName.ToLower() + " " + appName.ToLower() + "\n");
                if (proc.ProcessName.ToLower().Contains(appName.ToLower()))
                {
                    appProcess = proc;

                    break;
                }
            }
            app       = FlaUI.Core.Application.Attach(appProcess);
            appWindow = app.GetMainWindow(aUI3, TimeSpan.FromMilliseconds(5000));

            System.Diagnostics.Debug.Write(" WIDTH " + appWindow.Properties.BoundingRectangle.Value.Width);
            this.WIDTH  = appWindow.Properties.BoundingRectangle.Value.Width;
            this.HEIGHT = appWindow.Properties.BoundingRectangle.Value.Height;
        }
Ejemplo n.º 5
0
 public static Window RequireTopLevelWindow(Application application, UIA3Automation automation,
                                            Func <Window, bool> filter, string timeoutMessage, int timeoutSeconds = 5)
 {
     return(Retry.WhileNull(() =>
                            // ReSharper disable once AccessToDisposedClosure
                            application.GetAllTopLevelWindows(automation).FirstOrDefault(filter),
                            throwOnTimeout: true, timeout: TimeSpan.FromSeconds(timeoutSeconds), timeoutMessage: timeoutMessage
                            ).Result);
 }
Ejemplo n.º 6
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.º 7
0
        public void OneTimeSetUp()
        {
            this.app?.Dispose();
            this.app = Application.Launch(Info.ProcessStartInfo);
            this.automation?.Dispose();
            this.automation = new UIA3Automation();
            var window = this.app.GetMainWindow(this.automation);

            this.tabItem = window.FindFirstDescendant(x => x.ByName("ZoomViewer")).AsTabItem();
            this.tabItem.Click();
            this.app.WaitWhileBusy();
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            app        = FlaUI.Core.Application.Launch("SalesTax.exe");
            Automation = new UIA3Automation();
            window     = app.GetMainWindow(Automation);

            txtAmount       = window.FindFirstDescendant(cf => cf.ByAutomationId("txtAmount"))?.AsTextBox();
            chkCountyTax    = window.FindFirstDescendant(cf => cf.ByAutomationId("chkCountyTax"))?.AsCheckBox();
            btnCalculate    = window.FindFirstDescendant(cf => cf.ByAutomationId("btnCalculate"))?.AsButton();
            lstTotal        = window.FindFirstDescendant(cf => cf.ByAutomationId("lstTotal"))?.AsListBox();
            lstInitialItems = lstTotal.Items;
        }
Ejemplo n.º 9
0
 public void Dispose()
 {
     try
     {
         this.automation?.Dispose();
         this.automation = null;
         this.app?.Dispose();
         this.app = null;
     }
     catch (Exception)
     {
         // Swallow
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Retry until the label element with number of errors is found and then check that there are no errors.
        ///
        /// If the search times out, an exception will be thrown.
        /// </summary>
        /// <param name="application">AASX Package Explorer application under test</param>
        /// <param name="mainWindow">Main window of <paramref name="application"/></param>
        /// <remarks>Both <paramref name="application"/> and <paramref name="mainWindow"/> should be obtained
        /// with <see cref="RunWithMainWindow"/></remarks>
        public static void AssertNoErrors(Application application, Window mainWindow)
        {
            const string automationId = "LabelNumberErrors";

            var numberErrors = Retry.Find(
                () => (application.HasExited) ? null : mainWindow.FindFirstChild(cf => cf.ByAutomationId(automationId)),
                new RetrySettings {
                ThrowOnTimeout = true, Timeout = TimeSpan.FromSeconds(5)
            });

            Assert.IsFalse(application.HasExited,
                           "Application unexpectedly exited while searching for number of errors label");

            Assert.IsNotNull(numberErrors, $"Element {automationId} could not be found.");

            Assert.AreEqual("Text", numberErrors.ClassName, $"Expected {automationId} to be a label");
            Assert.AreEqual("No errors", numberErrors.AsLabel().Text, "Expected no errors on startup");
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
0
        //--------------------------------------------------------------------------------------------------

        public void Init(string cmdargs)
        {
            // Set up paths
            var applicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var applicationPath      = Path.Combine(applicationDirectory, "Macad.exe");
            var applicationArguments = "-sandbox " + cmdargs;

            // Start the app
            var processStartInfo = new ProcessStartInfo
            {
                FileName         = applicationPath,
                WorkingDirectory = applicationDirectory,
                Arguments        = applicationArguments
            };

            Application = FlaUI.Core.Application.Launch(processStartInfo);
            Assume.That(Application, Is.Not.Null);
            Application.WaitWhileMainHandleIsMissing();
            Application.WaitWhileBusy(new TimeSpan(0, 1, 0));
        }
Ejemplo n.º 13
0
        public void CloseBySelector(Selector selector, TimeSpan timeout, bool Force)
        {
            string url = "";
            var    f   = selector.First();
            var    p   = f.Properties.Where(x => x.Name == "url").FirstOrDefault();

            if (p != null)
            {
                url = p.Value;
            }
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            foreach (SHDocVw.InternetExplorer _ie in shellWindows)
            {
                var filename = System.IO.Path.GetFileNameWithoutExtension(_ie.FullName).ToLower();
                if (filename.Equals("iexplore"))
                {
                    try
                    {
                        var wBrowser = _ie as SHDocVw.WebBrowser;
                        if (wBrowser.LocationURL == url || string.IsNullOrEmpty(url))
                        {
                            using (var automation = Interfaces.AutomationUtil.getAutomation())
                            {
                                var _ele = automation.FromHandle(new IntPtr(_ie.HWND));
                                using (var app = new FlaUI.Core.Application(_ele.Properties.ProcessId.Value, false))
                                {
                                    app.Close();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "");
                    }
                }
            }
        }
Ejemplo n.º 14
0
 private void StartApplication()
 {
     app = FlaUI.Core.Application.Launch(Environment.CurrentDirectory.Replace('\\', '/') + "/../../../ArrayProcessForm/bin/Debug/ArrayProcessForm.exe");
 }
Ejemplo n.º 15
0
 public static Window RequireTopLevelWindowByTitle(Application application, UIA3Automation automation,
                                                   string title, int timeoutSeconds = 5)
 {
     return(RequireTopLevelWindow(application, automation, (w) => w.Title == title,
                                  $"Could not find the top-level window with the title {Quote(title)}", timeoutSeconds));
 }
Ejemplo n.º 16
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>
        /// <param name="run">Run options. If null, a new run with default values is used</param>
        public static void RunWithMainWindow(Implementation implementation, Run?run = null)
        {
            string releaseDir = ReleaseDir();
            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 resolvedRun = run ?? new Run();

            // See https://stackoverflow.com/questions/5510343/escape-command-line-arguments-in-c-sharp
            string joinedArgs = string.Join(
                " ",
                resolvedRun.Args
                .Select(arg => Regex.Replace(arg, @"(\\*)" + "\"", @"$1$1\" + "\"")));

            var psi = new ProcessStartInfo
            {
                FileName              = pathToExe,
                Arguments             = joinedArgs,
                RedirectStandardError = true,
                WorkingDirectory      = releaseDir,
                UseShellExecute       = false
            };

            bool gotStderr = false;

            var process = new Process {
                StartInfo = psi
            };

            try
            {
                process.ErrorDataReceived += (sender, e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        gotStderr = true;
                        TestContext.Error.WriteLine(e.Data);
                    }
                };

                process.Start();
                process.BeginErrorReadLine();
            }
            catch (Exception)
            {
                TestContext.Error.WriteLine(
                    $"Failed to launch the process: FileName: {psi.FileName}, " +
                    $"Arguments: {psi.Arguments}, Working directory: {psi.WorkingDirectory}");
                throw;
            }

            var app = new Application(process, false);

            try
            {
                using var automation = new UIA3Automation();

                var mainWindow = Retry.Find(() =>
                                            // ReSharper disable once AccessToDisposedClosure
                                            app.GetAllTopLevelWindows(automation)
                                            .FirstOrDefault(
                                                (w) => w.AutomationId == "mainWindow"),
                                            new RetrySettings
                {
                    ThrowOnTimeout = true,
                    Timeout        = TimeSpan.FromSeconds(5),
                    TimeoutMessage = "Could not find the main window"
                }).AsWindow();

                implementation(app, automation, mainWindow);
            }
            finally
            {
                if (!resolvedRun.DontKill)
                {
                    app.Kill();
                }
            }

            if (gotStderr)
            {
                throw new AssertionException(
                          "Unexpected writes to standard error. Please see the test context for more detail.");
            }
        }