第一次写博客,呵呵

 传点东西,自动测试的。

 class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Launch the Windows Calculator (calc.exe)
            Application application = Application.Launch("calc.exe");

            // Get the main and only window
            Window window = application.GetWindows()[0];

            // Get a reference to the Edit TextBox (AutomationId = "403")
            TextBox textBox = (TextBox)window.Get(SearchCriteria.ByAutomationId("403"));

            // Get a reference to the RadioButton "Dec" (AutomationId = "307")
            RadioButton radioButtonDecimal = window.Get<RadioButton>(SearchCriteria.ByAutomationId("307"));
            // If this RadioButton can not be found, the calculator uses the Standard view
            // Call the Scientfic/Wetenschappelijk menu to make more options visible
            if (radioButtonDecimal == null)
            {
                // Click on menu View/Beeld (AutomationItem = "Item 2")
                window.Get<Menu>(SearchCriteria.ByAutomationId("Item 2")).Click();
                // Click on menu Scientific/Wetenschappelijk (AutomationItem = "Item 304")
                window.Get<Menu>(SearchCriteria.ByAutomationId("Item 304")).Click();
                // The window layout changes. Apparently we need to get the main window
                // again to avoid exceptions when searching the buttons
                window = application.GetWindows()[0];
            }

            // Press F6 to make sure we are using the decimal numerical system
            window.Keyboard.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.F6);

            // Focus the Edit TextBox and enter the text 54
            textBox.Focus();
            Keyboard.Instance.Enter("54");

            // Press button "3" (AutomationId = "127") so the value will be 543
            window.Get<Button>(SearchCriteria.ByAutomationId("127")).Click();

            // Press the "+" button (AutomationId = "92")
            window.Get<Button>(SearchCriteria.ByAutomationId("92")).Click();

            // Enter the second value. Press button "6" (AutomationId = "130")
            window.Get<Button>(SearchCriteria.ByAutomationId("130")).Click();
            // Press button "7" (AutomationId = "131")
            window.Get<Button>(SearchCriteria.ByText("7")).Click();

            // Press the "=" button to calculate the result (AutomationId = "112")
            window.Get<Button>(SearchCriteria.ByText("=")).Click();

            // Focus the Edit TextBox again and copy the result to the clipboard
            // by sending the keyboard combination CTRL+C
            textBox.Focus();
            Keyboard.Instance.HoldKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL);
            Keyboard.Instance.Enter("C");
            Keyboard.Instance.LeaveKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL);

            // Press F8 to change the numerical system from decimal to binary
            window.Keyboard.PressSpecialKey(Core.WindowsAPI.KeyboardInput.SpecialKeys.F8);

            // Show the decimal result via the text on the clipboard
            // and the corresponding binary value by accessing the text of the Edit TextBox
            Console.WriteLine("543 + 67 = {0} (dec)", System.Windows.Forms.Clipboard.GetText());
            Console.WriteLine("{0} (dec) = {1} (bin) ", System.Windows.Forms.Clipboard.GetText(), textBox.Text);

            // Close the Calculator application
            application.Kill();

            Console.ReadKey();

        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值