基于ui automation的计算器测试程序
using System;
using System.Text;using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;
using System.Windows.Automation;
using System.Diagnostics;
namespace TestProject2
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
//Process p = Process.Start(@"E:\Project\WinFormTest\WinFormTest\bin\Debug\WinFormTest.exe");
var desktop = AutomationElement.RootElement; // 先找到根元素,可以认为是桌面
var condition = new PropertyCondition(AutomationElement.NameProperty, "计算器"); // 定义我们的查找条件,名字是test
var window = desktop.FindFirst(TreeScope.Children, condition); // 在桌面