什么是Coded UI
什么是Coded UI
Coded UI Test是Visual Studio 2010对于Testing Project(测试工程)提供的关于UI自动化测试的框架,支持Win32,Web,WPF等UI的自动化测试,是一个非常强大的测试工具,Coded UI支持自动录制和手动编写。
Coded UI能干什么
- 打开应用程序
- 模拟用户操作
- 获取UI元素
- UITestControl:所有UI类库的基类
- Web测试类库:HtmlControls(HtmlButton,HtmlDiv等)
- Winform测试类库:WinControls(WinMenu,WinWindow等)
- WPF测试类库:WpfControls(WpfCheckBox,WpfPane等)
Coded UI主要类库
- UITestControl:所有UI类库的基类
- Web测试类库:HtmlControls(HtmlButton,HtmlDiv等)
- Winform测试类库:WinControls(WinMenu,WinWindow等)
- WPF测试类库:WpfControls(WpfCheckBox,WpfPane等)
Coded UI结果验证类
Assert类: Microsoft.VisualStudio.QualityTools.UnitTesting
常用方法:IsTrue(),IsFalse(),IsNull(),AreEqual()
手动编写Coded UI Test
原理:手动编写与自动录制原理相同,但是更为灵活。自动录制生成的代码过于繁乱,不易修改维护,手动编写的话易于管理,可以按照实际情况运用一些常见的编程方法,对代码做一些定制,可读性更强,提取公共部分写成通用函数使得代码易于维护。
思路:
明确你想要测试的程序,根据程序控件的一些属性捕获到这个控件
根据测试需求对控件做一些操作
根据需求提取控件信息,控件状态、文本信息、控件定义等
将提取信息与期望信息匹配
新建Coded UI Test 工程
- 同上新建一个Test工程,添加Coded UI Test
- 在CodedUITest1.cs文件中编写测试方法。每个测试方法的方法体上面都要有[TestMethod],为了方便VS2010自带的方法执行工具发现该方法。
- 手动获取页面控件要使用IE Developer Tools
Coded UI一些操作方法
调用HtmlControls类库(后面有示例程序)
- 打开浏览器:调用BrowserWindow类来实例化一个BrowserWindow对象
BrowserWindow browser = BrowserWindow.Launch(new Uri("http://www.baidu.com"))
- 获取Div控件:调用HtmlDiv类实例化一个HtmlDiv对象
HtmlDiv header = new HtmlDiv(browser);
header.SearchProperties[HtmlDiv.PropertyNames.Class] = "s_tab";
- 获取文本框:调用HtmlEdit类来实例化一个HtmlEdit对象
HtmlEdit txtKeyWord = new HtmlEdit(browser);
txtKeyWord.SearchProperties[HtmlEdit.PropertyNames.Class] = "s_ipt";
- 获取按钮:调用HtmlInputButton类实例化一个HtmlInputButton对象
HtmlInputButton btnSubmit = new HtmlInputButton(browser);
btnSubmit.SearchProperties[HtmlInputButton.PropertyNames.Class] = "s_btn";
依次类推,在代码中会有智能提示,或者查询MSDN网站来查找相应方法
- 鼠标点击:Mouse.Click(HtmlControl);
Mouse.Click(btnSubmit);
- 验证结果:调用Assert类的各种方法
Assert.IsTrue(imgLogo.Exists, "Logo doesn't exist!");
- 等待浏览器加载完成:BrowserWindow .WaitForControlReady();
- 让程序等待:System.Threading.Thread.Sleep(毫秒数);
示例程序:验证百度搜索成功
public class CodedUITest1
{
[TestMethod]
public void VarifyFeatures()
{
#region 打开浏览器获取控件 //调用BrowserWindow打开浏览器,默认打开IE
BrowserWindow browser = BrowserWindow.Launch(new Uri("http://www.baidu.com")); //打开其他浏览器方法
//Process p = Process.Start(@"C:\Users\XXX\AppData\Roaming\360se6\Application\360se.exe", "http://www.baidu.com");
//BrowserWindow browser = BrowserWindow.FromProcess(p); //根据属性找到搜索文本框
HtmlEdit txtKeyWord = new HtmlEdit(browser);
txtKeyWord.SearchProperties[HtmlEdit.PropertyNames.Class] = "s_ipt"; //根据属性找到“百度一下”按钮
HtmlInputButton btnSubmit = new HtmlInputButton(browser);
btnSubmit.SearchProperties[HtmlInputButton.PropertyNames.Class] = "s_btn"; //根据属性找到header div
HtmlDiv header = new HtmlDiv(browser);
header.SearchProperties[HtmlDiv.PropertyNames.Class] = "s_tab"; #endregion #region 各种验证 //等待浏览器加载完成
browser.WaitForControlReady(); //输入测试关键字
txtKeyWord.Text = "软件测试"; //点击“百度一下按钮”
Mouse.Click(btnSubmit); //验证页面跳转后搜索框里面的关键字正确
Assert.IsTrue(txtKeyWord.ValueAttribute.Contains("软件测试")); //关闭浏览器
browser.Close();
#endregion
}
}
什么是Coded UI的更多相关文章
- Coded UI Test中的数据驱动测试
有关什么是Coded UI Test以及如何使用Coded UI Test可以查看我的另一篇文章:http://www.cnblogs.com/jaxu/p/3706652.html 本文主要介绍如何 ...
- 如何使用Coded UI Test对Webpage进行自动化测试
在Visual Studio中,Coded UI Test已经不是什么新特性了,较早版本的Visual Studio中就已经有这个东东了.它主要用来帮助自动化测试工程师和开发人员确保程序在UI方面没有 ...
- Coded UI Test对Webpage进行自动化测试
如何使用Coded UI Test对Webpage进行自动化测试 在Visual Studio中,Coded UI Test已经不是什么新特性了,较早版本的Visual Studio中就已经有这个 ...
- C#中通过Coded UI Test Web Page初体验(图文并茂,去繁就简!亲测通过哦~)
今天首次按照网上的步骤进行Coded UI测试,终于测试通过了,我这次进行的自动化测试是:打开浏览器,输入www.baidu.com,然后输入lty,然后点击页面中第一条数据的左侧位置(为了能获取到T ...
- SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow
Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...
- Coded UI
Coded UI Test是Visual Studio 2010对于Testing Project(测试工程)提供的关于UI自动化测试的框架,支持Win32,Web,WPF等UI的自动化测试,是一个非 ...
- Enable Coded UI Testing of Your Controls
http://msdn.microsoft.com/en-us/library/hh552522.aspx AccessibleObject Class http://msdn.microsoft.c ...
- 使用WatiN进行UI自动化测试
Watin是一个UI自动化测试工具,支持ie/firefox,官方网站:http://watin.org/. 主要有以下特点: 支持主要的html元素,见:http://watin.org/docum ...
- 自动化测试UI Test, Performance Test, Load Test 总结整理
MSDN: 测试应用程序,Test apps early and often ,Improve Code Quality 推荐书: <Visual Studio 2015高级编程> < ...
随机推荐
- Configuring spartan 6 using mcu and spi flash
http://forums.xilinx.com/t5/General-Technical-Discussion/Configuring-spartan-6-using-mcu-and-spi-fla ...
- Spring EL bean引用实例
在Spring EL,可以使用点(.)符号嵌套属性参考一个bean.例如,“bean.property_name”. public class Customer { @Value("#{ad ...
- eclipse安装Run-Jetty-Run插件,修改实时生效
http://marketplace.eclipse.org/content/run-jetty-run 1.直接拖拽到eclipse安装(7/8/9版本都安装) 2.以调试的方式启动jetty( ...
- 2014 百度之星 题解 1004 Labyrinth
Problem Description 度度熊是一仅仅喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上角的第一个格子才算走出迷宫,每一次仅仅能 ...
- U3D内存优化
原创文章如需转载请注明:转载自风宇冲Unity3D教程学院 U3D内存优化 读了Hog关于内存管理文章 ...
- [Android Memory] 使用 Eclipse Memory Analyzer 进行堆转储文件分析
转载地址:http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-ma/index.html Eclipse Memory Analyzer ...
- Istio在Openshift 3.11的安装
详细安装步骤及解释参考 https://docs.openshift.com/container-platform/3.11/servicemesh-install/servicemesh-insta ...
- Scrum 思考
下个月就要离职,所以这个月特别清闲,上班时间都在上网看书,偶然在Startup News的一篇文章(http://blog.devtang.com/blog/2013/06/17/startup-an ...
- RHEL7.0 配置网络IP的三种方法
导读 RHEL7里面的网卡命名方式从eth0,1,2的方式变成了enoXXXXX的格式. en代表的是enthernet (以太网),o 代表的是onboard (内置),那一串数字是主板的某种索引编 ...
- WordPress 如何修改编辑器TinyMCE里的内容
//获取编辑器对象,wp中的编辑器ID是"content" var editor = tinymce.get('content'); //获取编辑器内容 var content = ...