示例#1
0
        public void CalculatorTest()
        {
            var window = Application.GetMainWindow(Automation);
            var calc   = OperatingSystem.IsWindows10() ? (ICalculator) new Win10Calc(window) : new LegacyCalc(window);

            // Switch to default mode
            System.Threading.Thread.Sleep(1000);
            Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_1);
            Wait.UntilInputIsProcessed();
            Application.WaitWhileBusy();
            System.Threading.Thread.Sleep(1000);

            // Simple addition
            calc.Button1.Click();
            calc.Button2.Click();
            calc.Button3.Click();
            calc.Button4.Click();
            calc.ButtonAdd.Click();
            calc.Button5.Click();
            calc.Button6.Click();
            calc.Button7.Click();
            calc.Button8.Click();
            calc.ButtonEquals.Click();
            Application.WaitWhileBusy();
            var result = calc.Result;

            Assert.That(result, Is.EqualTo("6912"));

            // Date comparison
            using (Keyboard.Pressing(VirtualKeyShort.CONTROL))
            {
                Keyboard.Type(VirtualKeyShort.KEY_E);
            }
        }
示例#2
0
 protected override Application StartApplication()
 {
     if (OperatingSystem.IsWindows10())
     {
         // Use the store application on those systems
         return(Application.LaunchStoreApp("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"));
     }
     if (OperatingSystem.IsWindowsServer2016() || OperatingSystem.IsWindowsServer2019())
     {
         // The calc.exe on this system is just a stub which launches win32calc.exe
         return(Application.Launch("win32calc.exe"));
     }
     return(Application.Launch("calc.exe"));
 }
示例#3
0
        public static void Main(string[] args)
        {
            const int endValue = 52;

            Console.WriteLine($"Running FizzBuzz from 1 to {endValue}");

            if (!OperatingSystem.IsWindows10())
            {
                ShowError("Can only run on Windows 10, sorry!");
                return;
            }

            using (var automation = new UIA3Automation())
            {
                CloseExistingCalculators(automation);

                Application.LaunchStoreApp(MagicWindows10CalculatorName);

                var host = GetCalculatorProcess();

                if (host == null)
                {
                    ShowError("Failed to find the associated ApplicationFrameHost.");
                    return;
                }

                var calculatorApp = Application.Attach(host);

                Thread.Sleep(TimeSpan.FromSeconds(1.5));

                try
                {
                    var topWindows = calculatorApp.GetAllTopLevelWindows(automation);

                    if (topWindows.Length == 0)
                    {
                        ShowError("Failed to find the main window for Calculator.");
                        return;
                    }

                    var mainWindow = topWindows[0];

                    if (mainWindow == null)
                    {
                        ShowError("Failed to find the main window for Calculator.");
                        return;
                    }

                    var calculator = new Calculator(mainWindow);

                    for (var i = 1; i <= endValue; i++)
                    {
                        var fizzy = calculator.Divide(i, 3);
                        var buzzy = calculator.Divide(i, 5);

                        var written = false;

                        if (IsWhole(fizzy))
                        {
                            written = true;
                            Console.Write(Fizz);
                        }

                        if (IsWhole(buzzy))
                        {
                            written = true;
                            Console.Write(Buzz);

                            calculator.ClearHistory();
                        }

                        if (!written)
                        {
                            Console.Write(i.ToString("G"));
                        }

                        Console.WriteLine();
                    }
                }
                catch (Exception ex)
                {
                    ShowError($"Failed due to an unexpected error: {ex}.");
                }
                finally
                {
                    calculatorApp?.Close();
                }
            }

            Console.WriteLine("FizzBuzz complete, thanks for watching!");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }