使用UIAutomation自动化测试

参考链接:

http://wenku.baidu.com/view/05b0c4886529647d272852b8.html###

code:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework; 
using White.Core; 
using White.Core.UIItems.WindowItems; 
using White.Core.Factory; 
using White.Core.UIItems; 
using White.Core.UIItems.Finders; 

namespace spy_test_4
{
     [TestClass] 
public class Calculator
     {
         [TestMethod] 
         public void calc()
         {             
             Application calcapp = Application.Launch("calc.exe");
             Window calcwindow = calcapp.GetWindow("计算器", InitializeOption.NoCache);
             Button two = calcwindow.Get<Button>(SearchCriteria.ByText("2")); 
             two.Click();
             //Button add = calcwindow.Get<Button>(SearchCriteria.ByText("+"));
             Button add = calcwindow.Get<Button>(SearchCriteria.ByAutomationId("93")); 
             add.Click();
             Button three = calcwindow.Get<Button>(SearchCriteria.ByText("3"));
             three.Click();
             Button equals = calcwindow.Get<Button>(SearchCriteria.ByAutomationId("121"));
             equals.Click();
             //TextBox output = calcwindow.Get<TextBox>(SearchCriteria.ByAutomationId("150"));
             //var actualresult = output.Text;
             string actualresult = calcwindow.Get(SearchCriteria.ByAutomationId("158")).Name;
             if (actualresult == "5")
             {
                 NUnit.Framework.Assert.AreEqual("5", actualresult);
             }
             else
             {
                 NUnit.Framework.Assert.AreNotEqual("5", actualresult);
             }
         }
     } 
}

你可能感兴趣的:(automation)