White(一)

 用white做了个简单的实践,win7自带的calculator。代码如下:


{
    class Launch_Cal
    {
        public static void launchCal()
        {
            //Launch Calculator
            string path;
            string processname;


            path = @"C:/Windows/System32/calc.exe";
            processname = @"calc";
            //If the application have launched, Close it
            Kill_Application.Close_application(processname);
            Core.Application application = Core.Application.Launch(path);
            Assert.IsNotNull(application);
            Window Window = null;
            int numWaits = 0;
            //use the smart delay-loop technique instead of the arbitrarily long Sleep technique
            do
            {
                Window = application.GetWindow("Calculator");
                ++numWaits;
                Thread.Sleep(2000);
            } while (Window == null && numWaits < 10);

            if (Window == null)
            {
                Log.Instance.Error("Unable to get Calculator");
            }
            else
            {
                Log.Instance.Info("Found Calculator window");

            }

           

           //Press F1 button
            AttachedKeyboard keyboard = Window.Keyboard;
            keyboard.HoldKey(KeyboardInput.SpecialKeys.F1);
            keyboard.LeaveKey(KeyboardInput.SpecialKeys.F1);
           

             Thread.Sleep(5000);
            //I have no idea how to use white to recognize the help window, so I have to use UI automation.
            AutomationElement helper = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Windows Help and Support"));

            AutomationElement closebutton = helper.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Close"));
            InvokePattern invokepattern = closebutton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
            invokepattern.Invoke();

           

            Window.DisplayState = DisplayState.Minimized;
            Assert.AreEqual(DisplayState.Minimized, Window.DisplayState);
            Thread.Sleep(5000);
           

            Window.DisplayState = DisplayState.Restored;
            Assert.AreEqual(DisplayState.Restored, Window.DisplayState);

            Window.Close();
        

      
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值