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工具,一个是开源的自动化工具. 只 ...
随机推荐
- laravel框架一种方便的快速填充数据的方法
首先大家都知道在laravel框架里是采用seeder来填充数据的,具体命令如下,请将如下的类名称替换成你具体的seeder类名. 首先创建seeder类 php artisan make:seede ...
- 3.Nginx常用功能介绍
Nginx常用功能介绍 Nginx反向代理应用实例 反向代理(Reverse Proxy)方式是指通过代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器,并且从内部网络服 ...
- 如何写一个SSH项目(三)如何进行交互的
下面以登录为例子,展示从前台到后端的一整套流程并进行分析. 首先介绍一下我的SSH的分层结构 action和service一起是业务逻辑层 action层调用service层 dao ...
- find 命令的误差估值与单位调整
一.命令简介 find 命令的 -size 参数 单位b(不是byte而是block).c.w.k.M.G.默认是单位b ,也就是1block = 512byte = 0.5kb (文件系统ext4) ...
- Visual studio code离线安装插件
Visual studio code离线安装插件 公司研发区不能连接公网,使用Visual studio code(vsc)写Golang代码需要安装Go插件,下面介绍下,vsc离线安装插件的步骤.以 ...
- java自动化测试-http请求post
继上文的get请求http://www.cnblogs.com/xuezhezlr/p/7667995.html的简单讲解后,这篇文章大概说一下我所遇到的主要的post请求以及他的测试代码 上文介绍到 ...
- 【精选】Nginx模块Lua-Nginx-Module学习笔记(一)Nginx Lua API 接口详解
源码地址:https://github.com/Tinywan/Lua-Nginx-Redis 一.介绍 各种* _by_lua,* _by_lua_block和* _by_lua_file配置指令用 ...
- MyBatis单个多个参数传递
一.传入单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList ...
- [SharePoint]解决用户权限被无缘无故自动删除的问题
前几天在维护公司内网的时候接到了一个case, 说是某个用户的权限无缘无故的就会被SharePoint自动去掉. 刚开始我还不愿意相信这个用户的说法,认为可能是权限赋的方法不对,有可能是被其他人误删了 ...
- entity framework学习
资源 Entity Framework技术导游系列开篇与热身