UI Automation
public Form1()
{
InitializeComponent();
this.textBox1.AccessibilityObject.Name = "t1";
this.textBox3.AccessibilityObject.Name = "t3";
} private void button1_Click(object sender, EventArgs e)
{
var t = this.textBox1;
int i = int.Parse(textBox1.Text);
int j = int.Parse(textBox2.Text); textBox3.Text = (i + j).ToString();
} private void testBtn_Name_Click(object sender, EventArgs e)
{
textBox3.Text = "test";
}
上面是被自动化的代码。
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//启动被测试的程序
Process p = Process.Start(@"C:\vs2015项目\Automation\Automation\bin\Debug\Automation.exe"); //自动化根元素,可以认为是桌面.
AutomationElement aeDeskTop = AutomationElement.RootElement; Thread.Sleep();
AutomationElement aeForm = AutomationElement.FromHandle(p.MainWindowHandle); #region 获取 button 并模拟点击事件。 //找到窗体。
var testForm = aeDeskTop.FindFirst(TreeScope.Children, new PropertyCondition(
AutomationElement.NameProperty, "Form1")); //通过条件找到窗体里面的 btn。这个位置 name 属性对应控件的 Text 属性。
var btnCondition = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
new PropertyCondition(AutomationElement.NameProperty, "testBtn")); var singalCondition = new PropertyCondition(AutomationElement.NameProperty, "testBtn"); var testBtn = testForm.FindFirst(TreeScope.Children, btnCondition); // 在桌面的子控件中查找第一个符合条件的窗体。 //通过InvokePattern模拟点击按钮
InvokePattern ipClickTestBtn = (InvokePattern)testBtn.GetCurrentPattern(InvokePattern.Pattern);
ipClickTestBtn.Invoke(); #endregion #region 获取 textbox 并赋值 var txtCondition1 = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
new PropertyCondition(AutomationElement.NameProperty, "t1")); var txtCondition3 = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
new PropertyCondition(AutomationElement.NameProperty, "t3")); //设置值
var testText1 = testForm.FindFirst(TreeScope.Children, txtCondition1);
ValuePattern t1 = (ValuePattern)testText1.GetCurrentPattern(ValuePattern.Pattern);
t1.SetValue(""); //获取值
var testText3 = testForm.FindFirst(TreeScope.Children, txtCondition3);
var t3 = (TextPattern)testText3.GetCurrentPattern(TextPattern.Pattern);
string result2 = t3.DocumentRange.GetText(-); #endregion #region 实现关闭被测试程序 //实现关闭被测试程序
WindowPattern wpCloseForm = (WindowPattern)aeForm.GetCurrentPattern(WindowPattern.Pattern); #endregion
}
上面是控制代码
UI Automation的更多相关文章
- UI Automation Test
		UI Automation test is based on the windows API. U can find the UI Automation MSDN file from http://m ... 
- UI Automation 简介
		转载,源地址: http://blog.csdn.net/ffeiffei/article/details/6637418 MS UI Automation(Microsoft User Interf ... 
- 使用UI Automation实现自动化测试 --工具使用
		当前项目进行三个多月了,好久也没有写日志了:空下点时间,补写下N久没写的日志 介绍下两个工具 我本人正常使用的UISpy.exe工具和inspect.exe工具 这是UISPY工具使用的图,正常使用到 ... 
- MS UI Automation Introduction
		MS UI Automation Introduction 2014-09-17 MS UI Automation是什么 UIA架构 UI自动化模型 UI自动化树概述 UI自动化控件模式概述 UI 自 ... 
- Server-Side UI Automation Provider - WPF Sample
		Server-Side UI Automation Provider - WPF Sample 2014-09-14 引用程序集 自动化对等类 WPF Sample 参考 引用程序集 返回 UIAut ... 
- Client-Side UI Automation Provider -  WinForm Sample
		Client-Side UI Automation Provider - WinForm Sample 2014-09-15 源代码 目录 引用程序集实现提供程序接口分发客户端提供程序注册和配置客户 ... 
- Server-Side UI Automation Provider - WinForm Sample
		Server-Side UI Automation Provider - WinForm Sample 2014-09-14 源代码 目录 引用程序集提供程序接口公开服务器端 UI 自动化提供程序从 ... 
- 从UI Automation看Windows平台自动化测试原理
		前言 楼主在2013年初研究Android自动化测试的时候,就分享了几篇文章 Android ViewTree and DecorView Android自动化追本溯源系列(1): 获取页面元素 An ... 
- 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt
		首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ... 
- UI Automation的两个成熟的框架(QTP 和Selenium)
		自己在google code中开源了自己一直以来做的两个自动化的框架,一个是针对QTP的一个是针对Selenium的,显而易见,一个是商业的UI automation工具,一个是开源的自动化工具. 只 ... 
随机推荐
- ArcGIS API for JavaScript 4.2学习笔记[8] 2D与3D视图同步
			同一份数据不同视图查看可能用的比较少,因为3D视图放大很多后就和2D地图差不多了,畸变很小,用于超大范围的地图显示时有用,很多时候都是在平面地图上进行分析.查询.操作.教学需要可能会对这个有要求? 本 ... 
- C#中级-通过注册表读取Windows Service程序执行路径
			一.前言 假设我们的C#解决方案中有多个程序应用,如:Web应用.控制台程序.WPF程序应用和Windows服务应用. 那么这些非Windows Service应用程序怎么在代码中找到W ... 
- 3.sass的数据类型与函数
			数据类型 在sass里有数字.字符串.列表.颜色等类型 在cmd里 输入 sass -i 就会进入到交互模式,输入的计算可以马上得到结果 type-of()可以用来得到数据类型,如: type-of( ... 
- Linux_服务器_07_ 将用户设置为管理员
			二.参考资料 1.CentOS普通用户获得管理员权限 2.linux下添加用户并赋予root权限 
- CSS图片翻转动画技术详解
			因为不断有人问我,现在我补充一下:IE是支持这种技术的!尽管会很麻烦.需要做的是旋转front和back元素,而不是旋转整个容器元素.如果你使用的是最新版的IE,可以忽略这一节.IE10+是支持的,I ... 
- thinkinginjava学习笔记02_对象
			对象 1. 对象通过一个引用来操作,但是java中的对象是按值传递的,基本上可以在操作中认为对象本身,在内部结构中仍然要记得是对象实体的引用:如:String s = "abcd" ... 
- 转:java 可设置最大内存
			测试方法:在命令行下用 java -XmxXXXXM -version ,比如:java -Xmx1024M -version命令来进行测试,然后逐渐的增大XXXX的值,如果执行正常就表示指定的内存大 ... 
- 从开源项目看python代码注释
			最近看了不少代码,也写了不少代码,所以在看和写之间发现了很多的问题,真的是很多,至少从我的认识来看,有几个地方有很大的改进空间,这里不准备把所有的问题都列举出来,所以就先挑选一个比较明显得来和大家聊聊 ... 
- Python中的单例模式的几种实现方式的优缺点及优化
			单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ... 
- TurnipBit-MicroPython开发板:跟孩子一起DIY跳动的心
			天是越来越热了,小心脏也是越跳越快啊,为了表达现在激动的心情,必须做个激动的心开始跳动.紧接着就开始带领大家做个激动的心. 首先说说要借助的平台,这次仅仅需要借助一块TurnipBit开发板. Tur ... 
