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\image

  • 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();
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:
TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();
And you’re Done!!!

Add comment
facebook linkedin twitter email

Leave a Reply


  1. Pia18/08/2010 ב 16:00

    Can I use the same to run a CUIT on a machine that does not have Visual Studio 2010? Rather I tried doing it, but get an exception- UITestControlNotFoundException, when actually I can see the control there.

  2. sun06/10/2010 ב 13:13

    thanks very much

  3. daniel19/11/2010 ב 21:43

    I am getting the error when I try this example.

    Microsoft.VisualStudio.TestTools.UITest.Extension.InvalidUITestExtensionPackageException: The following package failed to load:

    . —> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

  4. Alon01/06/2011 ב 15:12

    I’ve build an app that runs coded ui tests via reflection. It works, however, it seems like TestContext is not initialized in that way.

    Do you know how I can initialize it so it would function as usual?


  5. Krishna Chaduvula27/06/2011 ב 22:34

    Can you please provide a sample Windows form that invokes the coded UI tests. I am getting a lot of errors while trying to run the tests.

    My Steps:
    Created Coded UI Tests
    Created a Windows App targeting framework 4 as you specified
    My Code in a button click event looks something like this

    Dim Personal As New PersonalInformation()

  6. Govind07/07/2011 ב 12:42

    I’ve installed the trial version of VS2010 Ultimate Edition but there was no ‘Microsoft Visual Studio 10.0’ folder in ‘C:\Program Files’. There was only ‘Microsoft Visual Studio 9.0’ and it didn’t contain any of the 5 DLLs mentioned in the Public/PrivateAssemblies folders.

    Will the DLLs come only with a registered version?


  7. shair11/07/2011 ב 19:44

    Hi Govind,

    Are you using 64bit operation system?
    If so, please look under Program File (x86)

  8. Bogdan14/07/2011 ב 12:05

    Anybody has any ideea on this error?

    Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform ” on the control. Additional Details: The control details were not specified. —> System.Runtime.InteropServices.COMException:
    Retrieving the COM class factory for component with CLSID {6DA215C2-D80D-42F2-A514-B44A16DCBAAA} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.InitPlayback()
    at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()
    — End of inner exception stack trace —
    at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)
    at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, IPlaybackContext context)
    at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()

  9. Tony Tonev27/07/2011 ב 22:54

    I had to also add references to “Microsoft.VisualStudio.TestTools.UITest.Extension.IE” and “Microsoft.VisualStudio.TestTools.UITest.Extension.Uia” but otherwise, works great, thanks!

  10. Tony Tonev29/07/2011 ב 00:52

    Yes, Bogdan, I’m getting the same exact error. Have you managed to resolve it? If so, please post the details.


  11. shair29/07/2011 ב 08:21


    Please make sure your Application sets to Framework 4.0 and not Client Profile.


  12. Prashanth02/08/2011 ב 12:46


    I’m not able to add my testproject to the windows form application.I added my testproject to the solution and added reference of the same.Intellisense works fine before building the project, but application is throwing a error “are you missing any (testproject) assembly reference”, once i build the application. Should i add any other reference??

  13. VIshesh15/09/2011 ב 12:12


    Thanks for this info, I have created the exe by using steps told by you.

    1 more question…… Can I run this exe in other machine which don’t have Visual Studio

  14. Abhishek11/10/2011 ב 18:57

    Hi Shai,

    Now I can run Coded UI thru windows form with the click of a button. Thanks for your help!!!

    Now I have created an exe and trying to run the Coded UI thru an exe. On running the exe, the form is opening and after clicking the button (which calls the coded UI) it is throwing an exception error.
    System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.VisualStudio.TestTools.UITesting, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.
    File name: ‘Microsoft.VisualStudio.TestTools.UITesting, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

    Please help.

    Thank you in Advance.


  15. PIyush Sharma05/11/2011 ב 12:24

    Can you plz told the Namespace to call

    because my solution has two projects
    one is for CUIT
    Secound is for Winform having a button (My Coded ui test)

    when we paste your code : –

    TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();

    they didnot identify the objects of Coded ui test project .. I paste this code on Click event of button

    than it means they can’t recognize .. will you pl help

  16. ATE30/11/2011 ב 12:29

    Hello, first of all … how can i call the CUIT mehtods ..
    I add all 5 refrences … but playback.initlize is not found in hint

    on total nothing is work … i done only at add refences to all dlls

  17. Igal17/02/2012 ב 01:25

    I’ve some form with controls I’m practice on it .

    the trigger for the UI test for this form is located on the form itself (link label). when I’m firing the Link Clicked event , the


    code should run, but actually happens is that my forms hangs (no exception), is this due to cross threading issue ?

  18. MikeB06/03/2012 ב 19:09

    I’m having a problem with “Object reference not set to an instance of an object.” exception on TestContect.DataRow.

    I am using Playback.Initialize(); as suggested but still get that exception.
    any ideas?
    thank you

  19. Laurie17/03/2012 ב 05:12

    Thank you for your code. I’m having trouble getting it to work. I’m getting an error “Broswer not supported” I added the line Playback.Initialize(), but that didn’t change the result.

    Do you have any ideas?


  20. shair30/03/2012 ב 08:38


    What type of browser you’re running your coded ui testing on?


  21. Eric Bauersachs18/06/2012 ב 13:21

    Great info! I had to include Microsoft.VisualStudio.TestTools.UITest.Extension.IE and Microsoft.VisualStudio.TestTools.UITest.Extension.Uia, (two additional private assemblies) as well, but now my standalone Console Playback test tool works.

  22. Markus20/08/2012 ב 11:57

    Thanks alot! I finally got this to work, thanks to this blog. 🙂

  23. Lilit Yenokyan05/10/2012 ב 02:25

    Thank you! Great post, helped me A LOT, especially about including the necessary references and calling Playback.Initialize method before executing test methods.

  24. Pingback: How to run Coded UI Tests from another library using reflection?