Running Coded UI test on VM using MSTEST

Prerequisites :

Microsoft Visual Studio Agent is installed on all VMs. This is required to have all necessary libraries to run coded UI through command prompt. We are not installing full Visual studio set up and neither are we using controller and agent set up to run automated coded UI test.

What we want to achieve :

 We have two applications, 1 windows based & other is web based. These applications interact with each other. Create a coded UI test for this interaction & run this on a VM.

How do we achieve :

1) Create a coded UI test for functionality you want to achieve. ( Described very well here :

2) Copy and Paste the binary ( DLL) from your system to VMs on which you want to run coded UI.

3) Open command prompt in admin mode and go to below location

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE OR C:\Program Files \Microsoft Visual Studio 11.0\Common7\IDE


5) Click enter.

6) Verify that test is running fine once and you are ready to go!


Things to know : 


Systems supported by Coded UI :

Command line options for MSTEST :

VMs cant be put off sleep while tests are running. More information available here :

If your tests involves audio, they cant be run on VM.

To run VM remotely without keep desktop active one must configure controller & agent set up.

Coded UI now supports multi language with Visual studio 2012 CTP update. (


Common Errors:

Now while all this is happening there are few precautions that you should take care of before :

1) Use same version of windows based application in all VMs which was used while creating Coded UI test other you might get below error ( if one is creating logs of error)

INNER EXCEPTION ISSystem.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at  Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String
queryId, Int32 maxDepth, Int32& timeLeft)

2) If coded UI test is created in Visual studio 2010, then install agent 2010 and in case test case is created in 2012, then install agent 2012

3) Make sure you have enough space in C Drive

4) In case your tests run for more than half hour then decorate your test with this attribute : [Timeout(TestTimeout.Infinite)] / alternatively you can create scheduled task.

Comments (6)

  1. Alex says:

    Shouldn't we rather not use cmd.exe in admin mode? In my local setup, I just set current working directory to a writable location like %temp% and it seems to work in my little use case (form processing in IE 10).

  2. Alexey says:

    It works, but I found that it creates the UITestPlaybackResults_QTAgent32.html and screenshots under c:Program Files (x86)Microsoft Visual Studio 11.0Common7IDE.

    Is there a way to tell it where to put the content?

  3. Ali Hassan says:

    Regarding the point "If coded UI test is created in Visual studio 2010, then install agent 2010 and in case test case is created in 2012, then install agent 2012".

    I have a question " We have created Coded UI test in Visual Studio 2010 But we have made test case using Microsoft Test Manager 2012. So should i install Visual Studio 2010 agents or Visual Studio 2012 agents?

  4. Rajesh Rawal says:

    Ali Hussain : You should install Visual Studio 2010 agents

  5. Rajesh Rawal says:

    Alex : yes, that should also be fine. Both approaches will work

  6. karthick says:


    I follow the same which given above.but in my case coded ui test not getting run…Please provide the solution