Share via


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 : https://msdn.microsoft.com/en-us/library/dd286681(v=vs.100).aspx)

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

4) Type MSTEST.EXE /testcontainer : "LOCATION OF YOUR BINARY (DLL)"

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 : https://msdn.microsoft.com/en-us/library/dd380742.aspx

Command line options for MSTEST : https://msdn.microsoft.com/en-us/library/ms182489(v=vs.80).aspx

VMs cant be put off sleep while tests are running. More information available here : https://msdn.microsoft.com/en-us/library/ee291332.aspx

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. (https://blogs.msdn.com/b/visualstudioalm/archive/2012/10/30/introducing-cross-browser-testing-with-coded-ui-tests.aspx)

 

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.