Coded UI Test功能扩展
来源:互联网 发布:美国陪审团知乎 编辑:程序博客网 时间:2024/05/01 05:19
[图书连载]Coded UI Test功能扩展(代码定位UI控件)
本文为电子工业出版社推出的《构筑敏捷的开发团队:微软Visual Studio 2010实战兵法》图书第八章连载之十九。
通过以上Coded UI Test(简称CUIT)实践的学习,我们已经对CUIT的功能应用特性有了更多的认识,但这并没触及到CUIT的核心Code,也就是如何使用Code来真正实现对程序UI的的控制,本节将简单介绍如何使用代码来控制UI上的元素。如图1所示,左边是UI测试的一个简单步骤模型,右边则是CUIT所提供的对应功能。
图1 用户界面测试模型
如图1所示,左半边的5步是测试所共有的步骤,也是进行UI自动化测试所必须的步骤,这不仅限于UI测试。在我们实际开发项目中,常被测试人员所忽略的地方是,用它来衡量被测试软件(Application Under Test, AUT)的可测试性(Testability)。在项目开始阶段,测试人员在评审PM和开发人员的文档时,往往总是从要实现系统的功能是否正确和完善的角度开始,急于去了解要测试内容的具体情况,忙着着手准备开始写测试计划。而没有人愿意去仔细思考一下:AUT是否好测试?稍改进一下是否更有利于实现自动化测试?
应用&实践:CodedUI Test代码定位UI控件
编写CUIT测试代码的第一步就是要能够找到所要操作的UI控件,然后创建对应的测试对象。要定位到指定的UI控件并创建测试对象,需要知道该空间的类型、父控件对象以及它的搜索属性。例如,Visual Studio 2010中新加入了一个新的工具窗口Architecture Explorer,用于浏览程序的结构层次,其中包含了一个个的Column窗口,如图2所示。
图2 架构浏览程序层次图
CUIT代码封装了对这个Column控件测试类,代码如下所示。
- public class VSAEColumn : WpfCustom
- {
- #region Constructors
- /// <summary>
- ///
- /// </summary>
- /// <param name="searchLimitContainer"></param>
- /// <param name="index">Column index</param>
- public VSAEColumn(VSArchitectureExplorer architectureExplorer, int index) :
- base(architectureExplorer.CascadeScrollViewPane)
- {
- this.architectureExplorer = architectureExplorer;
- #region Search Criteria
- this.SearchProperties[WpfCustom.PropertyNames.ClassName] = "Uia.CascadeColumn";
- this.SearchProperties[WpfCustom.PropertyNames.AutomationId] = String.Format("Column_{0}", index);
- #endregion
- }
- #endregion
- …
- }
如上面代码所示,它们共同工作完成了对UI测试对象的创建,代码中有三点需要特别注意:
● 父类WpfCustom:是CUIT框架提供的一个类,它所对应的UI元素是WPF Custom类型的控件。
● architectureExplorer.CascadeScrollViewPane:它是Column控件的父控件所对应的测试对象,它限定了对Column控件的搜索访问,即就在该父控件的子控件中进行搜索。
● Search Criteria中定义的两条搜索标准:AutomationId和ClassName。
通过上述这三点,我们如何才能知道所要的UI控件的类型、父和搜索标准呢?VS 2010中提供了Coded UI Test Builder工具来辅助获得这些信息。用CUIT Builder抓取的Column控件的信息,涵盖了上述的三方面内容,如图3所示。
图3 CUIT工具定位UI
Coded UI Test Builder对应的可执行文件CodedUITestBuilder.exe放在...\Program Files\Microsoft Visual Studio 10.0\Common7\IDE目录下。
在Visual Studio 2010中,对于CUIT工程不能独立执行,只能是先创建一个Coded UI Test工程,然后打开测试代码文件,鼠标右键单击任何一个[TestMethod]方法,弹出菜单中选择“Generate Code for Coded UI Test”|“Use Coded UI Test Builder”。
- Coded UI Test功能扩展
- Coded UI Test
- Coded Ui Test使用数据源
- Coded UI Test数据验证
- Rnp and Coded UI Test
- VS 2010 测试功能学习(18) – Coded UI Test三个必知的函数
- VS 2010 测试功能学习(18) – Coded UI Test三个必知的函数
- 如何打开Coded UI Test Builder
- 微软测试管理运行Coded UI Test
- Coded UI Test 入门学习(一)
- Coded UI Test--Method of search control
- Code UI Test -- 手动编写Coded UI Test(existing browser)
- 如保将test case转换成Coded UI Test
- Coded UI Test--Seperate the UIMap per test category
- Coded UI
- VS2010的Coded UI Test参考内容列表
- How does “Coded UI test” finds a control ?
- Troubleshooting Record and Playback issues in Coded UI Test
- Visual Studio 2010自动化Web应用测试实践
- MFC中Picture Control如何添加图片
- 利用 OpenScales+MapServer+PostGIS 快速构建 GIS 应用
- LINUX 查看硬件配置命令
- jquery查找元素方法示例
- Coded UI Test功能扩展
- 程序员专用经典语录
- oracle 11gR2 rac library cache: mutex X引发的故障
- 鸡尾酒排序
- MFEditor: MapServer mapfile文件可视化编辑工具下载
- 使用VS 2010实现敏捷驱动测试开发
- ITopologicalOperator接口详解
- 内存池
- 组件制作之一(概念)