今天开始写测试代码
首先创建一个测试项目,删除里面默认的文件,这里贴上我的项目图片:
右键项目,选择Code UI Map
![](https://i-blog.csdnimg.cn/blog_migrate/85ab264c30bcc4b45b199770f251df0b.jpeg)
Uimap由3个文件组成,但是就只有一个文件有用,就UIMAP1.DESIGNER.CS有用,
UIMAP1.uitest中的XML文件。如下图:
这个是在录制过程中用来识别页面控件的,你把这XML删除干净,程序照样跑。
最后在来看看最重要的那个文件生成的内容:
![](https://i-blog.csdnimg.cn/blog_migrate/22ddeb500553e41a3b00e30c2e01351f.jpeg)
using Microsoft.VisualStudio.TestTools.UITesting.WinControls; 这两个类中 包括 htmldiv htmlspan 等等html元素,当然也包括button等控件
private UIMap1 mUIMap1;
public UIMap1 UIMap1
{
get
{
if (mUIMap1 == null)
{
mUIMap1 = new UIMap1();
} return mUIMap1;
}
}
最后将操作过程写入TestMethod中
[TestMethod]
public void CodedUITestMethod1()
{
UIMap1.RecordedMethod1();
}
编译项目,目录 Test -》Windows-》TestView 选择点击Run Selection 就OK了