Running CodedUI Test From Another Application
Running CodedUI Test From Another Application
As Coded UI Testing become a very powerful and easy UI Testing there is lots of questions regarding using it in various ways, for example : how can I run CodedUI Test from WinForm application???
So the answer is very easy:
Step 1
Create new WinForm application, and add reference to the below assemblies:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\
- Microsoft.VisualStudio.TestTools.UITesting.dll
- Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\
- Microsoft.VisualStudio.TestTools.UITest.CodeGeneration.dll
- Microsoft.VisualStudio.TestTools.UITest.Framework.dll
- Microsoft.VisualStudio.TestTools.UITest.Playback.dll
Make sure you change Winform target framework to full 4.0 and not 4 Client Profile.
Step 2
Add the code calling your test project and executing you Test method.
TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();
coded.CodedUITestMethod1();
Here you will see your CodedUI throws an error - Object reference not set to an instance of an object.
This is because you must run: Playback.Initialize(); before you starting your Test.
So the code should look like that:
Playback.Initialize();
TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();
coded.CodedUITestMethod1();
Playback.Cleanup();
And you’re Done!!!
Enjoy.