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工具,一个是开源的自动化工具. 只 ...
随机推荐
- android中Log类的封装
1.为了方便的使用Log打印日志,以及后续方便撤销日志打印,所以对Log类进行封装是一件好事. package market.phone; import android.util.Log; /** * ...
- Mac下nvm管理node.js版本问题
本篇文章主要是针对已经安装了node.js和nvm管理工具小伙伴遇到的问题. 管理工具有两个,一个是nvm,还有一个是nnvm的好处就是可以管理多个node版本,而且可以切换想要的版本,可以安装一个稳 ...
- Chrome不支持本地Ajax请求,解决办法
Chrome不支持本地Ajax请求,当我在.html文件中访问.json文件时就会出现这个问题,就是说这个时候不能加载这个.html文件. 解决方式 打开Chrome快捷方式的属性中设置: 右击Chr ...
- python匿名函数
文章导读: 以前自己一直没搞明白Python中的匿名函数,现在拿这个问题基本上搞明白了,拿自己的理解整成一篇文章,附带大量例子,让其更加好理解. 在编程语言中,函数的应用: 1. 代码块重复,这时候必 ...
- 几个关于js数组方法reduce的经典片段
以下是个人在工作中收藏总结的一些关于javascript数组方法reduce的相关代码片段,后续遇到其他使用这个函数的场景,将会陆续添加,这里作为备忘. javascript数组那么多方法,为什么我要 ...
- thinkphp 官方文件执行引入流程
官方手册上的执行流程图: 系统流程 用户URL请求 调用应用入口文件(通常是网站的index.php) 载入框架入口文件(ThinkPHP.php) 记录初始运行时间和内存开销 系统常量判断及定义 载 ...
- java多线程(三)-Executors实现的几种线程池以及Callable
从java5开始,类库中引入了很多新的管理调度线程的API,最常用的就是Executor(执行器)框架.Executor帮助程序员管理Thread对象,简化了并发编程,它其实就是在 提供了一个中间层, ...
- class, classloder, dex 详解
class与dex文件 什么是class文件 class文件是一种能够被JVM识别,加载并且执行的文件格式. class文件的作用 class文件的作用是记录一个类文件的所有信息. 例如记住了当前类的 ...
- 抽象方法为什么不能被private与static修饰
private private访问修饰符修饰的方法只能在本类当中使用.所以,必然不能用private去修饰抽象方法.抽象方法一定是要被子类去重写的. static Java中用static修饰符修饰的 ...
- Java异常的正确使用姿势
最近在项目代码中,遇见异常滥用的情形,会带来什么样的后果呢? 1. 代码可读性变差,业务逻辑难以理解 异常流与业务状态流混在一起,无法从接口协议层面理解业务代码,只能深入到方法(Method)内部才能 ...