TestProject1.CodedUITest1 test = new TestProject1.CodedUITest1();
test.CodedUITestMethod1();
TestProject1.TestInit.Cleanup();
}
}
}
在TestProject1中创建类TestInit.cs其代码例如以下:
using Microsoft.VisualStudio.TestTools.UITesting;
namespace TestProject1
{
public class TestInit
{
public static void Init()
{
if (!Playback.IsInitialized)
{
Playback.Initialize();
}
}
public static void Cleanup()
{
if (Playback.IsInitialized)
{
Playback.Cleanup();
}
}
}
}
复制代码
编译解决方式。先打开CodeUITest.exe,再打开CodeUITestExe.exe,运行測试时当出现找不到dll时,可将
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies下的Microsoft.VisualStudio.T
estTools.UITest为前缀的dll拷贝到Debug下。
当将程序代码拷贝到其它电脑时,运行測试时会提示“Cannot perform ” on the control”错误,继续查找错
误会发现“ CLSID {6DA215C2-D80D-42F2-A514-B44A16DCBAAA} failed due to the following error: 80040
154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).”。究其原
因是缺少了Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.dll文件。